Isis 3 Programmer Reference
Footprint2DView.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "Footprint2DView.h"
10
11#include <QAction>
12#include <QDockWidget>
13#include <QDragEnterEvent>
14#include <QDragMoveEvent>
15#include <QDropEvent>
16#include <QItemSelectionModel>
17#include <QList>
18#include <QSize>
19#include <QSizePolicy>
20#include <QStatusBar>
21#include <QToolBar>
22#include <QBoxLayout>
23#include <QHBoxLayout>
24#include <QMainWindow>
25#include <QVBoxLayout>
26#include <QWidget>
27#include <QWidgetAction>
28#include <QXmlStreamWriter>
29
30#include "ControlNetTool.h"
31#include "ControlPoint.h"
32#include "Cube.h"
33#include "Directory.h"
34#include "Image.h"
35#include "ImageFileListWidget.h"
36#include "MosaicGraphicsView.h"
37#include "MosaicSceneWidget.h"
38#include "MosaicControlNetTool.h"
39#include "Project.h"
40#include "ProjectItem.h"
41#include "ProjectItemModel.h"
42#include "Shape.h"
43#include "ToolPad.h"
44
45namespace Isis {
53
54 QStatusBar *statusBar = new QStatusBar(this);
55 m_sceneWidget = new MosaicSceneWidget(statusBar, true, false, directory, this);
56 m_sceneWidget->getScene()->installEventFilter(this);
57 m_sceneWidget->setAcceptDrops(false);
58 MosaicGraphicsView *graphicsView = m_sceneWidget->getView();
59 graphicsView->installEventFilter(this);
60 graphicsView->setAcceptDrops(false);
61
62 connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
63 this, SLOT( onItemAdded(ProjectItem *) ) );
64 connect( internalModel(), SIGNAL( itemsAdded() ),
65 this, SLOT( onItemsAdded() ) );
66 connect( internalModel(), SIGNAL( itemRemoved(ProjectItem *) ),
67 this, SLOT( onItemRemoved(ProjectItem *) ) );
68
69 connect(m_sceneWidget, SIGNAL(queueSelectionChanged()),
70 this, SLOT(onQueueSelectionChanged()), Qt::QueuedConnection);
71
72 // Pass on Signals emitted from ControlNetTool, through the MosaicSceneWidget
73 // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
74 connect(m_sceneWidget, SIGNAL(modifyControlPoint(ControlPoint *)),
75 this, SIGNAL(modifyControlPoint(ControlPoint *)));
76
77 connect(m_sceneWidget, SIGNAL(deleteControlPoint(ControlPoint *)),
78 this, SIGNAL(deleteControlPoint(ControlPoint *)));
79
80 connect(m_sceneWidget, SIGNAL(createControlPoint(double, double)),
81 this, SIGNAL(createControlPoint(double, double)));
82
83 connect(m_sceneWidget, SIGNAL(mosCubeClosed(Image *)),
84 this, SLOT(onMosItemRemoved(Image *)));
85
86 // Pass on redrawMeasure signal from Directory, so the control measures are redrawn on all
87 // the footprints. Connection made in Directory from directory's signal to this signal since
88 // Directory doesn't have access to the scene within the sceneWidget.
89 connect(this, SIGNAL(redrawMeasures()), m_sceneWidget->getScene(), SLOT(update()));
90
91 setStatusBar(statusBar);
92
94
95 m_fileListWidget->setWindowTitle( tr("File List") );
96 m_fileListWidget->setObjectName( m_fileListWidget->windowTitle() );
97
98 m_directory = directory;
99
100 QDockWidget *imageFileListdock = new QDockWidget( m_fileListWidget->windowTitle() );
101 imageFileListdock->setObjectName(imageFileListdock->windowTitle());
102 imageFileListdock->setFeatures( QDockWidget::DockWidgetFloatable |
103 QDockWidget::DockWidgetMovable);
104
105 imageFileListdock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
106
107 imageFileListdock->setWidget(m_fileListWidget);
108
109 addDockWidget(Qt::LeftDockWidgetArea, imageFileListdock, Qt::Vertical);
110 setCentralWidget(m_sceneWidget);
111
112 m_permToolBar = addToolBar("Standard Tools");
113 m_permToolBar->setObjectName("permToolBar");
114 m_permToolBar->setIconSize(QSize(22, 22));
115
116 m_activeToolBar = addToolBar("Active Tool");
117 m_activeToolBar->setObjectName("activeToolBar");
118 m_activeToolBar->setIconSize(QSize(22, 22));
119
120 m_toolPad = new ToolPad("Tool Pad", 0);
121 m_toolPad->setObjectName("toolPad");
122 addToolBar(Qt::RightToolBarArea, m_toolPad);
123
124 m_sceneWidget->addToPermanent(m_permToolBar);
126 m_sceneWidget->addTo(m_toolPad);
127
128 // Store the actions for easy enable/disable.
129 foreach (QAction *action, findChildren<QAction *>()) {
130 addAction(action);
131 }
132 // On default, actions are disabled until the cursor enters the view.
134 }
135
140 delete m_fileListWidget;
141 delete m_permToolBar;
142 delete m_activeToolBar;
143 delete m_toolPad;
144
145 m_permToolBar = 0;
146 m_activeToolBar = 0;
147 m_toolPad = 0;
148 }
149
150
157
158
165
166
175 bool Footprint2DView::eventFilter(QObject *watched, QEvent *event) {
176 if (event->type() == QEvent::DragEnter) {
177 dragEnterEvent( static_cast<QDragEnterEvent *>(event) );
178 return true;
179 }
180 else if (event->type() == QEvent::DragMove) {
181 dragMoveEvent( static_cast<QDragMoveEvent *>(event) );
182 return true;
183 }
184 else if (event->type() == QEvent::Drop) {
185 dropEvent( static_cast<QDropEvent *>(event) );
186 return true;
187 }
188
189 return AbstractProjectItemView::eventFilter(watched, event);
190 }
191
192
202 if (!item || (!item->isImage() && !item->isShape())) {
203 return;
204 }
205
206 Image *image;
207 if (item->isShape()) {
208 image = new Image(item->shape()->cube(), item->shape()->footprint(), item->shape()->id());
209 }
210 else if (item->isImage()) {
211 image = item->image();
212 }
213
214 m_images.append(image);
215
216 if (!m_imageItemMap.value(image)) {
217 m_imageItemMap.insert(image, item);
218 }
219 }
220
221
229 // This is called once all selected images have been added to proxy model (internalModel())
230 // This is much faster than adding a single image at a time to the scene widget
231 m_sceneWidget->addImages(m_images);
232 m_fileListWidget->addImages(&m_images);
233 }
234
235
243 if (image) {
244 ImageList images;
245 images.append(image);
246
247 m_sceneWidget->removeImages(images);
248 m_fileListWidget->removeImages(&(images));
249
250 if ( m_imageItemMap.value( image ) ) {
251 m_imageItemMap.remove( image );
252 }
253 }
254 }
255
256
264
265 if (!item) {
266 return;
267 }
268
269 if (item->isImage()) {
270
271 ImageList images;
272 images.append(item->image());
273
274 m_sceneWidget->removeImages(images);
275 m_fileListWidget->removeImages(&(images));
276
277 if ( m_imageItemMap.value( item->image() ) ) {
278 m_imageItemMap.remove( item->image());
279 }
280 }
281 }
282
283
289 ImageList selectedImages = m_sceneWidget->selectedImages();
290
291 if (selectedImages.isEmpty() ) {
292 return;
293 }
294
295 Image *currentImage = selectedImages.first();
296
297 internalModel()->selectionModel()->clear();
298
299 if ( ProjectItem *item = m_imageItemMap.value(currentImage) ) {
300 internalModel()->selectionModel()->setCurrentIndex(item->index(), QItemSelectionModel::Select);
301 }
302
303 foreach (Image *image, selectedImages) {
304 if ( ProjectItem *item = m_imageItemMap.value(image) ) {
305 internalModel()->selectionModel()->select(item->index(), QItemSelectionModel::Select);
306 }
307 }
308 }
309
310
318 foreach (QAction *action, m_toolPad->actions()) {
319 if (action->toolTip() == "Control Net (c)") {
320 action->setEnabled(value);
321 if (value) {
322 MosaicControlNetTool *cnetTool = static_cast<MosaicControlNetTool *>(action->parent());
323 cnetTool->loadNetwork();
324 }
325 }
326 }
327 }
328
329
335 foreach (QAction *action, actions()) {
336 if (action->toolTip() == "Control Net (c)" && !m_directory->project()->activeControl()) {
337 continue;
338 }
339 action->setEnabled(true);
340 }
341 }
342
343
354 void Footprint2DView::save(QXmlStreamWriter &stream, Project *project,
355 FileName newProjectRoot) const {
356
357 stream.writeStartElement("footprint2DView");
358 stream.writeAttribute("objectName", objectName());
359
360 m_fileListWidget->save(stream, project, newProjectRoot);
361 m_sceneWidget->save(stream, project, newProjectRoot);
362
363 stream.writeEndElement();
364 }
365}
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt's model-view framework.
virtual void dropEvent(QDropEvent *event)
Drops the data into the internal model if it can accept the data.
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 ProjectItemModel * internalModel()
Returns the internal model of the view.
A single control point.
Project * project() const
Gets the Project for this directory.
File name manipulation and expansion.
Definition FileName.h:100
void enableActions()
Enables toolbars and toolpad actions.
ToolPad * m_toolPad
The tool pad.
ImageFileListWidget * fileListWidget()
Accessor for the FileListWidget.
MosaicSceneWidget * mosaicSceneWidget()
Accessor for the MosaicSceneWidget.
MosaicSceneWidget * m_sceneWidget
The scene widget.
void save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot) const
Save the footprint view widgets (ImageFileListWidget and MosaicSceneWidget to an XML file.
QMap< Image *, ProjectItem * > m_imageItemMap
Maps images to their items.
Footprint2DView(Directory *directory, QWidget *parent=0)
Constructor.
Directory * m_directory
The directory.
bool eventFilter(QObject *watched, QEvent *event)
Event filter to filter out drag and drop events.
void onItemsAdded()
Slot called once all selected images have been added to the proxy model.
void onQueueSelectionChanged()
Slot to connect to the queueSelectionChanged signal from a MosiacSceneWidget.
void onItemAdded(ProjectItem *item)
Slot to connect to the itemAdded signal from the model.
QToolBar * m_permToolBar
The permanent tool bar.
ImageFileListWidget * m_fileListWidget
The file list widget.
QToolBar * m_activeToolBar
The active tool bar.
void enableControlNetTool(bool value)
A slot function that is called when directory emits a siganl that an active control network is set.
void onMosItemRemoved(Image *image)
Slot at removes the mosaic item and corresponding image file list item when a cube is closed using th...
void onItemRemoved(ProjectItem *item)
Slot to connect to the itemRemoved signal from the model.
A colored, grouped cube list.
void addImages(ImageList *images)
This method adds the new images to the tree.
void removeImages(ImageList *images)
Removes an imagelist from the FileListWidget.
void save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot) const
This method saves the FootprintColumns in the project and the settings associated with every column.
This represents a cube in a project-based GUI interface.
Definition Image.h:105
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:53
void append(Image *const &value)
Appends an image to the image list.
//TODO: Remove debug printout & comment // 2016-08-25 Tracie Sucharski - Checking Directory pointer f...
void loadNetwork()
Load m_controlNetFile into memory - this will re-load the network if it's already open.
A graphics view that resizes in a more friendly way.
This widget encompasses the entire mosaic scene.
ImageList selectedImages()
Returns a list of all the cubes selected in the scene.
The main project for ipce.
Definition Project.h:287
Control * activeControl()
Return the Active Control (control network)
Definition Project.cpp:1964
Represents an item of a ProjectItemModel in Qt's model-view framework.
bool isShape() const
Returns true if an Shape is stored in the data of the item.
Shape * shape() const
Returns the Shape stored in the data of the item.
Image * image() const
Returns the Image stored in the data of the item.
bool isImage() const
Returns true if an Image is stored in the data of the item.
QString id() const
Get a unique, identifying string associated with this shape.
Definition Shape.cpp:443
Cube * cube()
Get the Cube * associated with this display property.
Definition Shape.cpp:308
geos::geom::MultiPolygon * footprint()
Get the footprint of this shape (if available).
Definition Shape.cpp:378
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16