Class view: Fix expanding of items on double click

Task-number: QTCREATORBUG-2536
Change-Id: I94471c265c9f9dbffe253d7c6e8a1e834b47f91f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Robert Loehning
2015-05-06 11:34:46 +02:00
parent ad9b4ce499
commit 9073c55035
2 changed files with 26 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QVariant>
#include <QVBoxLayout>
enum { debug = false };
@@ -102,6 +103,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) :
treeView->setDragEnabled(true);
treeView->setDragDropMode(QAbstractItemView::DragOnly);
treeView->setDefaultDropAction(Qt::MoveAction);
treeView->setExpandsOnDoubleClick(false);
verticalLayout->addWidget(Core::ItemViewFind::createSearchableWrapper(
treeView, Core::ItemViewFind::DarkColored,
Core::ItemViewFind::FetchMoreWhileSearching));
@@ -114,6 +116,9 @@ NavigationWidget::NavigationWidget(QWidget *parent) :
// selected item
connect(treeView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex)));
// double-clicked item
connect(treeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(onItemDoubleClicked(QModelIndex)));
// connections to the manager
Manager *manager = Manager::instance();
@@ -236,6 +241,26 @@ void NavigationWidget::onItemActivated(const QModelIndex &index)
emit requestGotoLocations(list);
}
/*!
Expands/collapses the item given by \a index if it
refers to a project file (.pro/.pri)
*/
void NavigationWidget::onItemDoubleClicked(const QModelIndex &index)
{
if (!index.isValid())
return;
const QVariant iconType = treeModel->data(index, Constants::IconTypeRole);
if (!iconType.isValid())
return;
bool ok = false;
const int type = iconType.toInt(&ok);
if (ok && type == INT_MIN)
treeView->setExpanded(index, !treeView->isExpanded(index));
}
/*!
Receives new data for the tree. \a result is a pointer to the Class View
model root item. The function does nothing if null is passed.