changeset 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 ee696abaab99
children 213d9163dab0
files src/constants.h src/mainwindow.cpp src/mainwindow.h src/metadataview.cpp src/metadataview.h src/pngplayer.cpp src/pngplayer.h
diffstat 7 files changed, 53 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.h	Wed May 06 18:20:13 2015 +0200
+++ b/src/constants.h	Wed May 06 19:45:26 2015 +0200
@@ -84,9 +84,15 @@
 #define SORT_ORDER_VALUE true
 
 /**@def The column to use (counted from 0 and including index nr) for the filename */
-#define FILENAME_COLUMN 1
+#define FILENAME_COLUMN_IDX 1
 
-/**@def The column to use as the date */
-#define DATE_COLUMN 2
+/**@def The column to use as the timestamp in the player window */
+#define DATE_COLUMN_KEY "DisplayDate"
+
+/**@def The default value for the timestamp column */
+#define DATE_COLUMN_DEFAULT "Date"
+
+/**@def The fallback value in case the DisplayDate column can't be found */
+#define DATE_COLUMN_FALLBACK_IDX 2
 
 #endif // CONSTANTS_H
--- a/src/mainwindow.cpp	Wed May 06 18:20:13 2015 +0200
+++ b/src/mainwindow.cpp	Wed May 06 19:45:26 2015 +0200
@@ -167,7 +167,7 @@
 }
 
 void MainWindow::showPictureNameStatus(const QString& fileName, int current,
-            int max, const QDateTime& timestamp) {
+            int max, const QString& timestamp) {
     if (current != 0 && max != 0) {
         statusBar()->showMessage(tr("Showing: '%1'").arg(fileName));
     }
--- a/src/mainwindow.h	Wed May 06 18:20:13 2015 +0200
+++ b/src/mainwindow.h	Wed May 06 19:45:26 2015 +0200
@@ -13,7 +13,6 @@
  */
 #include <QMainWindow>
 #include <QSettings>
-#include <QDateTime>
 
 class QPushButton;
 class QDropEvent;
@@ -72,7 +71,7 @@
      * Function signature is similar to showPicture in pngviewer
      */
     void showPictureNameStatus(const QString& fileName, int current,
-            int max, const QDateTime& timestamp );
+            int max, const QString& timestamp );
 
 private:
     QSettings mSettings;
--- 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;
--- a/src/metadataview.h	Wed May 06 18:20:13 2015 +0200
+++ b/src/metadataview.h	Wed May 06 19:45:26 2015 +0200
@@ -34,7 +34,7 @@
 Q_SIGNALS:
     /**@brief emited when the selection changed. */
     void selectionChanged(const QString& pictureFile, int current, int max,
-        const QDateTime& timestamp, int number);
+        const QString& timestamp, int number);
 
 protected slots:
     /** @brief internal slot to handle table view selection changes */
@@ -63,6 +63,7 @@
     QxtCsvModel *mCSVModel;
     QSortFilterProxyModel *mSortModel;
     QTableView *mView;
+    int mDateColIdx;
 };
 
 
--- a/src/pngplayer.cpp	Wed May 06 18:20:13 2015 +0200
+++ b/src/pngplayer.cpp	Wed May 06 19:45:26 2015 +0200
@@ -111,7 +111,7 @@
 }
 
 void PNGPlayer::showPicture(const QString& fileName, int current, int max,
-        const QDateTime& timestamp, int number) {
+        const QString& timestamp, int number) {
     QPixmap pic(mBaseDir.filePath(fileName));
     /* If this is too slow we could use a pixmap cache here and do
      * some intelligent preloading */
@@ -126,7 +126,7 @@
     updatePositions(current, max, timestamp, number);
 }
 
-void PNGPlayer::updatePositions(int current, int max, const QDateTime& timestamp,
+void PNGPlayer::updatePositions(int current, int max, const QString& timestamp,
         int number) {
     mMax = max;
     mSlider->blockSignals(true); /* We only want user generated changes */
@@ -135,9 +135,8 @@
     mSlider->setMaximum(max);
     mPositionLabel->setText("<b>" + tr("Screenshot Nr.:") + " </b>" +
             QString("%1 (%2)").arg(current + 1).arg(max + 1) +
-            "<b> " + tr("Index Nr.:") + " </b>" + QString::number(number) + " / <b>" +
-        tr("Timestamp:") + " </b>" + (timestamp.isValid() ?
-            timestamp.toString(LONG_DATE_FORMAT) : tr("Unknown")));
+            "/ <b>" + tr("Index Nr.:") + " </b>" + QString::number(number) + " / <b>" +
+        tr("Timestamp:") + " </b>" + timestamp);
 
     if (mMax == current && mAdvanceTimer.isActive()) {
         togglePlay();
@@ -203,7 +202,14 @@
 }
 
 void PNGPlayer::togglePicFullscreen() {
-    qDebug() << "togglePicFullscreen";
+    QSettings settings;
+    bool enabled = settings.value(DETACHABLE_IMAGE_KEY, DETACHABLE_IMAGE_DEFAULT).toBool();
+    settings.setValue(DETACHABLE_IMAGE_KEY, enabled);
+
+    if (!enabled) {
+        return;
+    }
+
     QVBoxLayout *baseLayout = qobject_cast<QVBoxLayout*>(layout());
     if (!baseLayout) {
         qWarning() << "Wrong layout!";
--- a/src/pngplayer.h	Wed May 06 18:20:13 2015 +0200
+++ b/src/pngplayer.h	Wed May 06 19:45:26 2015 +0200
@@ -10,7 +10,6 @@
 #include <QWidget>
 #include <QDir>
 #include <QTimer>
-#include <QDateTime>
 
 class QSlider;
 class QLabel;
@@ -57,13 +56,13 @@
      * @param number: The index number of the picture to show.
      */
     void showPicture(const QString& fileName, int current, int max,
-        const QDateTime& timestamp, int number);
+        const QString& timestamp, int number);
 
     /**@brief set the base dir to which filenames will be relative. */
     void setBaseDir(const QString& dirName) { mBaseDir.setPath(dirName); }
 
     /**@brief update positional information / slider current / max info. */
-    void updatePositions(int current, int max, const QDateTime& timestamp, int number);
+    void updatePositions(int current, int max, const QString& timestamp, int number);
 
     /**@brief set the replay speed */
     void setSpeed(int mSecsPerPicture);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)