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#include "XmlStackedHandlerReader.h"
45
46namespace Isis {
54
55 QStatusBar *statusBar = new QStatusBar(this);
56 m_sceneWidget = new MosaicSceneWidget(statusBar, true, false, directory, this);
57 m_sceneWidget->getScene()->installEventFilter(this);
58 m_sceneWidget->setAcceptDrops(false);
59 MosaicGraphicsView *graphicsView = m_sceneWidget->getView();
60 graphicsView->installEventFilter(this);
61 graphicsView->setAcceptDrops(false);
62
63 connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
64 this, SLOT( onItemAdded(ProjectItem *) ) );
65 connect( internalModel(), SIGNAL( itemsAdded() ),
66 this, SLOT( onItemsAdded() ) );
67 connect( internalModel(), SIGNAL( itemRemoved(ProjectItem *) ),
68 this, SLOT( onItemRemoved(ProjectItem *) ) );
69
70 connect(m_sceneWidget, SIGNAL(queueSelectionChanged()),
71 this, SLOT(onQueueSelectionChanged()), Qt::QueuedConnection);
72
73 // Pass on Signals emitted from ControlNetTool, through the MosaicSceneWidget
74 // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
75 connect(m_sceneWidget, SIGNAL(modifyControlPoint(ControlPoint *)),
76 this, SIGNAL(modifyControlPoint(ControlPoint *)));
77
78 connect(m_sceneWidget, SIGNAL(deleteControlPoint(ControlPoint *)),
79 this, SIGNAL(deleteControlPoint(ControlPoint *)));
80
81 connect(m_sceneWidget, SIGNAL(createControlPoint(double, double)),
82 this, SIGNAL(createControlPoint(double, double)));
83
84 connect(m_sceneWidget, SIGNAL(mosCubeClosed(Image *)),
85 this, SLOT(onMosItemRemoved(Image *)));
86
87 // Pass on redrawMeasure signal from Directory, so the control measures are redrawn on all
88 // the footprints. Connection made in Directory from directory's signal to this signal since
89 // Directory doesn't have access to the scene within the sceneWidget.
90 connect(this, SIGNAL(redrawMeasures()), m_sceneWidget->getScene(), SLOT(update()));
91
92 setStatusBar(statusBar);
93
95
96 m_fileListWidget->setWindowTitle( tr("File List") );
97 m_fileListWidget->setObjectName( m_fileListWidget->windowTitle() );
98
99 m_directory = directory;
100
101 QDockWidget *imageFileListdock = new QDockWidget( m_fileListWidget->windowTitle() );
102 imageFileListdock->setObjectName(imageFileListdock->windowTitle());
103 imageFileListdock->setFeatures( QDockWidget::DockWidgetFloatable |
104 QDockWidget::DockWidgetMovable);
105
106 imageFileListdock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
107
108 imageFileListdock->setWidget(m_fileListWidget);
109
110 addDockWidget(Qt::LeftDockWidgetArea, imageFileListdock, Qt::Vertical);
111 setCentralWidget(m_sceneWidget);
112
113 m_permToolBar = addToolBar("Standard Tools");
114 m_permToolBar->setObjectName("permToolBar");
115 m_permToolBar->setIconSize(QSize(22, 22));
116
117 m_activeToolBar = addToolBar("Active Tool");
118 m_activeToolBar->setObjectName("activeToolBar");
119 m_activeToolBar->setIconSize(QSize(22, 22));
120
121 m_toolPad = new ToolPad("Tool Pad", 0);
122 m_toolPad->setObjectName("toolPad");
123 addToolBar(Qt::RightToolBarArea, m_toolPad);
124
125 m_sceneWidget->addToPermanent(m_permToolBar);
127 m_sceneWidget->addTo(m_toolPad);
128
129 // Store the actions for easy enable/disable.
130 foreach (QAction *action, findChildren<QAction *>()) {
131 addAction(action);
132 }
133 // On default, actions are disabled until the cursor enters the view.
135 }
136
141 delete m_fileListWidget;
142 delete m_permToolBar;
143 delete m_activeToolBar;
144 delete m_toolPad;
145
146 m_permToolBar = 0;
147 m_activeToolBar = 0;
148 m_toolPad = 0;
149 }
150
151
158
159
166
167
176 bool Footprint2DView::eventFilter(QObject *watched, QEvent *event) {
177 if (event->type() == QEvent::DragEnter) {
178 dragEnterEvent( static_cast<QDragEnterEvent *>(event) );
179 return true;
180 }
181 else if (event->type() == QEvent::DragMove) {
182 dragMoveEvent( static_cast<QDragMoveEvent *>(event) );
183 return true;
184 }
185 else if (event->type() == QEvent::Drop) {
186 dropEvent( static_cast<QDropEvent *>(event) );
187 return true;
188 }
189
190 return AbstractProjectItemView::eventFilter(watched, event);
191 }
192
193
203 if (!item || (!item->isImage() && !item->isShape())) {
204 return;
205 }
206
207 Image *image;
208 if (item->isShape()) {
209 image = new Image(item->shape()->cube(), item->shape()->footprint(), item->shape()->id());
210 }
211 else if (item->isImage()) {
212 image = item->image();
213 }
214
215 m_images.append(image);
216
217 if (!m_imageItemMap.value(image)) {
218 m_imageItemMap.insert(image, item);
219 }
220 }
221
222
230 // This is called once all selected images have been added to proxy model (internalModel())
231 // This is much faster than adding a single image at a time to the scene widget
232 m_sceneWidget->addImages(m_images);
233 m_fileListWidget->addImages(&m_images);
234 }
235
236
244 if (image) {
245 ImageList images;
246 images.append(image);
247
248 m_sceneWidget->removeImages(images);
249 m_fileListWidget->removeImages(&(images));
250
251 if ( m_imageItemMap.value( image ) ) {
252 m_imageItemMap.remove( image );
253 }
254 }
255 }
256
257
265
266 if (!item) {
267 return;
268 }
269
270 if (item->isImage()) {
271
272 ImageList images;
273 images.append(item->image());
274
275 m_sceneWidget->removeImages(images);
276 m_fileListWidget->removeImages(&(images));
277
278 if ( m_imageItemMap.value( item->image() ) ) {
279 m_imageItemMap.remove( item->image());
280 }
281 }
282 }
283
284
290 ImageList selectedImages = m_sceneWidget->selectedImages();
291
292 if (selectedImages.isEmpty() ) {
293 return;
294 }
295
296 Image *currentImage = selectedImages.first();
297
298 internalModel()->selectionModel()->clear();
299
300 if ( ProjectItem *item = m_imageItemMap.value(currentImage) ) {
301 internalModel()->selectionModel()->setCurrentIndex(item->index(), QItemSelectionModel::Select);
302 }
303
304 foreach (Image *image, selectedImages) {
305 if ( ProjectItem *item = m_imageItemMap.value(image) ) {
306 internalModel()->selectionModel()->select(item->index(), QItemSelectionModel::Select);
307 }
308 }
309 }
310
311
319 foreach (QAction *action, m_toolPad->actions()) {
320 if (action->toolTip() == "Control Net (c)") {
321 action->setEnabled(value);
322 if (value) {
323 MosaicControlNetTool *cnetTool = static_cast<MosaicControlNetTool *>(action->parent());
324 cnetTool->loadNetwork();
325 }
326 }
327 }
328 }
329
330
336 foreach (QAction *action, actions()) {
337 if (action->toolTip() == "Control Net (c)" && !m_directory->project()->activeControl()) {
338 continue;
339 }
340 action->setEnabled(true);
341 }
342 }
343
344
350 xmlReader->pushContentHandler( new XmlHandler(this) );
351 }
352
353
364 void Footprint2DView::save(QXmlStreamWriter &stream, Project *project,
365 FileName newProjectRoot) const {
366
367 stream.writeStartElement("footprint2DView");
368 stream.writeAttribute("objectName", objectName());
369
370 m_fileListWidget->save(stream, project, newProjectRoot);
371 m_sceneWidget->save(stream, project, newProjectRoot);
372
373 stream.writeEndElement();
374 }
375
376
382
383 m_footprintView = footprintView;
384 }
385
386
392
393
409 bool Footprint2DView::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
410 const QString &qName, const QXmlAttributes &atts) {
411 bool result = XmlStackedHandler::startElement(namespaceURI, localName, qName, atts);
412
413 if (result) {
414 if (localName == "mosaicScene") {
415 m_footprintView->mosaicSceneWidget()->load(reader());
416 }
417 if (localName == "imageFileList") {
418 m_footprintView->m_fileListWidget->load(reader());
419 }
420 }
421 return result;
422 }
423
424
425 bool Footprint2DView::XmlHandler::endElement(const QString &namespaceURI,
426 const QString &localName, const QString &qName) {
427 bool result = XmlStackedHandler::endElement(namespaceURI, localName, qName);
428
429 return result;
430 }
431}
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
Footprint2DView * m_footprintView
The Footprint2DView.
~XmlHandler()
The Destructor for Directory::XmlHandler.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
The XML reader invokes this method at the start of every element in the XML document.
XmlHandler(Footprint2DView *footprintView)
This function sets the Directory pointer for the Directory::XmlHandler class.
View for displaying footprints of images in a QMos like way.
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.
void load(XmlStackedHandlerReader *xmlReader)
Loads the Footprint2DView from an XML file.
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:107
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:55
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:289
Control * activeControl()
Return the Active Control (control network)
Definition Project.cpp:1902
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:459
Cube * cube()
Get the Cube * associated with this display property.
Definition Shape.cpp:324
geos::geom::MultiPolygon * footprint()
Get the footprint of this shape (if available).
Definition Shape.cpp:394
Manage a stack of content handlers for reading XML files.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16