annotate src/folderselectdialog.cpp @ 38:26e1521b9afd

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