From 2b7bf671d7dddb20b26544fafc2eb9238013f234 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sat, 23 May 2009 18:45:05 +0300 Subject: [PATCH] Now starts the default application by double clicking the error. --- gui/applicationlist.cpp | 9 +++++++++ gui/applicationlist.h | 2 ++ gui/mainwindow.cpp | 13 ------------- gui/mainwindow.h | 1 - gui/resultstree.cpp | 25 +++++++++++++++++++------ gui/resultstree.h | 2 ++ gui/settingsdialog.cpp | 19 ++++++++++++++++++- gui/settingsdialog.h | 1 + 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index ba1505dfa..ec51845c7 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -111,3 +111,12 @@ void ApplicationList::RemoveApplication(const int index) mApplications.removeAt(index); } + +void ApplicationList::MoveFirst(const int index) +{ + if (index < mApplications.size() && index > 0) + { + mApplications.move(index, 0); + } +} + diff --git a/gui/applicationlist.h b/gui/applicationlist.h index 1eeb64c90..e2c085f90 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -53,6 +53,8 @@ public: void AddApplicationType(const QString &name, const QString &path); void RemoveApplication(const int index); + + void MoveFirst(const int index); protected: diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b4f3ff67c..ef5dccefa 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -191,19 +191,6 @@ Settings MainWindow::GetCppCheckSettings() return result; } - -QStringList MainWindow::RemoveDuplicates(const QStringList &list) -{ - QHash hash; - QString str; - foreach(str, list) - { - hash[str] = 0; - } - - return QStringList(hash.uniqueKeys()); -} - QStringList MainWindow::GetFilesRecursively(const QString &path) { QFileInfo info(path); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index dfe457ebb..ff694cf92 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -80,7 +80,6 @@ protected: void EnableCheckButtons(bool enable); void DoCheckFiles(QFileDialog::FileMode mode); QStringList GetFilesRecursively(const QString &path); - QStringList RemoveDuplicates(const QStringList &list); Settings GetCppCheckSettings(); QStringList RemoveUnacceptedFiles(const QStringList &list); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index eb507152c..55751633e 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -33,8 +33,11 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) : QStringList labels; labels << tr("File") << tr("Severity") << tr("Line") << tr("Message"); mModel.setHorizontalHeaderLabels(labels); - + setExpandsOnDoubleClick(false); LoadSettings(); + connect(this, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(QuickStartApplication(const QModelIndex &))); + } ResultsTree::~ResultsTree() @@ -365,12 +368,11 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) } } - -void ResultsTree::Context(int application) +void ResultsTree::StartApplication(QStandardItem *target, int application) { - if (mContextItem) + if (target && application >= 0 && application < mApplications.GetApplicationCount()) { - QVariantMap data = mContextItem->data().toMap(); + QVariantMap data = target->data().toMap(); QString program = mApplications.GetApplicationPath(application); @@ -402,6 +404,17 @@ void ResultsTree::Context(int application) program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive); program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive); - QProcess::execute(program); + QProcess::startDetached(program); } } + + +void ResultsTree::Context(int application) +{ + StartApplication(mContextItem, application); +} + +void ResultsTree::QuickStartApplication(const QModelIndex &index) +{ + StartApplication(mModel.itemFromIndex(index), 0); +} diff --git a/gui/resultstree.h b/gui/resultstree.h index de87c0ef6..f8f9ece9a 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -62,6 +62,7 @@ public: void ShowResults(ShowTypes type, bool show); protected slots: + void QuickStartApplication(const QModelIndex &index); /** * @brief Slot for context menu item to open an error with specified application * @@ -69,6 +70,7 @@ protected slots: */ void Context(int application); protected: + void StartApplication(QStandardItem *target, int application); void contextMenuEvent(QContextMenuEvent * e); QStandardItem *AddBacktraceFiles(QStandardItem *parent, diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 922152e78..c9837c677 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -105,10 +105,15 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list connect(modify, SIGNAL(clicked()), this, SLOT(ModifyApplication())); + QPushButton *def = new QPushButton(tr("Make default application")); + appslayout->addWidget(def); + connect(def, SIGNAL(clicked()), + this, SLOT(DefaultApplication())); + connect(mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(ModifyApplication())); - + mListWidget->setSortingEnabled(false); PopulateListWidget(); @@ -219,6 +224,18 @@ void SettingsDialog::ModifyApplication() } } +void SettingsDialog::DefaultApplication() +{ + QList selected = mListWidget->selectedItems(); + if (selected.size() > 0) + { + int index = mListWidget->row(selected[0]); + mApplications.MoveFirst(index); + mListWidget->clear(); + PopulateListWidget(); + } +} + void SettingsDialog::PopulateListWidget() { for (int i = 0;i < mApplications.GetApplicationCount();i++) diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 3c5591469..4e5cc07d5 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -50,6 +50,7 @@ protected slots: void AddApplication(); void DeleteApplication(); void ModifyApplication(); + void DefaultApplication(); protected: void PopulateListWidget(); /**