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 <QDragEnterEvent>
14#include <QDragMoveEvent>
15#include <QDropEvent>
16#include <QList>
17#include <QMainWindow>
18#include <QRect>
19#include <QSizePolicy>
20#include <QWidget>
21#include <QGuiApplication>
22#include <QScreen>
23
24#include "ProjectItem.h"
25#include "ProjectItemModel.h"
26#include "ProjectItemProxyModel.h"
27
28
29namespace Isis {
30
37
38 setWindowFlags(Qt::Widget);
39
40 QSizePolicy policy = sizePolicy();
41 policy.setHorizontalPolicy(QSizePolicy::Expanding);
42 policy.setVerticalPolicy(QSizePolicy::Expanding);
43 setSizePolicy(policy);
44
46 setAcceptDrops(true);
47 }
48
49
56
57 // Size hint is made large as a hack to have the views fill the available dock
58 // space. SizePolicy alone did not work.
59 QRect availableSpace = (QGuiApplication::primaryScreen()->availableGeometry());
60 return QSize( .89 * availableSpace.width(), .5 * availableSpace.height() );
61 }
62
63
71 if (ProjectItemProxyModel *proxyModel =
72 qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
73 proxyModel->setSourceModel(model);
74 }
75 }
76
77
85 if (ProjectItemProxyModel *proxyModel =
86 qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
87 return proxyModel->sourceModel();
88 }
89 return internalModel();
90 }
91
92
101
102
112
113
120 void AbstractProjectItemView::dragEnterEvent(QDragEnterEvent *event) {
121 if (internalModel()->canDropMimeData( event->mimeData(),
122 event->dropAction(),
123 0, 0, QModelIndex() ) ) {
124 event->acceptProposedAction();
125 }
126 }
127
128
135 void AbstractProjectItemView::dragMoveEvent(QDragMoveEvent *event) {
136 if (internalModel()->canDropMimeData( event->mimeData(),
137 event->dropAction(),
138 0, 0, QModelIndex() ) ) {
139 event->acceptProposedAction();
140 }
141 }
142
143
149 void AbstractProjectItemView::dropEvent(QDropEvent *event) {
150 if (internalModel()->canDropMimeData( event->mimeData(),
151 event->dropAction(),
152 0, 0, QModelIndex() ) ) {
153 internalModel()->dropMimeData( event->mimeData(), event->dropAction(),
154 0, 0, QModelIndex() );
155 event->acceptProposedAction();
156 }
157 }
158
159
160 void AbstractProjectItemView::moveEvent(QMoveEvent *event) {
161 QMainWindow::moveEvent(event);
162
163 emit windowChangeEvent(false);
164 }
165
166
167 void AbstractProjectItemView::resizeEvent(QResizeEvent *event) {
168 QMainWindow::resizeEvent(event);
169
170 emit windowChangeEvent(false);
171 }
172
173
181 }
182
183
191 }
192
193
198 foreach (QAction *action, actions()) {
199 action->setDisabled(true);
200 }
201 }
202
203
208 foreach (QAction *action, actions()) {
209 action->setEnabled(true);
210 }
211 }
212
213
220 return QList<QAction *>();
221 }
222
223
230 return model()->currentItem();
231 }
232
233
240 return model()->selectedItems();
241 }
242
243
252 if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
253 proxyModel->addItem(item);
254 }
255 }
256
257
265 void AbstractProjectItemView::addItems(QList<ProjectItem *> items) {
266 if (ProjectItemProxyModel *proxyModel = qobject_cast<ProjectItemProxyModel *>( internalModel() )) {
267 proxyModel->addItems(items);
268 }
269 }
270
271
280 if (ProjectItemProxyModel *proxyModel =
281 qobject_cast<ProjectItemProxyModel *>( internalModel() ) ) {
282 proxyModel->removeItem(item);
283 }
284 }
285
286
293 void AbstractProjectItemView::removeItems(QList<ProjectItem *> items) {
294 foreach (ProjectItem *item, items) {
295 removeItem(item);
296 }
297 }
298}
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