comparison src/folderselectdialog.cpp @ 109:0ad468912ff3

Add warning about folder names to widget
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 08 Dec 2016 15:23:38 +0100
parents 4302ca793c5a
children 48141e3c8903
comparison
equal deleted inserted replaced
108:a3f060eb199f 109:0ad468912ff3
86 86
87 void FolderSelectDialog::setupGUI() { 87 void FolderSelectDialog::setupGUI() {
88 QVBoxLayout *base = new QVBoxLayout; 88 QVBoxLayout *base = new QVBoxLayout;
89 QHBoxLayout *folderChangeArea = new QHBoxLayout; 89 QHBoxLayout *folderChangeArea = new QHBoxLayout;
90 90
91 mErrorWidget = new QWidget;
92
93 /* Handling for filename errors */
94 QHBoxLayout *errorArea = new QHBoxLayout;
95 mErrorWidget->setLayout(errorArea);
96 QPushButton *errorPush = new QPushButton(tr("Show Details"));
97
98 QLabel *errorLabel = new QLabel(tr("Warning: Some folder names could not be parsed."));
99 connect(errorPush, &QPushButton::clicked, this, [this] () {
100 QMessageBox::information(this, tr("Failed to parse some folder names."), mErrMsg);
101 });
102 errorArea->addWidget(errorLabel);
103 errorArea->addWidget(errorPush);
104 errorArea->addStretch(1);
105 mErrorWidget->setVisible(false);
106
91 if (mShowPathSelection) { 107 if (mShowPathSelection) {
92 mPathLabel = new QLabel; 108 mPathLabel = new QLabel;
93 folderChangeArea->addWidget(mPathLabel); 109 folderChangeArea->addWidget(mPathLabel);
94 base->addLayout(folderChangeArea); 110 base->addLayout(folderChangeArea);
95 111
119 connect(mPathLineEdit, &QLineEdit::returnPressed, this, 135 connect(mPathLineEdit, &QLineEdit::returnPressed, this,
120 &FolderSelectDialog::goClicked); 136 &FolderSelectDialog::goClicked);
121 } 137 }
122 138
123 mFilterWidget = new FilterWidget(mSortModel, false); 139 mFilterWidget = new FilterWidget(mSortModel, false);
140
141 base->addWidget(mErrorWidget);
124 base->addWidget(mFilterWidget); 142 base->addWidget(mFilterWidget);
125 connect(mSortModel, &QSortFilterProxyModel::sourceModelChanged, 143 connect(mSortModel, &QSortFilterProxyModel::sourceModelChanged,
126 mFilterWidget, &FilterWidget::headersChanged); 144 mFilterWidget, &FilterWidget::headersChanged);
127 145
128 mView = new QTableView; 146 mView = new QTableView;
152 if (!mShowPathSelection) { 170 if (!mShowPathSelection) {
153 backBtn = new QPushButton(tr("Back")); 171 backBtn = new QPushButton(tr("Back"));
154 backBtn->setToolTip(tr("Back to exam selection.")); 172 backBtn->setToolTip(tr("Back to exam selection."));
155 connect(backBtn, &QPushButton::clicked, this, 173 connect(backBtn, &QPushButton::clicked, this,
156 &FolderSelectDialog::backClicked); 174 &FolderSelectDialog::backClicked);
175 connect(backBtn, &QPushButton::clicked, mErrorWidget,
176 &QWidget::hide);
157 bottomButtons->addWidget(backBtn); 177 bottomButtons->addWidget(backBtn);
158 } 178 }
159 179
160 bottomButtons->addWidget(mOkButton); 180 bottomButtons->addWidget(mOkButton);
161 setLayout(base); 181 setLayout(base);
241 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); 261 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR);
242 int patternSize = columns.size(); 262 int patternSize = columns.size();
243 QDir dir(folder); 263 QDir dir(folder);
244 mModel->clear(); 264 mModel->clear();
245 qDebug() << "Folder set to: " << folder; 265 qDebug() << "Folder set to: " << folder;
266 QStringList errors;
246 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | 267 foreach (const QString & subfolder, dir.entryList(QDir::Dirs |
247 QDir::Readable | 268 QDir::Readable |
248 QDir::NoDotAndDotDot)) { 269 QDir::NoDotAndDotDot)) {
249 qDebug() << "Looking at: " << subfolder; 270 qDebug() << "Looking at: " << subfolder;
250 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); 271 QStringList itemData = subfolder.split(PATTERN_SEPERATOR);
251 if (itemData.size() != patternSize) { 272 if (itemData.size() != patternSize) {
273 errors << subfolder;
252 qDebug() << "Folder does not match pattern: " << subfolder; 274 qDebug() << "Folder does not match pattern: " << subfolder;
253 continue; 275 continue;
254 } 276 }
255 QList<QStandardItem*> items; 277 QList<QStandardItem*> items;
256 foreach (const QString& part, itemData) { 278 foreach (const QString& part, itemData) {
273 } 295 }
274 } 296 }
275 mModel->appendRow(items); 297 mModel->appendRow(items);
276 } 298 }
277 mModel->setHorizontalHeaderLabels(columns); 299 mModel->setHorizontalHeaderLabels(columns);
300
301 if (!errors.isEmpty()) {
302 mErrMsg = tr("The following folders did not match the pattern: %1").arg(mFolderPattern);
303 mErrMsg += "\n" + errors.join("\n");
304 mErrorWidget->setVisible(true);
305 } else {
306 mErrorWidget->setVisible(false);
307 }
308
278 mSortModel->setSourceModel(mModel); 309 mSortModel->setSourceModel(mModel);
279 mView->resizeColumnsToContents(); 310 mView->resizeColumnsToContents();
280 } 311 }
281 312
282 void FolderSelectDialog::wantToAccept() { 313 void FolderSelectDialog::wantToAccept() {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)