annotate src/metadataview.cpp @ 28:4e16fbd10945

(issue3-5) Make the default sort order configurable
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 May 2015 18:46:35 +0200
parents 64a51a42c01f
children f10d4e035eec
rev   line source
25
64a51a42c01f Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
1 /* Copyright (C) 2015 by ETH Zürich
64a51a42c01f Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 24
diff changeset
2 * Software engineering by Intevation GmbH
24
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 22
diff changeset
3 *
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 22
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 22
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 22
diff changeset
6 * See LICENSE.txt for details.
6b9b5efcd7f4 Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents: 22
diff changeset
7 */
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8 #include "metadataview.h"
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 #include "qxtcsvmodel.h"
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
10 #include "filterwidget.h"
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
11 #include "constants.h"
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include <QTextCodec>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include <QTableView>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include <QSortFilterProxyModel>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include <QVBoxLayout>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 #include <QLabel>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 #include <QDebug>
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 #include <QModelIndex>
22
0a08c1c2531a Fix missing include and update translations accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 17
diff changeset
20 #include <QHeaderView>
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 #include <QItemSelectionModel>
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
22 #include <QSettings>
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) :
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 QWidget(parent, f) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 /* Create models */
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 mSortModel = new QSortFilterProxyModel;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 mCSVModel = new QxtCsvModel;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 setupGUI();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged,
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 this, &MetaDataView::viewSelectionChanged);
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
33 connect(mSortModel, &QSortFilterProxyModel::dataChanged,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
34 this, &MetaDataView::dataChanged);
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 return;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 void MetaDataView::setupGUI() {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 QVBoxLayout *baseLayout = new QVBoxLayout;
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
40
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
41 FilterWidget *filterWidget = new FilterWidget(mSortModel);
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
42 connect(filterWidget, &FilterWidget::filterHasChanged,
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
43 this, &MetaDataView::applyDefaultSort);
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
44 baseLayout->addWidget(filterWidget);
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
45
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 mView = new QTableView;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 mView->setModel(mSortModel);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 mView->horizontalHeader()->setStretchLastSection(true);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 mView->resizeColumnsToContents();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 // mView->setColumnWidth(0, 60);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 mView->setSelectionBehavior(QAbstractItemView::SelectRows);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 mView->setSelectionMode(QAbstractItemView::SingleSelection);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 mView->setSortingEnabled(true);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 baseLayout->addWidget(mView);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 setLayout(baseLayout);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 QString MetaDataView::parseMetaData(const QString& filePath) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 mCSVModel->setSource(filePath, true, ';', QTextCodec::codecForName("UTF8"));
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 if (!mCSVModel->rowCount()) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 return tr("Failed to parse file: '%1'").arg(filePath);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 mSortModel->setSourceModel(mCSVModel);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows.";
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
70 applyDefaultSort();
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 return QString();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
74 void MetaDataView::dataChanged()
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
75 {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
76 QItemSelectionModel *selection = mView->selectionModel();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
77 QModelIndexList selected = selection->selectedIndexes();
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
78
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
79 qDebug() << "Data Changed.";
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
80 if (selected.isEmpty()) {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
81 /* Nothing selected still we need to emit this signal to update
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
82 * the viewer otherwise selection changed handles it. */
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
83 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1,
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
84 QDateTime());
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
85 }
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
86 }
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
87
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 void MetaDataView::viewSelectionChanged(const QItemSelection& selected,
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 const QItemSelection& deselected) {
4
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
90 if (selected.indexes().isEmpty()) {
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
91 /* Nothing selected */
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
92 return;
e4748da7140b Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents: 3
diff changeset
93 }
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 /* One row selected */
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount());
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 const QModelIndex idx = selected.indexes()[0];
3
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
97 const QString dateString = selected.indexes()[1].data().toString();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
98 bool ok;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
99 qint64 secondsSinceEpoch = dateString.toLongLong(&ok);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
100 if (!ok) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
101 // TODO emit error
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
102 qDebug() << "Unparsable date.";
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
103 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
104 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
105 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1,
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
106 timestamp);
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 qDebug() << "Selection changed: " << idx.data();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109
3
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
110 void MetaDataView::selectRow(int row) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
111 QItemSelectionModel *selection = mView->selectionModel();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
112 if (!mSortModel->hasIndex(row, 0)) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
113 qDebug() << "Invalid row: " << row;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
114 return;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
115 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
116 QModelIndex newIdx = mSortModel->index(row, 0);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
117 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
118 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
119
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
120 void MetaDataView::selectPrevRow() {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
121 QItemSelectionModel *selection = mView->selectionModel();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
122 QModelIndexList selected = selection->selectedIndexes();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
123 int row = 0,
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
124 col = 0;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
125 if (selected.isEmpty()) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
126 qDebug() << "Selection empty. Start at row 0";
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
127 if (!mSortModel->hasIndex(row, col)) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
128 qDebug() << "Empty model. Failed to advance.";
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
129 return;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
130 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
131 } else {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
132 QModelIndex old = selection->selectedIndexes().first();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
133 if (!mSortModel->hasIndex(old.row() - 1, old.column())) {
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
134 qDebug() << "No less rows.";
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
135 return;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
136 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
137 row = old.row() - 1;
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
138 col = old.column();
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
139 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
140 QModelIndex newIdx = mSortModel->index(row, col);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
141 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
142 }
248d5d1cdb38 Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 2
diff changeset
143
2
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 void MetaDataView::selectNextRow() {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 QItemSelectionModel *selection = mView->selectionModel();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 QModelIndexList selected = selection->selectedIndexes();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147 int row = 0,
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 col = 0;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 if (selected.isEmpty()) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 qDebug() << "Selection empty. Start at row 0";
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 if (!mSortModel->hasIndex(row, col)) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 qDebug() << "Empty model. Failed to advance.";
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 return;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 } else {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 QModelIndex old = selection->selectedIndexes().first();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 if (!mSortModel->hasIndex(old.row() + 1, old.column())) {
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 qDebug() << "No more rows.";
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 return;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 row = old.row() + 1;
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 col = old.column();
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 }
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 QModelIndex newIdx = mSortModel->index(row, col);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
97d2c8869c39 First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 }
28
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
167
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
168 void MetaDataView::applyDefaultSort() {
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
169 QSettings settings;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
170 QString sortField = settings.value(SORT_COLUMN_KEY, SORT_COLUMN_DEFAULT).toString();
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
171 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool();
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
172
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
173 int idx = -1;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
174 for (int i=0; i < mSortModel->columnCount(); i++) {
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
175 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString();
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
176 if (entry.toLower() == sortField.toLower()) {
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
177 idx = 1;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
178 break;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
179 }
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
180 }
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
181 if (idx == -1) {
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
182 qDebug() << "Failed to find configured sort column: " << sortField;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
183 return;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
184 }
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
185 qDebug() << "Applying default sort order on column " << idx;
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
186 mView->sortByColumn(idx, sortAsc ? Qt::AscendingOrder : Qt::DescendingOrder);
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
187 }
4e16fbd10945 (issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
188
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)