diff --git a/gui/gui.pro b/gui/gui.pro index 3d94f6c5a..c04f8377a 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -79,7 +79,8 @@ HEADERS += aboutdialog.h \ txtreport.h \ xmlreport.h \ xmlreportv1.h \ - xmlreportv2.h + xmlreportv2.h \ + selectfilesdialog.h SOURCES += aboutdialog.cpp \ application.cpp \ @@ -110,7 +111,8 @@ SOURCES += aboutdialog.cpp \ txtreport.cpp \ xmlreport.cpp \ xmlreportv1.cpp \ - xmlreportv2.cpp + xmlreportv2.cpp \ + selectfilesdialog.cpp win32 { DEFINES += _CRT_SECURE_NO_WARNINGS diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c4d8a9e14..d6159998d 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -41,6 +41,7 @@ #include "logview.h" #include "filelist.h" #include "showtypes.h" +#include "selectfilesdialog.h" static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html"); @@ -347,9 +348,13 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode) // QFileDialog::getExistingDirectory() because they show native Windows // selection dialog which is a lot more usable than QT:s own dialog. if (mode == QFileDialog::ExistingFiles) { - selected = QFileDialog::getOpenFileNames(this, - tr("Select files to check"), - mSettings->value(SETTINGS_CHECK_PATH, "").toString()); + SelectFilesDialog *dialog = new SelectFilesDialog; + dialog->exec(); + /* + selected = QFileDialog::getOpenFileNames(this, + tr("Select files to check"), + mSettings->value(SETTINGS_CHECK_PATH, "").toString()); + */ if (selected.isEmpty()) mCurrentDirectory.clear(); else { diff --git a/gui/selectfilesdialog.cpp b/gui/selectfilesdialog.cpp new file mode 100644 index 000000000..26ea6ed3d --- /dev/null +++ b/gui/selectfilesdialog.cpp @@ -0,0 +1,103 @@ + +#include "selectfilesdialog.h" + +#include +#include +#include +#include +#include +#include + +class SelectFilesModel : public QFileSystemModel { +private: + QList selected; + QList unselected; + + int getindex(const QList &s, const QString &filepath) const { + for (int i = 0; i < s.size(); ++i) { + if (filepath.startsWith(s[i])) + return i; + } + return -1; + } + +public: + SelectFilesModel() : QFileSystemModel() { + QStringList f; + f << "*.cpp"; + setNameFilters(f); + setNameFilterDisables(false); + } + + Qt::ItemFlags flags(const QModelIndex& index) const { + if (index.column() == 0) + return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable; + return QFileSystemModel::flags(index); + } + + QVariant data(const QModelIndex& index, int role=Qt::DisplayRole) const { + if (role == Qt::CheckStateRole) { + const QString filepath = filePath(index); + if (getindex(selected,filepath) >= 0 && + getindex(unselected,filepath) == -1) + return Qt::Checked; + + return Qt::Unchecked; + } + return QFileSystemModel::data(index, role); + } + + bool setData(const QModelIndex& index, const QVariant& value, int role) { + if (role == Qt::CheckStateRole) { + const QString filepath = filePath(index); + if (unselected.indexOf(filepath) != -1) { + // remove unchecked path + unselected.removeAll(filepath); + } else if (selected.indexOf(filepath) != -1) { + // remove checked path + selected.removeAll(filepath); + + // remove child unchecked paths + int i; + while ((i = getindex(unselected,filepath)) != -1) { + unselected.removeAt(i); + } + } else { + if (getindex(selected,filepath) == -1) + selected.append(filepath); + else + unselected.append(filepath); + } + + if (rowCount(index) > 0) + emit(dataChanged(index, index.child(rowCount(index)-1,0))); + + return true; + } + return QFileSystemModel::setData(index, value, role); + } +}; + + + + +SelectFilesDialog::SelectFilesDialog() : QDialog() +{ + setModal(true); + + resize(300,400); + + QTreeView *treeView = new QTreeView(this); + treeView->setModel(new SelectFilesModel); + for (int i = 1; i < 4; ++i) + treeView->setColumnHidden(i, true); + + QPushButton *cancel = new QPushButton("Cancel", this); + connect(cancel,SIGNAL(clicked()),this,SLOT(accept())); + + setLayout(new QVBoxLayout(this)); + layout()->addWidget(treeView); + layout()->addWidget(cancel); +} + + diff --git a/gui/selectfilesdialog.h b/gui/selectfilesdialog.h new file mode 100644 index 000000000..23f83be78 --- /dev/null +++ b/gui/selectfilesdialog.h @@ -0,0 +1,13 @@ + +#ifndef selectfilesdialogH +#define selectfilesdialogH + +#include + +class SelectFilesDialog : public QDialog { +public: + SelectFilesDialog(); +}; + +#endif +