GUI: Use SelectFilesDialog result if OK button is pressed

This commit is contained in:
Daniel Marjamäki 2012-01-12 07:51:59 +01:00
parent feb187cb02
commit 34105cb17e
4 changed files with 52 additions and 9 deletions

View File

@ -351,7 +351,9 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
// selection dialog which is a lot more usable than QT:s own dialog. // selection dialog which is a lot more usable than QT:s own dialog.
if (mode == QFileDialog::ExistingFiles) { if (mode == QFileDialog::ExistingFiles) {
SelectFilesDialog dialog(this); SelectFilesDialog dialog(this);
dialog.exec(); if (dialog.exec() == QDialog::Accepted) {
selected = dialog.getFiles();
}
/* /*
selected = QFileDialog::getOpenFileNames(this, selected = QFileDialog::getOpenFileNames(this,
tr("Select files to check"), tr("Select files to check"),

View File

@ -1,6 +1,7 @@
#include "selectfilesdialog.h" #include "selectfilesdialog.h"
#include "ui_selectfilesdialog.h" #include "ui_selectfilesdialog.h"
#include "filelist.h"
#include <QTreeView> #include <QTreeView>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -34,9 +35,13 @@ private:
public: public:
SelectFilesModel() : QFileSystemModel() { SelectFilesModel() : QFileSystemModel() {
QStringList f; class FileLister : private FileList {
f << "*.cpp"; public:
setNameFilters(f); static QStringList filters() {
return GetDefaultFilters();
}
};
setNameFilters(FileLister::filters());
setNameFilterDisables(false); setNameFilterDisables(false);
setRootPath("/"); setRootPath("/");
} }
@ -99,11 +104,31 @@ public:
} }
return QFileSystemModel::setData(index, value, role); return QFileSystemModel::setData(index, value, role);
} }
QStringList getFiles() const {
QStringList ret;
// List all files in "selected" folders..
FileList fileLister;
fileLister.AddPathList(selected);
ret = fileLister.GetFileList();
// Remove all items from ret that are unselected but not selected..
for (int i = ret.size() - 1; i >= 0; i--) {
int unselindex = getindex(unselected, ret[i]);
if (unselindex == -1)
continue;
// both selected and unselected, check which to rely on
int selindex = getindex(selected, ret[i]);
if (selected[selindex].size() < unselected[unselindex].size())
ret.removeAt(i);
}
return ret;
}
}; };
SelectFilesDialog::~SelectFilesDialog() {
delete ui;
}
SelectFilesDialog::SelectFilesDialog(QWidget *w) : SelectFilesDialog::SelectFilesDialog(QWidget *w) :
@ -112,9 +137,19 @@ SelectFilesDialog::SelectFilesDialog(QWidget *w) :
{ {
ui->setupUi(this); ui->setupUi(this);
ui->treeView->setModel(new SelectFilesModel); selectfilesmodel = new SelectFilesModel;
ui->treeView->setModel(selectfilesmodel);
for (int i = 1; i < 4; ++i) for (int i = 1; i < 4; ++i)
ui->treeView->setColumnHidden(i, true); ui->treeView->setColumnHidden(i, true);
} }
SelectFilesDialog::~SelectFilesDialog()
{
delete ui;
}
QStringList SelectFilesDialog::getFiles() const
{
return selectfilesmodel->getFiles();
}

View File

@ -3,18 +3,24 @@
#define selectfilesdialogH #define selectfilesdialogH
#include <QDialog> #include <QDialog>
#include <QStringList>
namespace Ui { namespace Ui {
class SelectFilesDialog; class SelectFilesDialog;
} }
class SelectFilesModel;
class SelectFilesDialog : public QDialog { class SelectFilesDialog : public QDialog {
public: public:
explicit SelectFilesDialog(QWidget *w); explicit SelectFilesDialog(QWidget *w);
~SelectFilesDialog(); ~SelectFilesDialog();
QStringList getFiles() const;
private: private:
Ui::SelectFilesDialog *ui; Ui::SelectFilesDialog *ui;
SelectFilesModel *selectfilesmodel;
}; };
#endif #endif

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Select files to check</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>