Brief description of class still missing. More...
#include <EventListModel.h>
Public Member Functions | |
virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const |
virtual QVariant | data (const QModelIndex &index, int role) const |
Event * | event (int index) const |
Event * | event (const QString &name) const |
EventListModel (QObject *parent) | |
virtual QVariant | headerData (int section, Qt::Orientation orientation, int role) const |
bool | load () |
virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
bool | save () |
void | setBaseDirectory (const QString &d) |
virtual void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder) |
void | update (QModelIndex index) |
~EventListModel () |
Brief description of class still missing.
Full description of class still missing
EventListModel::EventListModel | ( | QObject * | parent | ) |
int EventListModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
QVariant EventListModel::data | ( | const QModelIndex & | index, |
int | role | ||
) | const [virtual] |
References Event::id(), Event::magnitude(), Event::status(), Station::statusToString(), QGpCoreTools::tr(), and TRACE.
{ TRACE; switch (role) { case Qt::DisplayRole: { const Event * e=_events.at(index.row()); switch(index.column()) { default: return e->id(); case 1: { bool ok; double m=e->magnitude(ok); if(ok) { return QString::number(m, 'f', 1); } else { return tr("---"); } } case 2: return Station::statusToString(e->status()); } } break; default: return QVariant(); } }
Event* EventListModel::event | ( | int | index | ) | const [inline] |
Referenced by load().
{return _events.at(index);}
Event * EventListModel::event | ( | const QString & | name | ) | const |
References Event::id().
QVariant EventListModel::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role | ||
) | const [virtual] |
References QGpCoreTools::tr(), and TRACE.
{ TRACE; switch(orientation) { case Qt::Horizontal: switch(role) { case Qt::DisplayRole: switch(section) { default: return tr("Event ID"); case 1: return tr("Magnitude"); case 2: return tr("Status"); } default: return QVariant(); } case Qt::Vertical: break; } switch(role) { case Qt::DisplayRole: return section+1; default: return QVariant(); } }
bool EventListModel::load | ( | ) |
References QGpCoreTools::endl(), event(), fileName, Event::id(), QGpCoreTools::LineParser::setDelimiters(), Station::setStatus(), QGpCoreTools::LineParser::setString(), Event::station(), QGpCoreTools::LineParser::toString(), QGpCoreTools::tr(), and TRACE.
Referenced by MainWidget::setBaseDirectory().
{ TRACE; QString fileName=_baseDir.absoluteFilePath("sort.txt"); QFile f(fileName); if(!f.open(QIODevice::ReadOnly)) { App::stream() << tr("Cannot open file %1 for reading").arg(fileName) << endl; return false; } QTextStream s(&f); LineParser lp; lp.setDelimiters("\t"); bool ok=true; while(!s.atEnd()) { lp.setString(s.readLine()); Event * e=event(lp.toString(0, ok)); if(e) { Station * stat=e->station(lp.toString(1, ok)); if(stat) { stat->setStatus(lp.toString(2, ok)); } else { App::stream() << tr("Event %1 does not contain station %2").arg(e->id()).arg(lp.toString(1, ok)) << endl; } } else { App::stream() << tr("Event %1 does not exist in database").arg(lp.toString(0, ok)) << endl; } } if(!ok) { App::stream() << tr("Error while parsing file %1").arg(fileName) << endl; } App::stream() << tr("Current status loaded from %1").arg(fileName) << endl; return true; }
int EventListModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
bool EventListModel::save | ( | ) |
References QGpCoreTools::endl(), fileName, Event::id(), Event::save(), QGpCoreTools::tr(), and TRACE.
{ TRACE; QString fileName=_baseDir.absoluteFilePath("sort.txt"); QFile f(fileName); if(!f.open(QIODevice::WriteOnly)) { App::stream() << tr("Cannot open file %1 for writing").arg(fileName) << endl; return false; } QTextStream s(&f); for(QList<Event *>::const_iterator it=_events.begin(); it!=_events.end(); it++) { Event * e=*it; e->save(s, e->id()); } App::stream() << tr("Current status saved to %1").arg(fileName) << endl; return true; }
void EventListModel::setBaseDirectory | ( | const QString & | d | ) |
References Event::setId(), and TRACE.
Referenced by MainWidget::setBaseDirectory().
{ TRACE; qDeleteAll(_events); _baseDir.setPath(d); QStringList filters; filters << "[0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9]"; QStringList events=_baseDir.entryList(filters, QDir::Dirs); foreach(QString id, events) { Event * e=new Event; e->setId(_baseDir, id); _events.append(e); } reset(); }
void EventListModel::sort | ( | int | column, |
Qt::SortOrder | order = Qt::AscendingOrder |
||
) | [virtual] |
References Event::lessThan(), Event::setSortIndex(), and TRACE.
{ TRACE; Event::setSortIndex(order==Qt::AscendingOrder ? column+1 : -column-1); qStableSort(_events.begin(), _events.end(), Event::lessThan); reset(); }
void EventListModel::update | ( | QModelIndex | index | ) |