Isis 3 Programmer Reference
AbstractProjectItemView.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "AbstractProjectItemView.h"
10 
11 #include <QAction>
12 #include <QDebug>
13 #include <QDesktopWidget>
14 #include <QDragEnterEvent>
15 #include <QDragMoveEvent>
16 #include <QDropEvent>
17 #include <QList>
18 #include <QMainWindow>
19 #include <QRect>
20 #include <QSizePolicy>
21 #include <QWidget>
22 
23 #include "ProjectItem.h"
24 #include "ProjectItemModel.h"
25 #include "ProjectItemProxyModel.h"
26 
27 namespace Isis {
28 
35 
36  setWindowFlags(Qt::Widget);
37 
38  QSizePolicy policy = sizePolicy();
39  policy.setHorizontalPolicy(QSizePolicy::Expanding);
40  policy.setVerticalPolicy(QSizePolicy::Expanding);
41  setSizePolicy(policy);
42 
44  setAcceptDrops(true);
45  }
46 
47 
54 
55  // Size hint is made large as a hack to have the views fill the available dock
56  // space. SizePolicy alone did not work.
57  QDesktopWidget deskTop;
58  QRect availableSpace = deskTop.availableGeometry(deskTop.primaryScreen());
59  return QSize( .89 * availableSpace.width(), .5 * availableSpace.height() );
60  }
61 
62 
70  if (ProjectItemProxyModel *proxyModel =
71  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
72  proxyModel->setSourceModel(model);
73  }
74  }
75 
76 
84  if (ProjectItemProxyModel *proxyModel =
85  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
86  return proxyModel->sourceModel();
87  }
88  return internalModel();
89  }
90 
91 
99  }
100 
101 
109  return m_internalModel;
110  }
111 
112 
119  void AbstractProjectItemView::dragEnterEvent(QDragEnterEvent *event) {
120  if (internalModel()->canDropMimeData( event->mimeData(),
121  event->dropAction(),
122  0, 0, QModelIndex() ) ) {
123  event->acceptProposedAction();
124  }
125  }
126 
127 
134  void AbstractProjectItemView::dragMoveEvent(QDragMoveEvent *event) {
135  if (internalModel()->canDropMimeData( event->mimeData(),
136  event->dropAction(),
137  0, 0, QModelIndex() ) ) {
138  event->acceptProposedAction();
139  }
140  }
141 
142 
148  void AbstractProjectItemView::dropEvent(QDropEvent *event) {
149  if (internalModel()->canDropMimeData( event->mimeData(),
150  event->dropAction(),
151  0, 0, QModelIndex() ) ) {
152  internalModel()->dropMimeData( event->mimeData(), event->dropAction(),
153  0, 0, QModelIndex() );
154  event->acceptProposedAction();
155  }
156  }
157 
158 
159  void AbstractProjectItemView::moveEvent(QMoveEvent *event) {
160  QMainWindow::moveEvent(event);
161 
162  emit windowChangeEvent(false);
163  }
164 
165 
166  void AbstractProjectItemView::resizeEvent(QResizeEvent *event) {
167  QMainWindow::resizeEvent(event);
168 
169  emit windowChangeEvent(false);
170  }
171 
172 
179  enableActions();
180  }
181 
182 
189  disableActions();
190  }
191 
192 
197  foreach (QAction *action, actions()) {
198  action->setDisabled(true);
199  }
200  }
201 
202 
207  foreach (QAction *action, actions()) {
208  action->setEnabled(true);
209  }
210  }
211 
212 
219  return QList<QAction *>();
220  }
221 
222 
229  return model()->currentItem();
230  }
231 
232 
239  return model()->selectedItems();
240  }
241 
242 
251  if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
252  proxyModel->addItem(item);
253  }
254  }
255 
256 
265  if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
266  proxyModel->addItems(items);
267  }
268  }
269 
270 
279  if (ProjectItemProxyModel *proxyModel =
280  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
281  proxyModel->removeItem(item);
282  }
283  }
284 
285 
293  foreach (ProjectItem *item, items) {
294  removeItem(item);
295  }
296  }
297 }
Isis::AbstractProjectItemView::AbstractProjectItemView
AbstractProjectItemView(QWidget *parent=0)
Constructs the AbstractProjectItemView.
Definition: AbstractProjectItemView.cpp:34
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
Isis::AbstractProjectItemView::leaveEvent
virtual void leaveEvent(QEvent *event)
Disables actions when cursor leaves the view.
Definition: AbstractProjectItemView.cpp:188
QWidget
QList< QAction * >
Isis::AbstractProjectItemView::dropEvent
virtual void dropEvent(QDropEvent *event)
Drops the data into the internal model if it can accept the data.
Definition: AbstractProjectItemView.cpp:148
Isis::AbstractProjectItemView::setModel
virtual void setModel(ProjectItemModel *model)
Sets the model used by the view.
Definition: AbstractProjectItemView.cpp:69
Isis::AbstractProjectItemView::selectedItems
virtual QList< ProjectItem * > selectedItems()
Return the selected items of the model.
Definition: AbstractProjectItemView.cpp:238
Isis::ProjectItemProxyModel
Allows access to items in a ProjectItemModel through a proxy model.
Definition: ProjectItemProxyModel.h:70
QMainWindow
Isis::AbstractProjectItemView::addItems
virtual void addItems(QList< ProjectItem * > items)
Adds several items to the view.
Definition: AbstractProjectItemView.cpp:264
Isis::AbstractProjectItemView::removeItem
virtual void removeItem(ProjectItem *item)
Removes an item to the view.
Definition: AbstractProjectItemView.cpp:278
Isis::AbstractProjectItemView::currentItem
virtual ProjectItem * currentItem()
Returns the current item of the model.
Definition: AbstractProjectItemView.cpp:228
Isis::AbstractProjectItemView::m_internalModel
ProjectItemModel * m_internalModel
The internal model used by the view.
Definition: AbstractProjectItemView.h:123
Isis::AbstractProjectItemView::enableActions
virtual void enableActions()
Enables toolbars and toolpad actions.
Definition: AbstractProjectItemView.cpp:206
Isis::AbstractProjectItemView::enterEvent
virtual void enterEvent(QEvent *event)
Enables actions when cursor enters the view.
Definition: AbstractProjectItemView.cpp:178
Isis::AbstractProjectItemView::addItem
virtual void addItem(ProjectItem *item)
Adds an item to the view.
Definition: AbstractProjectItemView.cpp:250
Isis::AbstractProjectItemView::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *event)
Accepts the drag enter event if the internal model can accept the mime data.
Definition: AbstractProjectItemView.cpp:119
Isis::AbstractProjectItemView::setInternalModel
virtual void setInternalModel(ProjectItemModel *model)
Sets the internal model of the view.
Definition: AbstractProjectItemView.cpp:97
Isis::ProjectItemModel::selectedItems
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Definition: ProjectItemModel.cpp:158
Isis::AbstractProjectItemView::internalModel
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
Definition: AbstractProjectItemView.cpp:108
Isis::AbstractProjectItemView::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *event)
Accepts the drag event if the internal model can accept the mime data.
Definition: AbstractProjectItemView.cpp:134
Isis::AbstractProjectItemView::disableActions
virtual void disableActions()
Disables toolbars and toolpad actions.
Definition: AbstractProjectItemView.cpp:196
Isis::AbstractProjectItemView::removeItems
virtual void removeItems(QList< ProjectItem * > items)
Removes several items from the view.
Definition: AbstractProjectItemView.cpp:292
Isis::AbstractProjectItemView::sizeHint
virtual QSize sizeHint() const
Returns the suggested size.
Definition: AbstractProjectItemView.cpp:53
Isis::ProjectItemModel::currentItem
ProjectItem * currentItem()
Returns the current item of the internal selection model.
Definition: ProjectItemModel.cpp:139
Isis::AbstractProjectItemView::contextMenuActions
virtual QList< QAction * > contextMenuActions()
Returns a list of actions appropriate for a context menu.
Definition: AbstractProjectItemView.cpp:218
QAction
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