Isis 3 Programmer Reference
AbstractProjectItemView.cpp
Go to the documentation of this file.
1 
24 
25 #include <QAction>
26 #include <QDebug>
27 #include <QDesktopWidget>
28 #include <QDragEnterEvent>
29 #include <QDragMoveEvent>
30 #include <QDropEvent>
31 #include <QList>
32 #include <QMainWindow>
33 #include <QRect>
34 #include <QSizePolicy>
35 #include <QWidget>
36 
37 #include "ProjectItem.h"
38 #include "ProjectItemModel.h"
39 #include "ProjectItemProxyModel.h"
40 
41 namespace Isis {
42 
49 
50  setWindowFlags(Qt::Widget);
51 
52  QSizePolicy policy = sizePolicy();
53  policy.setHorizontalPolicy(QSizePolicy::Expanding);
54  policy.setVerticalPolicy(QSizePolicy::Expanding);
55  setSizePolicy(policy);
56 
58  setAcceptDrops(true);
59  }
60 
61 
68 
69  // Size hint is made large as a hack to have the views fill the available dock
70  // space. SizePolicy alone did not work.
71  QDesktopWidget deskTop;
72  QRect availableSpace = deskTop.availableGeometry(deskTop.primaryScreen());
73  return QSize( .89 * availableSpace.width(), .5 * availableSpace.height() );
74  }
75 
76 
84  if (ProjectItemProxyModel *proxyModel =
85  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
86  proxyModel->setSourceModel(model);
87  }
88  }
89 
90 
98  if (ProjectItemProxyModel *proxyModel =
99  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
100  return proxyModel->sourceModel();
101  }
102  return internalModel();
103  }
104 
105 
113  }
114 
115 
123  return m_internalModel;
124  }
125 
126 
133  void AbstractProjectItemView::dragEnterEvent(QDragEnterEvent *event) {
134  if (internalModel()->canDropMimeData( event->mimeData(),
135  event->dropAction(),
136  0, 0, QModelIndex() ) ) {
137  event->acceptProposedAction();
138  }
139  }
140 
141 
148  void AbstractProjectItemView::dragMoveEvent(QDragMoveEvent *event) {
149  if (internalModel()->canDropMimeData( event->mimeData(),
150  event->dropAction(),
151  0, 0, QModelIndex() ) ) {
152  event->acceptProposedAction();
153  }
154  }
155 
156 
162  void AbstractProjectItemView::dropEvent(QDropEvent *event) {
163  if (internalModel()->canDropMimeData( event->mimeData(),
164  event->dropAction(),
165  0, 0, QModelIndex() ) ) {
166  internalModel()->dropMimeData( event->mimeData(), event->dropAction(),
167  0, 0, QModelIndex() );
168  event->acceptProposedAction();
169  }
170  }
171 
172 
173  void AbstractProjectItemView::moveEvent(QMoveEvent *event) {
174  QMainWindow::moveEvent(event);
175 
176  emit windowChangeEvent(false);
177  }
178 
179 
180  void AbstractProjectItemView::resizeEvent(QResizeEvent *event) {
181  QMainWindow::resizeEvent(event);
182 
183  emit windowChangeEvent(false);
184  }
185 
186 
193  enableActions();
194  }
195 
196 
203  disableActions();
204  }
205 
206 
211  foreach (QAction *action, actions()) {
212  action->setDisabled(true);
213  }
214  }
215 
216 
221  foreach (QAction *action, actions()) {
222  action->setEnabled(true);
223  }
224  }
225 
226 
233  return QList<QAction *>();
234  }
235 
236 
243  return model()->currentItem();
244  }
245 
246 
253  return model()->selectedItems();
254  }
255 
256 
265  if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
266  proxyModel->addItem(item);
267  }
268  }
269 
270 
279  if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
280  proxyModel->addItems(items);
281  }
282  }
283 
284 
293  if (ProjectItemProxyModel *proxyModel =
294  qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
295  proxyModel->removeItem(item);
296  }
297  }
298 
299 
307  foreach (ProjectItem *item, items) {
308  removeItem(item);
309  }
310  }
311 }
$Revision$ $Date$
virtual void enterEvent(QEvent *event)
Enables actions when cursor enters the view.
virtual void addItem(ProjectItem *item)
Adds an item to the view.
$Date$ $Revision$
virtual void leaveEvent(QEvent *event)
Disables actions when cursor leaves the view.
virtual void dropEvent(QDropEvent *event)
Drops the data into the internal model if it can accept the data.
virtual void disableActions()
Disables toolbars and toolpad actions.
virtual void addItems(QList< ProjectItem *> items)
Adds several items to the view.
virtual void removeItems(QList< ProjectItem *> items)
Removes several items from the view.
virtual void setInternalModel(ProjectItemModel *model)
Sets the internal model of the view.
virtual void setModel(ProjectItemModel *model)
Sets the model used by the view.
virtual QSize sizeHint() const
Returns the suggested size.
ProjectItem * currentItem()
Returns the current item of the internal selection model.
virtual void removeItem(ProjectItem *item)
Removes an item to the view.
Provides access to data stored in a Project through Qt&#39;s model-view framework.
virtual ProjectItem * currentItem()
Returns the current item of the model.
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
Allows access to items in a ProjectItemModel through a proxy model.
virtual QList< QAction * > contextMenuActions()
Returns a list of actions appropriate for a context menu.
virtual void dragMoveEvent(QDragMoveEvent *event)
Accepts the drag event if the internal model can accept the mime data.
ProjectItemModel * m_internalModel
The internal model used by the view.
virtual void dragEnterEvent(QDragEnterEvent *event)
Accepts the drag enter event if the internal model can accept the mime data.
AbstractProjectItemView(QWidget *parent=0)
Constructs the AbstractProjectItemView.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
virtual QList< ProjectItem * > selectedItems()
Return the selected items of the model.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:146
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
$Date$ $Revision$
virtual void enableActions()
Enables toolbars and toolpad actions.
virtual ProjectItemModel * model()
Returns the model used by the view.