Mercurial > retraceit
comparison src/folderselectdialog.cpp @ 45:213d9163dab0
Add error handling to the folder selection dialog
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 06 May 2015 19:45:44 +0200 |
parents | 64a51a42c01f |
children | 07744e276579 |
comparison
equal
deleted
inserted
replaced
44:73e6b6b12412 | 45:213d9163dab0 |
---|---|
22 #include <QHeaderView> | 22 #include <QHeaderView> |
23 #include <QDebug> | 23 #include <QDebug> |
24 #include <QSettings> | 24 #include <QSettings> |
25 #include <QStringList> | 25 #include <QStringList> |
26 #include <QStandardItem> | 26 #include <QStandardItem> |
27 #include <QMessageBox> | |
27 | 28 |
28 FolderSelectDialog::FolderSelectDialog(const QString& startFolder, | 29 FolderSelectDialog::FolderSelectDialog(const QString& startFolder, |
29 const QString& folderPattern, | 30 const QString& folderPattern, |
30 const QString& pathLabel, | 31 const QString& pathLabel, |
31 QWidget * parent, | 32 QWidget * parent, |
143 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); | 144 QStringList columns = mFolderPattern.split(PATTERN_SEPERATOR); |
144 mModel->clear(); | 145 mModel->clear(); |
145 mModel->setHorizontalHeaderLabels(columns); | 146 mModel->setHorizontalHeaderLabels(columns); |
146 QDir dir(folder); | 147 QDir dir(folder); |
147 qDebug() << "Folder set to: " << folder; | 148 qDebug() << "Folder set to: " << folder; |
149 QStringList errors; | |
148 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | | 150 foreach (const QString & subfolder, dir.entryList(QDir::Dirs | |
149 QDir::Readable | | 151 QDir::Readable | |
150 QDir::NoDotAndDotDot)) { | 152 QDir::NoDotAndDotDot)) { |
151 qDebug() << "Looking at: " << subfolder; | 153 qDebug() << "Looking at: " << subfolder; |
152 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); | 154 QStringList itemData = subfolder.split(PATTERN_SEPERATOR); |
153 if (itemData.size() != columns.size()) { | 155 if (itemData.size() != columns.size()) { |
154 qDebug() << "Failed to parse: " << subfolder; | 156 errors << subfolder; |
155 continue; | 157 continue; |
156 } | 158 } |
157 QList<QStandardItem*> items; | 159 QList<QStandardItem*> items; |
158 foreach (const QString& part, itemData) { | 160 foreach (const QString& part, itemData) { |
159 QStandardItem * item = new QStandardItem(part); | 161 QStandardItem * item = new QStandardItem(part); |
161 items.append(item); | 163 items.append(item); |
162 } | 164 } |
163 mModel->appendRow(items); | 165 mModel->appendRow(items); |
164 } | 166 } |
165 mSortModel->setSourceModel(mModel); | 167 mSortModel->setSourceModel(mModel); |
168 if (!errors.isEmpty()) { | |
169 QString errMsg = tr("The following folders did not match the pattern: %1").arg(mFolderPattern); | |
170 errMsg += "\n" + errors.join("\n"); | |
171 QMessageBox::warning(this, tr("Failed to parse some folders."), errMsg); | |
172 } | |
166 } | 173 } |
167 | 174 |
168 void FolderSelectDialog::wantToAccept() { | 175 void FolderSelectDialog::wantToAccept() { |
169 QItemSelectionModel *selection = mView->selectionModel(); | 176 QItemSelectionModel *selection = mView->selectionModel(); |
170 QModelIndexList selected = selection->selectedIndexes(); | 177 QModelIndexList selected = selection->selectedIndexes(); |