changeset 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 a3f060eb199f
children 48141e3c8903
files src/folderselectdialog.cpp src/folderselectdialog.h
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/folderselectdialog.cpp	Thu Dec 08 15:22:51 2016 +0100
+++ b/src/folderselectdialog.cpp	Thu Dec 08 15:23:38 2016 +0100
@@ -88,6 +88,22 @@
     QVBoxLayout *base = new QVBoxLayout;
     QHBoxLayout *folderChangeArea = new QHBoxLayout;
 
+    mErrorWidget = new QWidget;
+
+    /* Handling for filename errors */
+    QHBoxLayout *errorArea = new QHBoxLayout;
+    mErrorWidget->setLayout(errorArea);
+    QPushButton *errorPush = new QPushButton(tr("Show Details"));
+
+    QLabel *errorLabel = new QLabel(tr("Warning: Some folder names could not be parsed."));
+    connect(errorPush, &QPushButton::clicked, this, [this] () {
+                QMessageBox::information(this, tr("Failed to parse some folder names."), mErrMsg);
+            });
+    errorArea->addWidget(errorLabel);
+    errorArea->addWidget(errorPush);
+    errorArea->addStretch(1);
+    mErrorWidget->setVisible(false);
+
     if (mShowPathSelection) {
         mPathLabel = new QLabel;
         folderChangeArea->addWidget(mPathLabel);
@@ -121,6 +137,8 @@
     }
 
     mFilterWidget = new FilterWidget(mSortModel, false);
+
+    base->addWidget(mErrorWidget);
     base->addWidget(mFilterWidget);
     connect(mSortModel, &QSortFilterProxyModel::sourceModelChanged,
             mFilterWidget, &FilterWidget::headersChanged);
@@ -154,6 +172,8 @@
         backBtn->setToolTip(tr("Back to exam selection."));
         connect(backBtn, &QPushButton::clicked, this,
                 &FolderSelectDialog::backClicked);
+        connect(backBtn, &QPushButton::clicked, mErrorWidget,
+                &QWidget::hide);
         bottomButtons->addWidget(backBtn);
     }
 
@@ -243,12 +263,14 @@
     QDir dir(folder);
     mModel->clear();
     qDebug() << "Folder set to: " << folder;
+    QStringList errors;
     foreach (const QString & subfolder, dir.entryList(QDir::Dirs |
                                                       QDir::Readable |
                                                       QDir::NoDotAndDotDot)) {
         qDebug() << "Looking at: " << subfolder;
         QStringList itemData = subfolder.split(PATTERN_SEPERATOR);
         if (itemData.size() != patternSize) {
+            errors << subfolder;
             qDebug() << "Folder does not match pattern: " << subfolder;
             continue;
         }
@@ -275,6 +297,15 @@
         mModel->appendRow(items);
     }
     mModel->setHorizontalHeaderLabels(columns);
+
+    if (!errors.isEmpty()) {
+        mErrMsg = tr("The following folders did not match the pattern: %1").arg(mFolderPattern);
+        mErrMsg += "\n" + errors.join("\n");
+        mErrorWidget->setVisible(true);
+    } else {
+        mErrorWidget->setVisible(false);
+    }
+
     mSortModel->setSourceModel(mModel);
     mView->resizeColumnsToContents();
 }
--- a/src/folderselectdialog.h	Thu Dec 08 15:22:51 2016 +0100
+++ b/src/folderselectdialog.h	Thu Dec 08 15:23:38 2016 +0100
@@ -82,6 +82,8 @@
     QLineEdit *mPathLineEdit;
     QPushButton *mGoButton,
                 *mOkButton;
+    QWidget *mErrorWidget;
+    QString mErrMsg;
     bool mShowPathSelection;
 };
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)