Skip to content

Commit 2b7bf67

Browse files
committed
Now starts the default application by double clicking the error.
1 parent 31a88bd commit 2b7bf67

8 files changed

Lines changed: 51 additions & 21 deletions

File tree

gui/applicationlist.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ void ApplicationList::RemoveApplication(const int index)
111111
mApplications.removeAt(index);
112112
}
113113

114+
115+
void ApplicationList::MoveFirst(const int index)
116+
{
117+
if (index < mApplications.size() && index > 0)
118+
{
119+
mApplications.move(index, 0);
120+
}
121+
}
122+

gui/applicationlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class ApplicationList : public QObject
5353
void AddApplicationType(const QString &name, const QString &path);
5454

5555
void RemoveApplication(const int index);
56+
57+
void MoveFirst(const int index);
5658
protected:
5759

5860

gui/mainwindow.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,6 @@ Settings MainWindow::GetCppCheckSettings()
191191
return result;
192192
}
193193

194-
195-
QStringList MainWindow::RemoveDuplicates(const QStringList &list)
196-
{
197-
QHash<QString, int> hash;
198-
QString str;
199-
foreach(str, list)
200-
{
201-
hash[str] = 0;
202-
}
203-
204-
return QStringList(hash.uniqueKeys());
205-
}
206-
207194
QStringList MainWindow::GetFilesRecursively(const QString &path)
208195
{
209196
QFileInfo info(path);

gui/mainwindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ protected slots:
8080
void EnableCheckButtons(bool enable);
8181
void DoCheckFiles(QFileDialog::FileMode mode);
8282
QStringList GetFilesRecursively(const QString &path);
83-
QStringList RemoveDuplicates(const QStringList &list);
8483
Settings GetCppCheckSettings();
8584
QStringList RemoveUnacceptedFiles(const QStringList &list);
8685

gui/resultstree.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) :
3333
QStringList labels;
3434
labels << tr("File") << tr("Severity") << tr("Line") << tr("Message");
3535
mModel.setHorizontalHeaderLabels(labels);
36-
36+
setExpandsOnDoubleClick(false);
3737
LoadSettings();
38+
connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
39+
this, SLOT(QuickStartApplication(const QModelIndex &)));
40+
3841
}
3942

4043
ResultsTree::~ResultsTree()
@@ -365,12 +368,11 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
365368
}
366369
}
367370

368-
369-
void ResultsTree::Context(int application)
371+
void ResultsTree::StartApplication(QStandardItem *target, int application)
370372
{
371-
if (mContextItem)
373+
if (target && application >= 0 && application < mApplications.GetApplicationCount())
372374
{
373-
QVariantMap data = mContextItem->data().toMap();
375+
QVariantMap data = target->data().toMap();
374376

375377
QString program = mApplications.GetApplicationPath(application);
376378

@@ -402,6 +404,17 @@ void ResultsTree::Context(int application)
402404
program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
403405
program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
404406

405-
QProcess::execute(program);
407+
QProcess::startDetached(program);
406408
}
407409
}
410+
411+
412+
void ResultsTree::Context(int application)
413+
{
414+
StartApplication(mContextItem, application);
415+
}
416+
417+
void ResultsTree::QuickStartApplication(const QModelIndex &index)
418+
{
419+
StartApplication(mModel.itemFromIndex(index), 0);
420+
}

gui/resultstree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ class ResultsTree : public QTreeView
6262

6363
void ShowResults(ShowTypes type, bool show);
6464
protected slots:
65+
void QuickStartApplication(const QModelIndex &index);
6566
/**
6667
* @brief Slot for context menu item to open an error with specified application
6768
*
6869
* @param application Index of the application to open the error
6970
*/
7071
void Context(int application);
7172
protected:
73+
void StartApplication(QStandardItem *target, int application);
7274
void contextMenuEvent(QContextMenuEvent * e);
7375

7476
QStandardItem *AddBacktraceFiles(QStandardItem *parent,

gui/settingsdialog.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
105105
connect(modify, SIGNAL(clicked()),
106106
this, SLOT(ModifyApplication()));
107107

108+
QPushButton *def = new QPushButton(tr("Make default application"));
109+
appslayout->addWidget(def);
110+
connect(def, SIGNAL(clicked()),
111+
this, SLOT(DefaultApplication()));
112+
108113
connect(mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
109114
this, SLOT(ModifyApplication()));
110115

111-
116+
mListWidget->setSortingEnabled(false);
112117
PopulateListWidget();
113118

114119

@@ -219,6 +224,18 @@ void SettingsDialog::ModifyApplication()
219224
}
220225
}
221226

227+
void SettingsDialog::DefaultApplication()
228+
{
229+
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
230+
if (selected.size() > 0)
231+
{
232+
int index = mListWidget->row(selected[0]);
233+
mApplications.MoveFirst(index);
234+
mListWidget->clear();
235+
PopulateListWidget();
236+
}
237+
}
238+
222239
void SettingsDialog::PopulateListWidget()
223240
{
224241
for (int i = 0;i < mApplications.GetApplicationCount();i++)

gui/settingsdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected slots:
5050
void AddApplication();
5151
void DeleteApplication();
5252
void ModifyApplication();
53+
void DefaultApplication();
5354
protected:
5455
void PopulateListWidget();
5556
/**

0 commit comments

Comments
 (0)