annotate src/folderselectdialog.cpp @ 83:11aaa9214cfb

Add back to folder selection button
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 18 Jun 2015 18:55:00 +0200
parents ca8d3cfe8ba1
children 90c297a2a3dd
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
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 FolderSelectDialog::FolderSelectDialog(const QString& startFolder,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 const QString& folderPattern,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 const QString& pathLabel,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 QWidget * parent,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 Qt::WindowFlags f) :
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 QDialog(parent, f),
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 mCurFolder(startFolder),
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 mFolderPattern(folderPattern),
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 mPathLabelString(pathLabel),
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 mPathLabel(NULL),
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 mPathLineEdit(NULL)
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 mSortModel = new QSortFilterProxyModel();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 mModel = new QStandardItemModel();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 mShowPathSelection = !pathLabel.isEmpty();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 setupGUI();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 if (mShowPathSelection) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 mPathLabel->setText("<b>" + pathLabel + ":</b> ");
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 setFolder(mCurFolder);
50
07744e276579 Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents: 45
diff changeset
49 #ifndef Q_OS_WIN
07744e276579 Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents: 45
diff changeset
50 QIcon windowIcon = QIcon(":/icon-64.png");
07744e276579 Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents: 45
diff changeset
51 setWindowIcon(windowIcon);
07744e276579 Add icon also for non Windows systems
Andre Heinecke <andre.heinecke@intevation.de>
parents: 45
diff changeset
52 #endif
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 void FolderSelectDialog::setupGUI() {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 QVBoxLayout *base = new QVBoxLayout;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 QHBoxLayout *folderChangeArea = new QHBoxLayout;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 if (mShowPathSelection) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 mPathLabel = new QLabel;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 folderChangeArea->addWidget(mPathLabel);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 base->addLayout(folderChangeArea);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 QPushButton *folderSelect = new QPushButton();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 folderSelect->setToolTip(tr("Select folder"));
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 folderSelect->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon));
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 connect(folderSelect, &QPushButton::clicked, this,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 &FolderSelectDialog::changeFolderClicked);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 folderChangeArea->addWidget(folderSelect);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 mPathLineEdit = new QLineEdit;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 mPathLineEdit->setClearButtonEnabled(true);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 connect(mPathLineEdit, &QLineEdit::textChanged, this,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 &FolderSelectDialog::pathLineChanged);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 folderChangeArea->addWidget(mPathLineEdit);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 mGoButton = new QPushButton(tr("Go"));
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 mGoButton->setEnabled(false);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 folderChangeArea->addWidget(mGoButton);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 connect(mGoButton, &QPushButton::clicked, this,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 &FolderSelectDialog::goClicked);
79
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
82 connect(mPathLineEdit, &QLineEdit::returnPressed, this,
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
83 &FolderSelectDialog::goClicked);
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 }
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 mFilterWidget = new FilterWidget(mSortModel);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 base->addWidget(mFilterWidget);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 mView = new QTableView;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 mView->setModel(mSortModel);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 mView->resizeColumnsToContents();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 mView->setSelectionBehavior(QAbstractItemView::SelectRows);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 mView->setSelectionMode(QAbstractItemView::SingleSelection);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 mView->setSortingEnabled(true);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 mView->setEditTriggers(QAbstractItemView::NoEditTriggers);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 this, &FolderSelectDialog::selectionChanged);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 connect(mView, &QTableView::doubleClicked, this,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 &FolderSelectDialog::wantToAccept);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 base->addWidget(mView);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 QHBoxLayout * bottomButtons = new QHBoxLayout;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 base->addLayout(bottomButtons);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 mOkButton = new QPushButton(tr("Ok"));
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 mOkButton->setEnabled(false);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 connect(mOkButton, &QPushButton::clicked, this,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 &FolderSelectDialog::wantToAccept);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 bottomButtons->addStretch(-1);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 bottomButtons->addWidget(mOkButton);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 setLayout(base);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 void FolderSelectDialog::selectionChanged (const QItemSelection& selected,
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 const QItemSelection& deselected) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 mOkButton->setEnabled(!selected.indexes().isEmpty());
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 void FolderSelectDialog::pathLineChanged() {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 const QString path = mPathLineEdit->text();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 if (path.isEmpty()) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 mGoButton->setEnabled(false);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 return;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 }
79
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
127 mGoButton->setEnabled(true);
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 void FolderSelectDialog::goClicked() {
79
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
132 const QString path = mPathLineEdit->text();
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
133 QDir dir(path);
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
134 if (!dir.exists()) {
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
135 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
136 mGoButton->setEnabled(false);
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
137 return;
ca8d3cfe8ba1 Do not check path existence while typing
Andre Heinecke <andre.heinecke@intevation.de>
parents: 61
diff changeset
138 }
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 setFolder(mPathLineEdit->text());
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 QSettings settings;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 /* assuming go is only available in root folder mode */
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 settings.setValue(ROOT_FOLDER_KEY, mPathLineEdit->text());
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 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
146 if (folder.isEmpty()) {
de148cd023a1 Do not print errors if the folder is not set.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
147 return;
de148cd023a1 Do not print errors if the folder is not set.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
148 }
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 mCurFolder = folder;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 if (mPathLineEdit) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 mPathLineEdit->setText(mCurFolder);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 mModel->clear();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 mModel->setHorizontalHeaderLabels(columns);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 QDir dir(folder);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 qDebug() << "Folder set to: " << folder;
45
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
159 QStringList errors;
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 foreach (const QString & subfolder, dir.entryList(QDir::Dirs |
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 QDir::Readable |
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 QDir::NoDotAndDotDot)) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 qDebug() << "Looking at: " << subfolder;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 QStringList itemData = subfolder.split(PATTERN_SEPERATOR);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 if (itemData.size() != columns.size()) {
45
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
166 errors << subfolder;
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 continue;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 QList<QStandardItem*> items;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 foreach (const QString& part, itemData) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171 QStandardItem * item = new QStandardItem(part);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 item->setData(dir.absoluteFilePath(subfolder));
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 items.append(item);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 mModel->appendRow(items);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 mSortModel->setSourceModel(mModel);
45
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
178 if (!errors.isEmpty()) {
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
179 QString errMsg = tr("The following folders did not match the pattern: %1").arg(mFolderPattern);
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
180 errMsg += "\n" + errors.join("\n");
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
181 QMessageBox::warning(this, tr("Failed to parse some folders."), errMsg);
213d9163dab0 Add error handling to the folder selection dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 25
diff changeset
182 }
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::wantToAccept() {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 QItemSelectionModel *selection = mView->selectionModel();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 QModelIndexList selected = selection->selectedIndexes();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 if (selected.isEmpty()) { /* Ok should not be enabled in that case */
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189 return;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 const QString folder = selected[0].data(Qt::UserRole + 1).toString();
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 emit folderSelected(folder);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 accept();
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 void FolderSelectDialog::changeFolderClicked()
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 const QString oldFolder = mCurFolder;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 const QString startLoc = mCurFolder.isEmpty() ?
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) :
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 mCurFolder;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204 QString outFolder = QFileDialog::getExistingDirectory(
12
971bd39a6116 German translations
Andre Heinecke <andre.heinecke@intevation.de>
parents: 9
diff changeset
205 this, tr("Select %1").arg(mPathLabelString),
9
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 startLoc);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207 if (outFolder.isEmpty()) {
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208 /* User aborted */
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 return;
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210 }
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211 setFolder(outFolder);
e3c8f61e45a9 Implement folderselection dialogs
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)