From 70c32c10e4e3b69562d00ffc2922f46f7c280ee8 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sat, 23 May 2009 14:26:04 +0300 Subject: [PATCH] Added the initial version of opening a error with user specified application. --- gui/applicationdialog.cpp | 6 +- gui/applicationlist.cpp | 23 ++++--- gui/mainwindow.cpp | 4 +- gui/resultstree.cpp | 139 ++++++++++++++++++++++++++++++++++---- gui/resultstree.h | 50 ++++++++++---- gui/resultsview.cpp | 4 +- gui/resultsview.h | 2 +- gui/settingsdialog.cpp | 22 +++--- gui/test.cpp | 4 +- 9 files changed, 193 insertions(+), 61 deletions(-) diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp index 35510174c..8c8322503 100644 --- a/gui/applicationdialog.cpp +++ b/gui/applicationdialog.cpp @@ -26,8 +26,8 @@ #include ApplicationDialog::ApplicationDialog(const QString &name, -const QString &path, -const QString &title) + const QString &path, + const QString &title) { QVBoxLayout *layout = new QVBoxLayout(); mName = new QLineEdit(name); @@ -51,7 +51,7 @@ const QString &title) layout->addWidget(new QLabel(tr("Application to execute"))); layout->addWidget(mPath); QPushButton *browse = new QPushButton(tr("Browse")); - connect(browse,SIGNAL(clicked()), this, SLOT(Browse())); + connect(browse, SIGNAL(clicked()), this, SLOT(Browse())); layout->addWidget(browse); QPushButton *cancel = new QPushButton(tr("Cancel")); diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index f10a96074..ba1505dfa 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -35,9 +35,11 @@ void ApplicationList::LoadSettings(QSettings &programSettings) QStringList names = programSettings.value(tr("Application names"), QStringList()).toStringList(); QStringList paths = programSettings.value(tr("Application paths"), QStringList()).toStringList(); - if (names.size() == paths.size()) { - for(int i=0;iaddMenu(tr("&File")); menu->addAction(&mActionCheckFiles); @@ -249,7 +249,7 @@ void MainWindow::CheckDone() void MainWindow::ProgramSettings() { - SettingsDialog dialog(mSettings,mApplications); + SettingsDialog dialog(mSettings, mApplications); if (dialog.exec() == QDialog::Accepted) { dialog.SaveCheckboxValues(); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index cca631c82..eb507152c 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -20,13 +20,18 @@ #include "resultstree.h" #include +#include +#include +#include -ResultsTree::ResultsTree(QSettings &settings) : - mSettings(settings) +ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) : + mSettings(settings), + mApplications(list), + mContextItem(0) { setModel(&mModel); QStringList labels; - labels <setData(QVariant(data)); //Add backtrace files as children - for (int i=1;iappendRow(list); - setRowHidden(parent->rowCount()-1,parent->index(),hide); + setRowHidden(parent->rowCount() - 1, parent->index(), hide); //TODO Does this leak memory? Should items from list be deleted? @@ -204,10 +211,10 @@ void ResultsTree::RefreshTree() //Get the amount of files in the tree int filecount = mModel.rowCount(); - for (int i=0;ichild(j,0); + QStandardItem *child = file->child(j, 0); if (!child) { continue; @@ -237,7 +244,7 @@ void ResultsTree::RefreshTree() bool hide = !mShowTypes[VariantToShowType(data["severity"])]; //Hide/show accordingly - setRowHidden(j,file->index(),hide); + setRowHidden(j, file->index(), hide); //If it was shown then the file itself has to be shown aswell if (!hide) @@ -247,7 +254,7 @@ void ResultsTree::RefreshTree() } //Show the file if any of it's errors are visible - setRowHidden(i,QModelIndex(),!show); + setRowHidden(i, QModelIndex(), !show); } } @@ -293,6 +300,108 @@ void ResultsTree::ShowFileItem(const QString &name) QStandardItem *item = FindFileItem(name); if (item) { - setRowHidden(0,mModel.indexFromItem(item),false); + setRowHidden(0, mModel.indexFromItem(item), false); + } +} + +void ResultsTree::contextMenuEvent(QContextMenuEvent * e) +{ + QModelIndex index = indexAt(e->pos()); + if (index.isValid()) + { + mContextItem = mModel.itemFromIndex(index); + if (mContextItem && mApplications.GetApplicationCount() > 0 && mContextItem->parent()) + { + + //Create a new context menu + QMenu menu(this); + //Store all applications in a list + QList actions; + + //Create a signal mapper so we don't have to store data to class + //member variables + QSignalMapper *signalMapper = new QSignalMapper(this); + + //Go through all applications and add them to the context menu + for (int i = 0;i < mApplications.GetApplicationCount();i++) + { + //Create an action for the application + QAction *start = new QAction(mApplications.GetApplicationName(i), &menu); + + //Add it to our list so we can disconnect later on + actions << start; + + //Add it to context menu + menu.addAction(start); + + //Connect the signal to signal mapper + connect(start, SIGNAL(triggered()), signalMapper, SLOT(map())); + + //Add a new mapping + signalMapper->setMapping(start, i); + } + + connect(signalMapper, SIGNAL(mapped(int)), + this, SLOT(Context(int))); + + //Start the menu + menu.exec(e->globalPos()); + + + //Disconnect all signals + for (int i = 0;i < actions.size();i++) + { + + disconnect(actions[i], SIGNAL(triggered()), signalMapper, SLOT(map())); + } + + + disconnect(signalMapper, SIGNAL(mapped(int)), + this, SLOT(Context(int))); + //And remove the signal mapper + delete signalMapper; + } + + } +} + + +void ResultsTree::Context(int application) +{ + if (mContextItem) + { + QVariantMap data = mContextItem->data().toMap(); + + QString program = mApplications.GetApplicationPath(application); + + //TODO Check which line was actually right clicked, now defaults to 0 + unsigned int index = 0; + + //Replace (file) with filename + QStringList files = data["files"].toStringList(); + if (files.size() > 0) + { + program.replace("(file)", files[index], Qt::CaseInsensitive); + } + else + { + qDebug("Failed to get filename!"); + } + + + QVariantList lines = data["lines"].toList(); + if (lines.size() > 0) + { + program.replace("(line)", QString("%1").arg(lines[index].toInt()), Qt::CaseInsensitive); + } + else + { + qDebug("Failed to get filenumber!"); + } + + program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive); + program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive); + + QProcess::execute(program); } } diff --git a/gui/resultstree.h b/gui/resultstree.h index d3fd892fc..de87c0ef6 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -25,7 +25,9 @@ #include #include #include +#include #include "common.h" +#include "applicationlist.h" /** @@ -34,8 +36,9 @@ */ class ResultsTree : public QTreeView { + Q_OBJECT public: - ResultsTree(QSettings &settings); + ResultsTree(QSettings &settings, ApplicationList &list); virtual ~ResultsTree(); /** @@ -58,13 +61,22 @@ public: void Clear(); void ShowResults(ShowTypes type, bool show); +protected slots: + /** + * @brief Slot for context menu item to open an error with specified application + * + * @param application Index of the application to open the error + */ + void Context(int application); protected: + void contextMenuEvent(QContextMenuEvent * e); + QStandardItem *AddBacktraceFiles(QStandardItem *parent, - const QString &file, - const int line, - const QString &severity, - const QString &message, - const bool hide); + const QString &file, + const int line, + const QString &severity, + const QString &message, + const bool hide); void AddItem(int index); void RefreshTree(); @@ -101,18 +113,18 @@ protected: QStandardItem *FindFileItem(const QString &name); - /** - * @brief Ensures there's a item in the model for the specified file - * - * @param name Filename - * @return QStandardItem to be used as a parent for all errors for specified file + /** + * @brief Ensures there's a item in the model for the specified file + * + * @param name Filename + * @return QStandardItem to be used as a parent for all errors for specified file */ QStandardItem *EnsureFileItem(const QString &name); - /** - * @brief Show a file item - * - * @param name Filename of the fileitem + /** + * @brief Show a file item + * + * @param name Filename of the fileitem */ void ShowFileItem(const QString &name); @@ -129,6 +141,14 @@ protected: QSettings &mSettings; bool mShowTypes[SHOW_NONE]; + + ApplicationList &mApplications; + + /** + * @brief Right clicked item (used by context menu slots) + * + */ + QStandardItem *mContextItem; private: }; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index f04b5d5fa..b1e4628b9 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -22,7 +22,7 @@ #include #include -ResultsView::ResultsView(QSettings &settings) +ResultsView::ResultsView(QSettings &settings, ApplicationList &list) { QVBoxLayout *layout = new QVBoxLayout(); setLayout(layout); @@ -31,7 +31,7 @@ ResultsView::ResultsView(QSettings &settings) layout->addWidget(mProgress); mProgress->setMinimum(0); - mTree = new ResultsTree(settings); + mTree = new ResultsTree(settings, list); layout->addWidget(mTree); } diff --git a/gui/resultsview.h b/gui/resultsview.h index 0b5759e68..e6cb43688 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -38,7 +38,7 @@ class ResultsView : public QWidget Q_OBJECT public: - ResultsView(QSettings &settings); + ResultsView(QSettings &settings, ApplicationList &list); virtual ~ResultsView(); void ShowResults(ShowTypes type, bool show); diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index c0d517a2e..922152e78 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -58,7 +58,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //General tab QWidget *general = new QWidget(); - tabs->addTab(general,tr("General")); + tabs->addTab(general, tr("General")); //layout for general tab @@ -83,7 +83,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //Add tab for setting user startable applications QWidget *applications = new QWidget(); - tabs->addTab(applications,tr("Applications")); + tabs->addTab(applications, tr("Applications")); QVBoxLayout *appslayout = new QVBoxLayout(); mListWidget = new QListWidget(); @@ -105,8 +105,8 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list connect(modify, SIGNAL(clicked()), this, SLOT(ModifyApplication())); - connect(mListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), - this,SLOT(ModifyApplication())); + connect(mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(ModifyApplication())); PopulateListWidget(); @@ -175,11 +175,11 @@ void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) void SettingsDialog::AddApplication() { - ApplicationDialog dialog("","",tr("Add a new application")); + ApplicationDialog dialog("", "", tr("Add a new application")); if (dialog.exec() == QDialog::Accepted) { - mApplications.AddApplicationType(dialog.GetName(),dialog.GetPath()); + mApplications.AddApplicationType(dialog.GetName(), dialog.GetPath()); mListWidget->addItem(dialog.GetName()); } } @@ -190,9 +190,9 @@ void SettingsDialog::DeleteApplication() QList selected = mListWidget->selectedItems(); QListWidgetItem *item = 0; - foreach(item,selected) + foreach(item, selected) { - qDebug()<row(item)); mListWidget->clear(); PopulateListWidget(); @@ -203,7 +203,7 @@ void SettingsDialog::ModifyApplication() { QList selected = mListWidget->selectedItems(); QListWidgetItem *item = 0; - foreach(item,selected) + foreach(item, selected) { int row = mListWidget->row(item); @@ -213,7 +213,7 @@ void SettingsDialog::ModifyApplication() if (dialog.exec() == QDialog::Accepted) { - mApplications.SetApplicationType(row,dialog.GetName(),dialog.GetPath()); + mApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath()); item->setText(dialog.GetName()); } } @@ -221,7 +221,7 @@ void SettingsDialog::ModifyApplication() void SettingsDialog::PopulateListWidget() { - for (int i=0;iaddItem(mApplications.GetApplicationName(i)); } diff --git a/gui/test.cpp b/gui/test.cpp index 169fcf474..2527fd74c 100644 --- a/gui/test.cpp +++ b/gui/test.cpp @@ -1,12 +1,12 @@ /* This is testing data for the GUI. -Used for testing GUI with various error styles reported by cppcheck. +Used for testing GUI with various error styles reported by cppcheck. Not meant to be compiled. */ void unused() { - int a = 15; + int a = 15; } void f(char k)