forked from qt-creator/qt-creator
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user