# HG changeset patch # User Andre Heinecke # Date 1432026742 -7200 # Node ID 016cbcb1a233b1f08ece0c6ab07ac87a671e39a9 # Parent 23672cbc3e5f2e1a997a4fe1405624105b3f98b8 Wrap the CSV model to have it return not only string variants but also numerical types diff -r 23672cbc3e5f -r 016cbcb1a233 src/l10n/main_de_DE.ts --- a/src/l10n/main_de_DE.ts Tue May 19 10:13:04 2015 +0200 +++ b/src/l10n/main_de_DE.ts Tue May 19 11:12:22 2015 +0200 @@ -75,27 +75,27 @@ Auf die Metadaten-Datei: '%1' konnte nicht zugegriffen werden. - + Parsed: '%1' '%1' eingelesen - + Showing: '%1' Zeige: '%1' - + Persons Personen - + Exams Prüfungen - + Root-Path Wurzelverzeichnis @@ -103,7 +103,7 @@ MetaDataView - + Failed to parse file: '%1' Die Datei '%1' konnte nicht eingelesen werden. diff -r 23672cbc3e5f -r 016cbcb1a233 src/mainwindow.cpp --- a/src/mainwindow.cpp Tue May 19 10:13:04 2015 +0200 +++ b/src/mainwindow.cpp Tue May 19 11:12:22 2015 +0200 @@ -151,7 +151,6 @@ QString errorMsg = mDataView->parseMetaData(metaData.filePath()); if (!errorMsg.isEmpty()) { showErrorMessage(errorMsg); - return; } statusBar()->showMessage(tr("Parsed: '%1'").arg(metaData.filePath())); qDebug() << "Parsed: " << metaData.filePath(); diff -r 23672cbc3e5f -r 016cbcb1a233 src/metadataview.cpp --- a/src/metadataview.cpp Tue May 19 10:13:04 2015 +0200 +++ b/src/metadataview.cpp Tue May 19 11:12:22 2015 +0200 @@ -23,12 +23,32 @@ #include #include +/**@brief Small wrapper around csv model to enable numerical sorting. */ +class numericSortCSVModel : public QxtCsvModel +{ +public: + /**@brief returns the data as string, integer or double variant. */ + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { + QVariant base = QxtCsvModel::data(index, role); + bool ok = false; + int intVal = base.toInt(&ok); + if (ok) { + return intVal; + } + double dblVal = base.toDouble(&ok); + if (ok) { + return dblVal; + } + return base; + } +}; + MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mDateColIdx(-1) { /* Create models */ mSortModel = new QSortFilterProxyModel; - mCSVModel = new QxtCsvModel; + mCSVModel = new numericSortCSVModel; setupGUI(); connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged,