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