diff src/metadataview.cpp @ 44:73e6b6b12412

(issue 1,2) Make the column used for the Timestamp value configurable If the column contains a number it is interpreted as seconds since epoch. Otherwise its a verbatim copy of the column string.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 May 2015 19:45:26 +0200
parents 0c05958d254c
children 28d5a77db9fb
line wrap: on
line diff
--- a/src/metadataview.cpp	Wed May 06 18:20:13 2015 +0200
+++ b/src/metadataview.cpp	Wed May 06 19:45:26 2015 +0200
@@ -24,7 +24,8 @@
 #include <QApplication>
 
 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) :
-    QWidget(parent, f) {
+    QWidget(parent, f),
+    mDateColIdx(-1) {
     /* Create models */
     mSortModel = new QSortFilterProxyModel;
     mCSVModel = new QxtCsvModel;
@@ -71,6 +72,21 @@
     qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows.";
     applyDefaultSort();
     resizeColsToHeaders();
+
+    QSettings settings;
+    const QString displayDate = settings.value(DATE_COLUMN_KEY, DATE_COLUMN_DEFAULT).toString();
+    settings.setValue(DATE_COLUMN_KEY, displayDate);
+    for (int i=0; i < mSortModel->columnCount(); i++) {
+        QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
+        if (entry.toLower() == displayDate.toLower()) {
+            mDateColIdx = i;
+            break;
+        }
+    }
+    if (mDateColIdx == -1) {
+        qDebug() << "Failed to find displayDate column: " << displayDate;
+        mDateColIdx = DATE_COLUMN_FALLBACK_IDX;
+    }
     return QString();
 }
 
@@ -84,7 +100,7 @@
         /* Nothing selected still we need to emit this signal to update
          * the viewer otherwise selection changed handles it. */
         emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1,
-                QDateTime(), 0);
+                QString(), 0);
     }
 }
 
@@ -96,15 +112,17 @@
     }
     /* One row selected */
     Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
-    const QModelIndex idx = selected.indexes()[FILENAME_COLUMN];
-    const QString dateString = selected.indexes()[DATE_COLUMN].data().toString();
+    const QModelIndex idx = selected.indexes()[FILENAME_COLUMN_IDX];
+    const QString dateString = selected.indexes()[mDateColIdx].data().toString();
     bool ok;
     qint64 secondsSinceEpoch = dateString.toLongLong(&ok);
-    if (!ok) {
-        // TODO emit error
-        qDebug() << "Unparsable date.";
+    QString timestamp = dateString;
+    if (ok) {
+        QDateTime datetime = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
+        if (datetime.isValid()) {
+            timestamp = datetime.toString(LONG_DATE_FORMAT);
+        }
     }
-    QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
     emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1,
             timestamp, selected.indexes()[0].data().toInt());
     qDebug() << "Selection changed: " << idx.data();
@@ -176,7 +194,6 @@
     int idx = -1;
     for (int i=0; i < mSortModel->columnCount(); i++) {
         QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
-        qDebug() << "Looking at entry: " << entry;
         if (entry.toLower() == sortField.toLower()) {
             idx = i;
             break;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)