Isis 3 Programmer Reference
ProjectItemTreeView.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "ProjectItemTreeView.h"
10
11#include <QAbstractItemView>
12#include <QEvent>
13#include <QObject>
14#include <QRect>
15#include <QTreeView>
16#include <QVBoxLayout>
17#include <QWidget>
18#include <QGuiApplication>
19#include <QScreen>
20
21#include "ProjectItem.h"
22#include "ProjectItemModel.h"
23
24
25namespace Isis {
32
33 m_treeView = new QTreeView(this);
34 m_treeView->installEventFilter(this);
35
37 // 2017-04-12 TSucharski Turn off for now, since not accepting drops, not point in allowing
38 // drags
39// m_treeView->setDragEnabled(true);
40 m_treeView->setDragEnabled(false);
41 m_treeView->setAcceptDrops(false);
42 m_treeView->setHeaderHidden(true);
43
44 // Simply doing this creates scrollbar when the dock widget within the main window is made too
45 // small- looks like QMainWindow and/or QDockWidget handles the scrollbars for us.
46 setCentralWidget(m_treeView);
47
48 //This works so that it cannot be shrunk in width, only grown
49 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
50
51 // Currently set all items on view to un-editable
52 //m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
53
54// setAcceptDrops(true);
55 }
56
57
64 QRect availableSpace = (QGuiApplication::primaryScreen()->availableGeometry());
65 return QSize(.15 * availableSpace.width(), .5 * availableSpace.height());
66 }
67
68
73
74
81 return m_treeView;
82 }
83
84
92 disconnect(internalModel(), 0, this, 0);
93
95
96 m_treeView->reset();
97 m_treeView->setModel(model);
98 m_treeView->setSelectionModel( model->selectionModel() );
99 m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
100
101 connect( model, SIGNAL( itemAdded(ProjectItem *) ),
102 this, SLOT( onItemAdded(ProjectItem *) ) );
103
104 }
105
106
113 ProjectItem *parent = item->parent();
114 if (!parent) {
115 return;
116 }
117 if ( !parent->isImageList() && !parent->isControlList() ) {
118 m_treeView->expand( parent->index() );
119 }
120 }
121
122
132 bool ProjectItemTreeView::eventFilter(QObject *watched, QEvent *event) {
133 if (event->type() == QEvent::DragEnter) {
134 return true;
135 }
136 else if (event->type() == QEvent::Drop) {
137 return true;
138 }
139
140 return AbstractProjectItemView::eventFilter(watched, event);
141 }
142
143}
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt's model-view framework.
virtual ProjectItemModel * model()
Returns the model used by the view.
virtual void setInternalModel(ProjectItemModel *model)
Sets the internal model of the view.
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
Represents an item of a ProjectItemModel in Qt's model-view framework.
bool isControlList() const
Returns true if a ControlList is stored in the data of the item.
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
ProjectItem * parent() const
Returns the parent item of this item.
Provides access to data stored in a Project through Qt's model-view framework.
virtual void setInternalModel(ProjectItemModel *model)
Sets the model so that the internal proxy model exactly matches the source model.
~ProjectItemTreeView()
Default destructor.
QTreeView * m_treeView
The tree view (widget)
bool eventFilter(QObject *watched, QEvent *event)
Filters out drag and drop events so that they are handled by the ProjectItemTreeView.
void onItemAdded(ProjectItem *item)
Expands the parent project item in the tree view to show the added item.
QTreeView * treeView()
Returns the tree view.
ProjectItemTreeView(QWidget *parent=0)
Constructs a ProjectItemTreeView.
virtual QSize sizeHint() const
Returns the suggested size.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16