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
27namespace 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
100
101
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
180 }
181
182
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
264 void AbstractProjectItemView::addItems(QList<ProjectItem *> items) {
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
292 void AbstractProjectItemView::removeItems(QList<ProjectItem *> items) {
293 foreach (ProjectItem *item, items) {
294 removeItem(item);
295 }
296 }
297}
virtual QList< QAction * > contextMenuActions()
Returns a list of actions appropriate for a context menu.
virtual void dropEvent(QDropEvent *event)
Drops the data into the internal model if it can accept the data.
virtual void enableActions()
Enables toolbars and toolpad actions.
virtual void dragEnterEvent(QDragEnterEvent *event)
Accepts the drag enter event if the internal model can accept the mime data.
virtual void dragMoveEvent(QDragMoveEvent *event)
Accepts the drag event if the internal model can accept the mime data.
virtual void disableActions()
Disables toolbars and toolpad actions.
virtual void enterEvent(QEvent *event)
Enables actions when cursor enters the view.
virtual QList< ProjectItem * > selectedItems()
Return the selected items of the model.
virtual void addItem(ProjectItem *item)
Adds an item to the view.
ProjectItemModel * m_internalModel
The internal model used by the view.
virtual QSize sizeHint() const
Returns the suggested size.
virtual void removeItems(QList< ProjectItem * > items)
Removes several items from the view.
virtual ProjectItemModel * model()
Returns the model used by the view.
virtual void setInternalModel(ProjectItemModel *model)
Sets the internal model of the view.
virtual void addItems(QList< ProjectItem * > items)
Adds several items to the view.
virtual void removeItem(ProjectItem *item)
Removes an item to the view.
AbstractProjectItemView(QWidget *parent=0)
Constructs the AbstractProjectItemView.
virtual void setModel(ProjectItemModel *model)
Sets the model used by the view.
virtual ProjectItem * currentItem()
Returns the current item of the model.
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
virtual void leaveEvent(QEvent *event)
Disables actions when cursor leaves the view.
Represents an item of a ProjectItemModel in Qt's model-view framework.
Provides access to data stored in a Project through Qt's model-view framework.
Allows access to items in a ProjectItemModel through a proxy model.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16