diff --git a/gui/gui.pro b/gui/gui.pro index f2ac7478d..b380780ae 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -44,8 +44,7 @@ FORMS = about.ui \ resultsview.ui \ scratchpad.ui \ settings.ui \ - stats.ui \ - selectfilesdialog.ui + stats.ui TRANSLATIONS = cppcheck_de.ts \ cppcheck_es.ts \ @@ -99,8 +98,7 @@ HEADERS += aboutdialog.h \ txtreport.h \ xmlreport.h \ xmlreportv1.h \ - xmlreportv2.h \ - selectfilesdialog.h + xmlreportv2.h SOURCES += aboutdialog.cpp \ application.cpp \ @@ -132,8 +130,7 @@ SOURCES += aboutdialog.cpp \ txtreport.cpp \ xmlreport.cpp \ xmlreportv1.cpp \ - xmlreportv2.cpp \ - selectfilesdialog.cpp + xmlreportv2.cpp win32 { DEFINES += _CRT_SECURE_NO_WARNINGS diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 4e57b2dcf..0e1e41654 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -43,7 +43,6 @@ #include "logview.h" #include "filelist.h" #include "showtypes.h" -#include "selectfilesdialog.h" static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html"); @@ -374,15 +373,9 @@ 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) { - SelectFilesDialog dialog(this); - if (dialog.exec() == QDialog::Accepted) { - selected = dialog.getFiles(); - } - /* - selected = QFileDialog::getOpenFileNames(this, - tr("Select files to check"), - mSettings->value(SETTINGS_CHECK_PATH, "").toString()); - */ + 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 deleted file mode 100644 index fe0bc8d7e..000000000 --- a/gui/selectfilesdialog.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2013 Daniel Marjamäki and Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "selectfilesdialog.h" -#include "ui_selectfilesdialog.h" -#include "filelist.h" - -#include -#include -#include - -class SelectFilesModel : public QFileSystemModel { -private: - /** - * paths that are user-checked. on the screen all children - * for these paths will appear to be checked too unless - * they are "unchecked". - */ - QStringList checked; - - /** - * paths that are user-unchecked. - */ - QStringList unchecked; - - /** - * Get index in stringlist where start of string matches. If - * many strings in the stringlist match then return the index - * for the longest string. - * \param paths stringlist with filepaths - * \param filepath the filepath that is matched against the stringlist - */ - int getindex(const QStringList &paths, const QString &filepath) const { - int matchlen = 0; - int matchindex = -1; - for (int i = 0; i < paths.size(); ++i) { - if (filepath.startsWith(paths[i])) { - // not a real match of paths.. - if (paths[i].size() < filepath.size() && filepath[paths[i].size()] != '/') - continue; - - // paths match. the return value is the index for the - // longest match - if (paths[i].size() > matchlen) - matchindex = i; - } - } - return matchindex; - } - - /** - * Is filepath partially checked? - * \param filepath the filepath to investigate - * \param checkindex result from getindex(checked,filepath). If not given the getindex will be called. - * \return true if filepath is partially checked - */ - bool partiallyChecked(const QString &filepath, int checkindex = -2) const { - const QString filepath2 = filepath.endsWith("/") ? filepath : (filepath + "/"); - - for (int i = 0; i < unchecked.size(); ++i) { - if (unchecked[i].startsWith(filepath2)) { - return true; - } - } - - if (checkindex == -2) - checkindex = getindex(checked, filepath); - - - if (checkindex == -1) { - for (int i = 0; i < checked.size(); ++i) { - if (checked[i].startsWith(filepath2)) { - return true; - } - } - } - - return false; - } - -public: - SelectFilesModel() : QFileSystemModel() { - class FileLister : private FileList { - public: - static QStringList filters() { - return GetDefaultFilters(); - } - }; - setNameFilters(FileLister::filters()); - setNameFilterDisables(false); - setRootPath("/"); - } - - 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); - const int checkindex = getindex(checked, filepath); - const int uncheckindex = getindex(unchecked, filepath); - - // If some children are not checked then this item should be partially checked.. - if (partiallyChecked(filepath, checkindex)) - return Qt::PartiallyChecked; - - // Is item selected but not unselected? - if (checkindex >= 0 && uncheckindex == -1) - return Qt::Checked; - if (checkindex >= 0 && uncheckindex >= 0 && - checked[checkindex].size() > unchecked[uncheckindex].size()) - return Qt::Checked; - - // Item is either not selected at all or else it is unselected - 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); - - bool partiallychecked = partiallyChecked(filepath); - - if (unchecked.indexOf(filepath) != -1) { - // remove unchecked path - unchecked.removeAll(filepath); - } else if (partiallychecked || checked.indexOf(filepath) != -1) { - // remove child selected paths - for (int i = checked.size() - 1; i >= 0; --i) { - if (checked[i].startsWith(filepath)) - checked.removeAt(i); - } - - // remove child unselected paths - for (int i = unchecked.size() - 1; i >= 0; --i) { - if (unchecked[i].startsWith(filepath)) - unchecked.removeAt(i); - } - - // If partialChecked then select this item - if (partiallychecked) - checked.append(filepath); - } else { - const int checkindex = getindex(checked, filepath); - const int uncheckindex = getindex(unchecked, filepath); - if (checkindex == -1) - checked.append(filepath); - else if (uncheckindex >= 0 && checked[checkindex].size() < unchecked[uncheckindex].size()) - checked.append(filepath); - else - unchecked.append(filepath); - } - - if (rowCount(index) > 0) - emit(dataChanged(index, index.child(rowCount(index)-1,0))); - - // update parents - QModelIndex parent = index.parent(); - while (parent != QModelIndex()) { - emit(dataChanged(parent,parent)); - parent = parent.parent(); - } - - return true; - } - return QFileSystemModel::setData(index, value, role); - } - - QStringList getFiles() const { - QStringList ret; - - // List all files in "checked" folders.. - FileList fileLister; - fileLister.AddPathList(checked); - ret = fileLister.GetFileList(); - - // Remove all items from ret that are unchecked but not checked.. - for (int i = ret.size() - 1; i >= 0; i--) { - int uncheckindex = getindex(unchecked, ret[i]); - if (uncheckindex == -1) - continue; - - // both checked and unchecked, check which to rely on - int checkindex = getindex(checked, ret[i]); - if (checked[checkindex].size() < unchecked[uncheckindex].size()) - ret.removeAt(i); - } - - return ret; - } -}; - - - -SelectFilesDialog::SelectFilesDialog(QWidget *w) : - QDialog(w), - ui(new Ui::SelectFilesDialog) -{ - ui->setupUi(this); - - selectfilesmodel = new SelectFilesModel; - - ui->treeView->setModel(selectfilesmodel); - for (int i = 1; i < 4; ++i) - ui->treeView->setColumnHidden(i, true); - - // Change text of "OK" button to "Check" - QPushButton *okbutton = ui->buttonBox->button(QDialogButtonBox::Ok); - if (okbutton) - okbutton->setText(tr("Check")); -} - -SelectFilesDialog::~SelectFilesDialog() -{ - delete ui; -} - -QStringList SelectFilesDialog::getFiles() const -{ - return selectfilesmodel->getFiles(); -} diff --git a/gui/selectfilesdialog.h b/gui/selectfilesdialog.h deleted file mode 100644 index 0f5f8ba3f..000000000 --- a/gui/selectfilesdialog.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2013 Daniel Marjamäki and Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef selectfilesdialogH -#define selectfilesdialogH - -#include -#include - -namespace Ui { - class SelectFilesDialog; -} - -class SelectFilesModel; - -class SelectFilesDialog : public QDialog { -public: - explicit SelectFilesDialog(QWidget *w); - ~SelectFilesDialog(); - - QStringList getFiles() const; - -private: - Ui::SelectFilesDialog *ui; - SelectFilesModel *selectfilesmodel; -}; - -#endif diff --git a/gui/selectfilesdialog.ui b/gui/selectfilesdialog.ui deleted file mode 100644 index a67577364..000000000 --- a/gui/selectfilesdialog.ui +++ /dev/null @@ -1,67 +0,0 @@ - - - SelectFilesDialog - - - - 0 - 0 - 400 - 450 - - - - Select files to check - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - SelectFilesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - SelectFilesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -