comparison 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
comparison
equal deleted inserted replaced
43:ee696abaab99 44:73e6b6b12412
22 #include <QSettings> 22 #include <QSettings>
23 #include <QFontMetrics> 23 #include <QFontMetrics>
24 #include <QApplication> 24 #include <QApplication>
25 25
26 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) : 26 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) :
27 QWidget(parent, f) { 27 QWidget(parent, f),
28 mDateColIdx(-1) {
28 /* Create models */ 29 /* Create models */
29 mSortModel = new QSortFilterProxyModel; 30 mSortModel = new QSortFilterProxyModel;
30 mCSVModel = new QxtCsvModel; 31 mCSVModel = new QxtCsvModel;
31 setupGUI(); 32 setupGUI();
32 33
69 70
70 mSortModel->setSourceModel(mCSVModel); 71 mSortModel->setSourceModel(mCSVModel);
71 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows."; 72 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows.";
72 applyDefaultSort(); 73 applyDefaultSort();
73 resizeColsToHeaders(); 74 resizeColsToHeaders();
75
76 QSettings settings;
77 const QString displayDate = settings.value(DATE_COLUMN_KEY, DATE_COLUMN_DEFAULT).toString();
78 settings.setValue(DATE_COLUMN_KEY, displayDate);
79 for (int i=0; i < mSortModel->columnCount(); i++) {
80 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
81 if (entry.toLower() == displayDate.toLower()) {
82 mDateColIdx = i;
83 break;
84 }
85 }
86 if (mDateColIdx == -1) {
87 qDebug() << "Failed to find displayDate column: " << displayDate;
88 mDateColIdx = DATE_COLUMN_FALLBACK_IDX;
89 }
74 return QString(); 90 return QString();
75 } 91 }
76 92
77 void MetaDataView::dataChanged() 93 void MetaDataView::dataChanged()
78 { 94 {
82 qDebug() << "Data Changed."; 98 qDebug() << "Data Changed.";
83 if (selected.isEmpty()) { 99 if (selected.isEmpty()) {
84 /* Nothing selected still we need to emit this signal to update 100 /* Nothing selected still we need to emit this signal to update
85 * the viewer otherwise selection changed handles it. */ 101 * the viewer otherwise selection changed handles it. */
86 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1, 102 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1,
87 QDateTime(), 0); 103 QString(), 0);
88 } 104 }
89 } 105 }
90 106
91 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, 107 void MetaDataView::viewSelectionChanged(const QItemSelection& selected,
92 const QItemSelection& deselected) { 108 const QItemSelection& deselected) {
94 /* Nothing selected */ 110 /* Nothing selected */
95 return; 111 return;
96 } 112 }
97 /* One row selected */ 113 /* One row selected */
98 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); 114 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
99 const QModelIndex idx = selected.indexes()[FILENAME_COLUMN]; 115 const QModelIndex idx = selected.indexes()[FILENAME_COLUMN_IDX];
100 const QString dateString = selected.indexes()[DATE_COLUMN].data().toString(); 116 const QString dateString = selected.indexes()[mDateColIdx].data().toString();
101 bool ok; 117 bool ok;
102 qint64 secondsSinceEpoch = dateString.toLongLong(&ok); 118 qint64 secondsSinceEpoch = dateString.toLongLong(&ok);
103 if (!ok) { 119 QString timestamp = dateString;
104 // TODO emit error 120 if (ok) {
105 qDebug() << "Unparsable date."; 121 QDateTime datetime = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
106 } 122 if (datetime.isValid()) {
107 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000); 123 timestamp = datetime.toString(LONG_DATE_FORMAT);
124 }
125 }
108 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1, 126 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1,
109 timestamp, selected.indexes()[0].data().toInt()); 127 timestamp, selected.indexes()[0].data().toInt());
110 qDebug() << "Selection changed: " << idx.data(); 128 qDebug() << "Selection changed: " << idx.data();
111 } 129 }
112 130
174 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool(); 192 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool();
175 193
176 int idx = -1; 194 int idx = -1;
177 for (int i=0; i < mSortModel->columnCount(); i++) { 195 for (int i=0; i < mSortModel->columnCount(); i++) {
178 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); 196 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
179 qDebug() << "Looking at entry: " << entry;
180 if (entry.toLower() == sortField.toLower()) { 197 if (entry.toLower() == sortField.toLower()) {
181 idx = i; 198 idx = i;
182 break; 199 break;
183 } 200 }
184 } 201 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)