View for ProjectTreeModel representing the project tree. More...
#include <treeview.h>
Public Member Functions | |
ProjectTreeView (QWidget *parent=0) | |
~ProjectTreeView () | |
virtual void | setModel (QAbstractItemModel *model) |
ProjectTreeModel * | model () |
Protected Slots | |
virtual void | onCollapse (const QModelIndex &index) |
virtual void | onExpand (const QModelIndex &index) |
Protected Member Functions | |
void | contextMenuEvent (QContextMenuEvent *e) |
View for ProjectTreeModel representing the project tree.
ProjectTreeView::ProjectTreeView | ( | QWidget * | parent = 0 |
) |
: QTreeView(parent) { qRegisterMetaTypeStreamOperators<TreePathList>("TreePathList"); //QSettings needs this to save and load. The parser knows its QList< QVector<long long int> > expandedTreePaths = QSettings().value("projecttree/treeview/states").value<TreePathList>(); setModel(new ProjectTreeModel(this)); //er zijn dependenties hierop (!): moet in constructor worden uitgevoerd. setItemDelegate(new TreeViewDelegate(this)); setSelectionMode(QAbstractItemView::ExtendedSelection); setDragEnabled(true); setDropIndicatorShown(true); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); setAlternatingRowColors(true); restoreExpandedItems(); resizeColumnToContents(0); //must be updated after restoration! // Setup connections connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(onExpand(QModelIndex))); connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(onCollapse(QModelIndex))); }
ProjectTreeView::~ProjectTreeView | ( | ) |
{ saveExpandedItems(); }
void ProjectTreeView::contextMenuEvent | ( | QContextMenuEvent * | e | ) | [protected] |
{ // In base class QAbstractScrollArea this event is ignored QPoint pos = e->globalPos(); QModelIndex treeItemIndex = indexAt(viewport()->mapFromGlobal(pos)); selectionModel()->select(treeItemIndex, QItemSelectionModel::ClearAndSelect); // Check if a menu is needed if (!treeItemIndex.isValid()) return; // Execute menu TreeViewMenu menu(treeItemIndex); qDebug() << "Menu returned: " << menu.exec(pos); }
ProjectTreeModel * ProjectTreeView::model | ( | ) |
{ return dynamic_cast<ProjectTreeModel*>(QTreeView::model()); }
void ProjectTreeView::onCollapse | ( | const QModelIndex & | index | ) | [protected, virtual, slot] |
Referenced by ProjectTreeView().
{ resizeColumnToContents(0); TreePath path = index.data(ProjectTreeModel::TreeItemPath).value<TreePath>(); Q_ASSERT(!path.isEmpty()); expandedTreePaths.removeAll(path); }
void ProjectTreeView::onExpand | ( | const QModelIndex & | index | ) | [protected, virtual, slot] |
Referenced by ProjectTreeView().
{ resizeColumnToContents(0); TreePath path = index.data(ProjectTreeModel::TreeItemPath).value<TreePath>(); Q_ASSERT(!path.isEmpty()); if (!expandedTreePaths.contains(path)) expandedTreePaths.append(path); }
void ProjectTreeView::setModel | ( | QAbstractItemModel * | model | ) | [virtual] |
Reimplemented from QTreeView.
Referenced by ProjectTreeView().
{ QTreeView::setModel(model); connect(model, SIGNAL(modelReset()), this, SLOT(restoreExpandedItems())); }