GUI: Allow selecting multiple items in results tree.

If multiple items are selected then other than "Hide" context menu
items are disabled.
This commit is contained in:
Kimmo Varis 2010-11-28 23:26:53 +02:00
parent 85735e382f
commit e0702d3ef8
3 changed files with 31 additions and 4 deletions

View File

@ -37,6 +37,7 @@
#include <QClipboard>
#include <QContextMenuEvent>
#include <QModelIndex>
#include <QItemSelectionModel>
#include "erroritem.h"
#include "settings.h"
#include "applicationlist.h"
@ -47,7 +48,8 @@
ResultsTree::ResultsTree(QWidget * parent) :
QTreeView(parent),
mContextItem(0),
mVisibleErrors(false)
mVisibleErrors(false),
mSelectionModel(0)
{
for (int i = 0; i < SHOW_NONE; i++)
mShowTypes[i] = false;
@ -446,6 +448,11 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
QModelIndex index = indexAt(e->pos());
if (index.isValid())
{
bool multipleSelection = false;
mSelectionModel = selectionModel();
if (mSelectionModel->selectedRows().count() > 1)
multipleSelection = true;
mContextItem = mModel.itemFromIndex(index);
//Create a new context menu
@ -465,6 +472,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
{
//Create an action for the application
QAction *start = new QAction(mApplications->GetApplicationName(i), &menu);
if (multipleSelection)
start->setDisabled(true);
//Add it to our list so we can disconnect later on
actions << start;
@ -497,6 +506,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
QAction *copymessage = new QAction(tr("Copy message"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu);
if (multipleSelection)
{
copyfilename->setDisabled(true);
copypath->setDisabled(true);
copymessage->setDisabled(true);
}
menu.addAction(copyfilename);
menu.addAction(copypath);
menu.addAction(copymessage);
@ -658,12 +674,18 @@ void ResultsTree::CopyMessage()
void ResultsTree::HideResult()
{
if (mContextItem)
if (!mSelectionModel)
return;
QModelIndexList selectedRows = mSelectionModel->selectedRows();
QModelIndex index;
foreach(index, selectedRows)
{
QStandardItem *item = mModel.itemFromIndex(index);
//Set the "hide" flag for this item
QVariantMap data = mContextItem->data().toMap();
QVariantMap data = item->data().toMap();
data["hide"] = true;
mContextItem->setData(QVariant(data));
item->setData(QVariant(data));
RefreshTree();
emit ResultsHidden(true);

View File

@ -34,6 +34,7 @@ class ErrorItem;
class ErrorLine;
class QModelIndex;
class QWidget;
class QItemSelectionModel;
/// @addtogroup GUI
/// @{
@ -411,6 +412,7 @@ protected:
bool mVisibleErrors;
private:
QItemSelectionModel *mSelectionModel;
};
/// @}
#endif // RESULTSTREE_H

View File

@ -56,6 +56,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
<widget class="QTextEdit" name="mDetails">
<property name="undoRedoEnabled">