Public Member Functions | Protected Slots | Protected Member Functions

ProjectTreeView Class Reference

View for ProjectTreeModel representing the project tree. More...

#include <treeview.h>

Inheritance diagram for ProjectTreeView:
Inheritance graph
[legend]
Collaboration diagram for ProjectTreeView:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ProjectTreeView (QWidget *parent=0)
 ~ProjectTreeView ()
virtual void setModel (QAbstractItemModel *model)
ProjectTreeModelmodel ()

Protected Slots

virtual void onCollapse (const QModelIndex &index)
virtual void onExpand (const QModelIndex &index)

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *e)

Detailed Description

View for ProjectTreeModel representing the project tree.


Constructor & Destructor Documentation

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();
}


Member Function Documentation

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()));
}


The documentation for this class was generated from the following files: