changeset 56:016cbcb1a233

Wrap the CSV model to have it return not only string variants but also numerical types
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 19 May 2015 11:12:22 +0200
parents 23672cbc3e5f
children 2cd76e6c0fcf
files src/l10n/main_de_DE.ts src/mainwindow.cpp src/metadataview.cpp
diffstat 3 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
         <translation>Auf die Metadaten-Datei: &apos;%1&apos; konnte nicht zugegriffen werden.</translation>
     </message>
     <message>
-        <location filename="../mainwindow.cpp" line="156"/>
+        <location filename="../mainwindow.cpp" line="155"/>
         <source>Parsed: &apos;%1&apos;</source>
         <translation>&apos;%1&apos; eingelesen</translation>
     </message>
     <message>
-        <location filename="../mainwindow.cpp" line="173"/>
+        <location filename="../mainwindow.cpp" line="172"/>
         <source>Showing: &apos;%1&apos;</source>
         <translation>Zeige: &apos;%1&apos;</translation>
     </message>
     <message>
-        <location filename="../mainwindow.cpp" line="192"/>
+        <location filename="../mainwindow.cpp" line="191"/>
         <source>Persons</source>
         <translation>Personen</translation>
     </message>
     <message>
-        <location filename="../mainwindow.cpp" line="209"/>
+        <location filename="../mainwindow.cpp" line="208"/>
         <source>Exams</source>
         <translation>Prüfungen</translation>
     </message>
     <message>
-        <location filename="../mainwindow.cpp" line="208"/>
+        <location filename="../mainwindow.cpp" line="207"/>
         <source>Root-Path</source>
         <translation>Wurzelverzeichnis</translation>
     </message>
@@ -103,7 +103,7 @@
 <context>
     <name>MetaDataView</name>
     <message>
-        <location filename="../metadataview.cpp" line="70"/>
+        <location filename="../metadataview.cpp" line="90"/>
         <source>Failed to parse file: &apos;%1&apos;</source>
         <translation>Die Datei &apos;%1&apos; konnte nicht eingelesen werden.</translation>
     </message>
--- 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();
--- 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 <QFontMetrics>
 #include <QApplication>
 
+/**@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,
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)