Mercurial > retraceit
annotate src/folderselectdialog.cpp @ 112:9daf778feaf1 1.4
Fix usage of WIN32 macro. With c++11 this is no longer set.
_WIN32 is the better macro to use anyway.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 08 Dec 2016 15:34:07 +0100 |
parents | 48141e3c8903 |
children |
rev | line source |
---|---|
25
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
12
diff
changeset
|
1 /* Copyright (C) 2015 by ETH Zürich |
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
12
diff
changeset
|
2 * Software engineering by Intevation GmbH |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * See LICENSE.txt for details. |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "folderselectdialog.h" |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "constants.h" |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QSortFilterProxyModel> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QStandardItemModel> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #include <QTableView> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 #include <QVBoxLayout> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #include <QLineEdit> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include <QLabel> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #include <QApplication> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #include <QStyle> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #include <QFileDialog> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 #include <QStandardPaths> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 #include <QPushButton> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 #include <QHeaderView> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 #include <QDebug> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 #include <QSettings> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 #include <QStringList> |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 #include <QStandardItem> |
45
213d9163dab0
Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
27 #include <QMessageBox> |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 |
84
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
29 static ulong ipStringToLong(const QString str) { |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
30 QStringList octets = str.split("."); |
99
0cf81afa82c1
Fix compiler warning about logic error
Andre Heinecke <andre.heinecke@intevation.de>
parents:
90
diff
changeset
|
31 if (!(octets.size() > 3)) { |
84
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
32 qWarning() << "invalid call to str to long"; |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
33 return 0; |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
34 } |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
35 ulong s1 = octets.at(0).toLong(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
36 ulong s2 = octets.at(1).toLong(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
37 ulong s3 = octets.at(2).toLong(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
38 ulong s4 = octets.at(3).toLong(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
39 |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
40 return (s1 << 24) | (s2 << 16) | (s3 << 8) | s4; |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
41 } |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
42 |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
43 class IPAwareSortModel : public QSortFilterProxyModel |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
44 { |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
45 public: |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
46 bool lessThan(const QModelIndex &left, |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
47 const QModelIndex &right) const |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
48 { |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
49 QString leftString = sourceModel()->data(left).toString(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
50 QString rightString = sourceModel()->data(right).toString(); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
51 |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
52 static QRegExp ipPattern("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
53 if (ipPattern.indexIn(leftString) != -1 && ipPattern.indexIn(rightString) != -1) { |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
54 return ipStringToLong(leftString) > ipStringToLong(rightString); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
55 } else { |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
56 return QSortFilterProxyModel::lessThan(left, right); |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
57 } |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
58 } |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
59 }; |
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
60 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 FolderSelectDialog::FolderSelectDialog(const QString& startFolder, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 const QString& folderPattern, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 const QString& pathLabel, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 QWidget * parent, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 Qt::WindowFlags f) : |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 QDialog(parent, f), |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 mCurFolder(startFolder), |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 mFolderPattern(folderPattern), |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 mPathLabelString(pathLabel), |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 mPathLabel(NULL), |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 mPathLineEdit(NULL) |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 { |
84
90c297a2a3dd
Sort IP Addresses by their actual number in folder selection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
79
diff
changeset
|
73 mSortModel = new IPAwareSortModel(); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 mModel = new QStandardItemModel(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 mShowPathSelection = !pathLabel.isEmpty(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 setupGUI(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 if (mShowPathSelection) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 mPathLabel->setText("<b>" + pathLabel + ":</b> "); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 setFolder(mCurFolder); |
50
07744e276579
Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents:
45
diff
changeset
|
81 #ifndef Q_OS_WIN |
07744e276579
Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents:
45
diff
changeset
|
82 QIcon windowIcon = QIcon(":/icon-64.png"); |
07744e276579
Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents:
45
diff
changeset
|
83 setWindowIcon(windowIcon); |
07744e276579
Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents:
45
diff
changeset
|
84 #endif |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 void FolderSelectDialog::setupGUI() { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 QVBoxLayout *base = new QVBoxLayout; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 QHBoxLayout *folderChangeArea = new QHBoxLayout; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
91 mErrorWidget = new QWidget; |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
92 |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
93 /* Handling for filename errors */ |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
94 QHBoxLayout *errorArea = new QHBoxLayout; |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
95 mErrorWidget->setLayout(errorArea); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
96 QPushButton *errorPush = new QPushButton(tr("Show Details")); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
97 |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
98 QLabel *errorLabel = new QLabel(tr("Warning: Some folder names could not be parsed.")); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
99 connect(errorPush, &QPushButton::clicked, this, [this] () { |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
100 QMessageBox::information(this, tr("Failed to parse some folder names."), mErrMsg); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
101 }); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
102 errorArea->addWidget(errorLabel); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
103 errorArea->addWidget(errorPush); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
104 errorArea->addStretch(1); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
105 mErrorWidget->setVisible(false); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
106 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 if (mShowPathSelection) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 mPathLabel = new QLabel; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 folderChangeArea->addWidget(mPathLabel); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 base->addLayout(folderChangeArea); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 QPushButton *folderSelect = new QPushButton(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 folderSelect->setToolTip(tr("Select folder")); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 folderSelect->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon)); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 connect(folderSelect, &QPushButton::clicked, this, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 &FolderSelectDialog::changeFolderClicked); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 folderChangeArea->addWidget(folderSelect); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 mPathLineEdit = new QLineEdit; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 mPathLineEdit->setClearButtonEnabled(true); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 connect(mPathLineEdit, &QLineEdit::textChanged, this, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 &FolderSelectDialog::pathLineChanged); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 folderChangeArea->addWidget(mPathLineEdit); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 mGoButton = new QPushButton(tr("Go")); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 mGoButton->setEnabled(false); |
90
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
127 |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
128 QPushButton *backBtn = new QPushButton; |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
129 backBtn->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowBack)); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
130 backBtn->setToolTip(tr("Back to exam selection.")); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
131 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 folderChangeArea->addWidget(mGoButton); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 connect(mGoButton, &QPushButton::clicked, this, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 &FolderSelectDialog::goClicked); |
79
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
135 connect(mPathLineEdit, &QLineEdit::returnPressed, this, |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
136 &FolderSelectDialog::goClicked); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
86
diff
changeset
|
139 mFilterWidget = new FilterWidget(mSortModel, false); |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
140 |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
141 base->addWidget(mErrorWidget); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 base->addWidget(mFilterWidget); |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
86
diff
changeset
|
143 connect(mSortModel, &QSortFilterProxyModel::sourceModelChanged, |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
86
diff
changeset
|
144 mFilterWidget, &FilterWidget::headersChanged); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 mView = new QTableView; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 mView->setModel(mSortModel); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 mView->setSelectionBehavior(QAbstractItemView::SelectRows); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 mView->setSelectionMode(QAbstractItemView::SingleSelection); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 mView->setSortingEnabled(true); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 mView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 this, &FolderSelectDialog::selectionChanged); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 connect(mView, &QTableView::doubleClicked, this, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 &FolderSelectDialog::wantToAccept); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 base->addWidget(mView); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 QHBoxLayout * bottomButtons = new QHBoxLayout; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 base->addLayout(bottomButtons); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 mOkButton = new QPushButton(tr("Ok")); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 mOkButton->setEnabled(false); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 connect(mOkButton, &QPushButton::clicked, this, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 &FolderSelectDialog::wantToAccept); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 bottomButtons->addStretch(-1); |
90
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
168 |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
169 QPushButton *backBtn = NULL; |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
170 if (!mShowPathSelection) { |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
171 backBtn = new QPushButton(tr("Back")); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
172 backBtn->setToolTip(tr("Back to exam selection.")); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
173 connect(backBtn, &QPushButton::clicked, this, |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
174 &FolderSelectDialog::backClicked); |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
175 connect(backBtn, &QPushButton::clicked, mErrorWidget, |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
176 &QWidget::hide); |
90
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
177 bottomButtons->addWidget(backBtn); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
178 } |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
179 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 bottomButtons->addWidget(mOkButton); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 setLayout(base); |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
182 resize(700, 600); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 void FolderSelectDialog::selectionChanged (const QItemSelection& selected, |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 const QItemSelection& deselected) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
187 mOkButton->setEnabled(!selected.indexes().isEmpty()); |
90
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
188 if (mOkButton->isEnabled()) { |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
189 mOkButton->setFocus(); |
c3000fa6ca56
Add back button to subfolder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents:
88
diff
changeset
|
190 } |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
191 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
192 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
193 void FolderSelectDialog::pathLineChanged() { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
194 const QString path = mPathLineEdit->text(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
195 if (path.isEmpty()) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
196 mGoButton->setEnabled(false); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
197 return; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
198 } |
79
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
199 mGoButton->setEnabled(true); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
200 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
201 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
202 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 void FolderSelectDialog::goClicked() { |
79
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
204 const QString path = mPathLineEdit->text(); |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
205 QDir dir(path); |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
206 if (!dir.exists()) { |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
207 QMessageBox::warning(this, tr("Error!"), tr("Failed to access directory: '%1'").arg(path)); |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
208 mGoButton->setEnabled(false); |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
209 return; |
ca8d3cfe8ba1
Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents:
61
diff
changeset
|
210 } |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 setFolder(mPathLineEdit->text()); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 QSettings settings; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
213 /* assuming go is only available in root folder mode */ |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 settings.setValue(ROOT_FOLDER_KEY, mPathLineEdit->text()); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
217 QString stripQuotes (const QString &in) |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
218 { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
219 QString out = in; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
220 if (in.startsWith("\"")) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
221 out = out.right(out.size()-1); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
222 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
223 if (in.endsWith("\"")) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
224 out = out.left(out.size()-1); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
225 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
226 return out; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
227 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
228 |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
229 QMap <QString, QString> readExtraColumns(const QString &path) |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
230 { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
231 QMap <QString, QString> ret; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
232 |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
233 QFile file(path); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
234 if (!file.open(QIODevice::ReadOnly)) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
235 qDebug () << "Failed to open: " << path; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
236 return ret; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
237 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
238 QTextStream in(&file); |
110
48141e3c8903
Set textcodec for user env file to UTF-8
Andre Heinecke <andre.heinecke@intevation.de>
parents:
109
diff
changeset
|
239 in.setCodec("UTF-8"); |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
240 while (!in.atEnd()) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
241 QString line = in.readLine(); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
242 int equalsign = line.indexOf("="); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
243 if (equalsign != -1) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
244 QString name = stripQuotes(line.left(equalsign).replace (QStringLiteral("export "), "")); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
245 QString value = stripQuotes(line.right(line.size() - equalsign - 1)); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
246 ret.insert (name, value); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
247 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
248 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
249 return ret; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
250 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
251 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
252 void FolderSelectDialog::setFolder(const QString& folder) { |
61
de148cd023a1
Do not print errors if the folder is not set.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
50
diff
changeset
|
253 if (folder.isEmpty()) { |
de148cd023a1
Do not print errors if the folder is not set.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
50
diff
changeset
|
254 return; |
de148cd023a1
Do not print errors if the folder is not set.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
50
diff
changeset
|
255 } |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
256 mCurFolder = folder; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
257 if (mPathLineEdit) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
258 mPathLineEdit->setText(mCurFolder); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
259 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
260 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
261 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
262 int patternSize = columns.size(); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
263 QDir dir(folder); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
264 mModel->clear(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
265 qDebug() << "Folder set to: " << folder; |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
266 QStringList errors; |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
267 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
268 QDir::Readable | |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
269 QDir::NoDotAndDotDot)) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
270 qDebug() << "Looking at: " << subfolder; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
271 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); |
112
9daf778feaf1
Fix usage of WIN32 macro. With c++11 this is no longer set.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
110
diff
changeset
|
272 qDebug () << "Item Data size" << itemData.size() << patternSize |
9daf778feaf1
Fix usage of WIN32 macro. With c++11 this is no longer set.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
110
diff
changeset
|
273 << itemData; |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
274 if (itemData.size() != patternSize) { |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
275 errors << subfolder; |
100
7c84242971cb
Don't warn if folders do not match pattern
Andre Heinecke <andre.heinecke@intevation.de>
parents:
99
diff
changeset
|
276 qDebug() << "Folder does not match pattern: " << subfolder; |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
277 continue; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
278 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
279 QList<QStandardItem*> items; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
280 foreach (const QString& part, itemData) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
281 QStandardItem * item = new QStandardItem(part); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
282 item->setData(dir.absoluteFilePath(subfolder)); |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
283 QFileInfo fi (dir.absoluteFilePath(subfolder + "/.exam-setup-user")); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
284 items.append(item); |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
285 if (fi.isReadable()) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
286 const QMap<QString, QString> map = readExtraColumns (fi.filePath()); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
287 |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
288 Q_FOREACH (const QString &name, map.keys()) |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
289 { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
290 qDebug() << "Adding extra column: " << name; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
291 if (!columns.contains(name)) { |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
292 columns << name; |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
293 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
294 QStandardItem * subitem = new QStandardItem(map[name]); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
295 items.append(subitem); |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
296 } |
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
297 } |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
298 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
299 mModel->appendRow(items); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
300 } |
101
8ed21aa68021
Read .exam-setup-user in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
100
diff
changeset
|
301 mModel->setHorizontalHeaderLabels(columns); |
109
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
302 |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
303 if (!errors.isEmpty()) { |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
304 mErrMsg = tr("The following folders did not match the pattern: %1").arg(mFolderPattern); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
305 mErrMsg += "\n" + errors.join("\n"); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
306 mErrorWidget->setVisible(true); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
307 } else { |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
308 mErrorWidget->setVisible(false); |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
309 } |
0ad468912ff3
Add warning about folder names to widget
Andre Heinecke <andre.heinecke@intevation.de>
parents:
104
diff
changeset
|
310 |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
311 mSortModel->setSourceModel(mModel); |
86
a32406f8832f
Fix resize to contents in folderselection
Andre Heinecke <andre.heinecke@intevation.de>
parents:
84
diff
changeset
|
312 mView->resizeColumnsToContents(); |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
313 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
314 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
315 void FolderSelectDialog::wantToAccept() { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
316 QItemSelectionModel *selection = mView->selectionModel(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
317 QModelIndexList selected = selection->selectedIndexes(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
318 if (selected.isEmpty()) { /* Ok should not be enabled in that case */ |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
319 return; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
320 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
321 const QString folder = selected[0].data(Qt::UserRole + 1).toString(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
322 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
323 emit folderSelected(folder); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
324 accept(); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
325 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
326 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
327 void FolderSelectDialog::changeFolderClicked() |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
328 { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
329 const QString oldFolder = mCurFolder; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
330 const QString startLoc = mCurFolder.isEmpty() ? |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
331 QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) : |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
332 mCurFolder; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
333 |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
334 QString outFolder = QFileDialog::getExistingDirectory( |
12
971bd39a6116
German translations
Andre Heinecke <andre.heinecke@intevation.de>
parents:
9
diff
changeset
|
335 this, tr("Select %1").arg(mPathLabelString), |
9
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
336 startLoc); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
337 if (outFolder.isEmpty()) { |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
338 /* User aborted */ |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
339 return; |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
340 } |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
341 setFolder(outFolder); |
e3c8f61e45a9
Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
342 } |