Added the initial version of opening a error with user specified application.
This commit is contained in:
parent
78d4318c5e
commit
70c32c10e4
|
@ -26,8 +26,8 @@
|
|||
#include <QDebug>
|
||||
|
||||
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"));
|
||||
|
|
|
@ -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;i<names.size();i++) {
|
||||
AddApplicationType(names[i],paths[i]);
|
||||
if (names.size() == paths.size())
|
||||
{
|
||||
for (int i = 0;i < names.size();i++)
|
||||
{
|
||||
AddApplicationType(names[i], paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +49,14 @@ void ApplicationList::SaveSettings(QSettings &programSettings)
|
|||
QStringList names;
|
||||
QStringList paths;
|
||||
|
||||
for(int i=0;i<GetApplicationCount();i++) {
|
||||
names<<GetApplicationName(i);
|
||||
paths<<GetApplicationPath(i);
|
||||
for (int i = 0;i < GetApplicationCount();i++)
|
||||
{
|
||||
names << GetApplicationName(i);
|
||||
paths << GetApplicationPath(i);
|
||||
}
|
||||
|
||||
programSettings.setValue(tr("Application names"),names);
|
||||
programSettings.setValue(tr("Application paths"),paths);
|
||||
programSettings.setValue(tr("Application names"), names);
|
||||
programSettings.setValue(tr("Application paths"), paths);
|
||||
|
||||
}
|
||||
|
||||
|
@ -100,11 +103,11 @@ void ApplicationList::AddApplicationType(const QString &name, const QString &pat
|
|||
ApplicationType type;
|
||||
type.Name = name;
|
||||
type.Path = path;
|
||||
mApplications<<type;
|
||||
mApplications << type;
|
||||
}
|
||||
|
||||
void ApplicationList::RemoveApplication(const int index)
|
||||
{
|
||||
mApplications.removeAt(index);
|
||||
mApplications.removeAt(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ MainWindow::MainWindow() :
|
|||
mActionShowErrors(tr("Show &common errors"), this),
|
||||
mActionShowCheckAll(tr("Check all"), this),
|
||||
mActionShowUncheckAll(tr("Uncheck all"), this),
|
||||
mResults(mSettings)
|
||||
mResults(mSettings, mApplications)
|
||||
{
|
||||
QMenu *menu = menuBar()->addMenu(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();
|
||||
|
|
|
@ -20,13 +20,18 @@
|
|||
|
||||
#include "resultstree.h"
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QSignalMapper>
|
||||
#include <QProcess>
|
||||
|
||||
ResultsTree::ResultsTree(QSettings &settings) :
|
||||
mSettings(settings)
|
||||
ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) :
|
||||
mSettings(settings),
|
||||
mApplications(list),
|
||||
mContextItem(0)
|
||||
{
|
||||
setModel(&mModel);
|
||||
QStringList labels;
|
||||
labels <<tr("File")<< tr("Severity") << tr("Line") << tr("Message");
|
||||
labels << tr("File") << tr("Severity") << tr("Line") << tr("Message");
|
||||
mModel.setHorizontalHeaderLabels(labels);
|
||||
|
||||
LoadSettings();
|
||||
|
@ -88,14 +93,15 @@ void ResultsTree::AddErrorItem(const QString &file,
|
|||
item->setData(QVariant(data));
|
||||
|
||||
//Add backtrace files as children
|
||||
for (int i=1;i<files.size() && i < lines.size();i++)
|
||||
for (int i = 1;i < files.size() && i < lines.size();i++)
|
||||
{
|
||||
AddBacktraceFiles(item,files[i],lines[i].toInt(),severity,message,hide);
|
||||
AddBacktraceFiles(item, files[i], lines[i].toInt(), severity, message, hide);
|
||||
}
|
||||
|
||||
//TODO just hide/show current error and it's file
|
||||
//since this does a lot of unnecessary work
|
||||
if (!hide) {
|
||||
if (!hide)
|
||||
{
|
||||
ShowFileItem(realfile);
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +114,8 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
|||
const bool hide)
|
||||
|
||||
{
|
||||
if (!parent) {
|
||||
if (!parent)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -123,7 +130,7 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
|||
|
||||
parent->appendRow(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;i<filecount;i++)
|
||||
for (int i = 0;i < filecount;i++)
|
||||
{
|
||||
//Get file i
|
||||
QStandardItem *file = mModel.item(i,0);
|
||||
QStandardItem *file = mModel.item(i, 0);
|
||||
if (!file)
|
||||
{
|
||||
continue;
|
||||
|
@ -219,10 +226,10 @@ void ResultsTree::RefreshTree()
|
|||
//By default it shouldn't be visible
|
||||
bool show = false;
|
||||
|
||||
for (int j=0;j<errorcount;j++)
|
||||
for (int j = 0;j < errorcount;j++)
|
||||
{
|
||||
//Get the error itself
|
||||
QStandardItem *child = file->child(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<QAction*> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
#include <QSettings>
|
||||
#include <QContextMenuEvent>
|
||||
#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:
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QListWidgetItem *> selected = mListWidget->selectedItems();
|
||||
QListWidgetItem *item = 0;
|
||||
|
||||
foreach(item,selected)
|
||||
foreach(item, selected)
|
||||
{
|
||||
qDebug()<<item;
|
||||
qDebug() << item;
|
||||
mApplications.RemoveApplication(mListWidget->row(item));
|
||||
mListWidget->clear();
|
||||
PopulateListWidget();
|
||||
|
@ -203,7 +203,7 @@ void SettingsDialog::ModifyApplication()
|
|||
{
|
||||
QList<QListWidgetItem *> 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;i<mApplications.GetApplicationCount();i++)
|
||||
for (int i = 0;i < mApplications.GetApplicationCount();i++)
|
||||
{
|
||||
mListWidget->addItem(mApplications.GetApplicationName(i));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue