Isis 3 Programmer Reference
Footprint2DView.cpp
Go to the documentation of this file.
1 
23 #include "IsisDebug.h"
24 
25 #include "Footprint2DView.h"
26 
27 #include <QAction>
28 #include <QDockWidget>
29 #include <QDragEnterEvent>
30 #include <QDragMoveEvent>
31 #include <QDropEvent>
32 #include <QItemSelectionModel>
33 #include <QList>
34 #include <QSize>
35 #include <QSizePolicy>
36 #include <QStatusBar>
37 #include <QToolBar>
38 #include <QBoxLayout>
39 #include <QHBoxLayout>
40 #include <QMainWindow>
41 #include <QVBoxLayout>
42 #include <QWidget>
43 #include <QWidgetAction>
44 #include <QXmlStreamWriter>
45 
46 #include "ControlNetTool.h"
47 #include "ControlPoint.h"
48 #include "Cube.h"
49 #include "Directory.h"
50 #include "Image.h"
51 #include "ImageFileListWidget.h"
52 #include "MosaicGraphicsView.h"
53 #include "MosaicSceneWidget.h"
54 #include "MosaicControlNetTool.h"
55 #include "Project.h"
56 #include "ProjectItem.h"
57 #include "ProjectItemModel.h"
58 #include "Shape.h"
59 #include "ToolPad.h"
60 #include "XmlStackedHandlerReader.h"
61 
62 namespace Isis {
69  AbstractProjectItemView(parent) {
70 
71  QStatusBar *statusBar = new QStatusBar(this);
72  m_sceneWidget = new MosaicSceneWidget(statusBar, true, false, directory, this);
73  m_sceneWidget->getScene()->installEventFilter(this);
74  m_sceneWidget->setAcceptDrops(false);
75  MosaicGraphicsView *graphicsView = m_sceneWidget->getView();
76  graphicsView->installEventFilter(this);
77  graphicsView->setAcceptDrops(false);
78 
79  connect( internalModel(), SIGNAL( itemAdded(ProjectItem *) ),
80  this, SLOT( onItemAdded(ProjectItem *) ) );
81  connect( internalModel(), SIGNAL( itemsAdded() ),
82  this, SLOT( onItemsAdded() ) );
83  connect( internalModel(), SIGNAL( itemRemoved(ProjectItem *) ),
84  this, SLOT( onItemRemoved(ProjectItem *) ) );
85 
86  connect(m_sceneWidget, SIGNAL(queueSelectionChanged()),
87  this, SLOT(onQueueSelectionChanged()), Qt::QueuedConnection);
88 
89  // Pass on Signals emitted from ControlNetTool, through the MosaicSceneWidget
90  // TODO 2016-09-09 TLS Design: Use a proxy model instead of signals?
91  connect(m_sceneWidget, SIGNAL(modifyControlPoint(ControlPoint *)),
92  this, SIGNAL(modifyControlPoint(ControlPoint *)));
93 
94  connect(m_sceneWidget, SIGNAL(deleteControlPoint(ControlPoint *)),
95  this, SIGNAL(deleteControlPoint(ControlPoint *)));
96 
97  connect(m_sceneWidget, SIGNAL(createControlPoint(double, double)),
98  this, SIGNAL(createControlPoint(double, double)));
99 
100  connect(m_sceneWidget, SIGNAL(mosCubeClosed(Image *)),
101  this, SLOT(onMosItemRemoved(Image *)));
102 
103  // Pass on redrawMeasure signal from Directory, so the control measures are redrawn on all
104  // the footprints. Connection made in Directory from directory's signal to this signal since
105  // Directory doesn't have access to the scene within the sceneWidget.
106  connect(this, SIGNAL(redrawMeasures()), m_sceneWidget->getScene(), SLOT(update()));
107 
108  setStatusBar(statusBar);
109 
110  m_fileListWidget = new ImageFileListWidget(directory);
111 
112  m_fileListWidget->setWindowTitle( tr("File List") );
113  m_fileListWidget->setObjectName( m_fileListWidget->windowTitle() );
114 
115  m_directory = directory;
116 
117  QDockWidget *imageFileListdock = new QDockWidget( m_fileListWidget->windowTitle() );
118  imageFileListdock->setObjectName(imageFileListdock->windowTitle());
119  imageFileListdock->setFeatures( QDockWidget::DockWidgetFloatable |
120  QDockWidget::DockWidgetMovable);
121 
122  imageFileListdock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
123 
124  imageFileListdock->setWidget(m_fileListWidget);
125 
126  addDockWidget(Qt::LeftDockWidgetArea, imageFileListdock, Qt::Vertical);
127  setCentralWidget(m_sceneWidget);
128 
129  m_permToolBar = addToolBar("Standard Tools");
130  m_permToolBar->setObjectName("permToolBar");
131  m_permToolBar->setIconSize(QSize(22, 22));
132 
133  m_activeToolBar = addToolBar("Active Tool");
134  m_activeToolBar->setObjectName("activeToolBar");
135  m_activeToolBar->setIconSize(QSize(22, 22));
136 
137  m_toolPad = new ToolPad("Tool Pad", 0);
138  m_toolPad->setObjectName("toolPad");
139  addToolBar(Qt::RightToolBarArea, m_toolPad);
140 
141  m_sceneWidget->addToPermanent(m_permToolBar);
143  m_sceneWidget->addTo(m_toolPad);
144 
145  // Store the actions for easy enable/disable.
146  foreach (QAction *action, findChildren<QAction *>()) {
147  addAction(action);
148  }
149  // On default, actions are disabled until the cursor enters the view.
150  disableActions();
151  }
152 
157  delete m_fileListWidget;
158  delete m_permToolBar;
159  delete m_activeToolBar;
160  delete m_toolPad;
161 
162  m_permToolBar = 0;
163  m_activeToolBar = 0;
164  m_toolPad = 0;
165  }
166 
167 
172  return m_sceneWidget;
173  }
174 
175 
180  return m_fileListWidget;
181  }
182 
183 
192  bool Footprint2DView::eventFilter(QObject *watched, QEvent *event) {
193  if (event->type() == QEvent::DragEnter) {
194  dragEnterEvent( static_cast<QDragEnterEvent *>(event) );
195  return true;
196  }
197  else if (event->type() == QEvent::DragMove) {
198  dragMoveEvent( static_cast<QDragMoveEvent *>(event) );
199  return true;
200  }
201  else if (event->type() == QEvent::Drop) {
202  dropEvent( static_cast<QDropEvent *>(event) );
203  return true;
204  }
205 
206  return AbstractProjectItemView::eventFilter(watched, event);
207  }
208 
209 
219  if (!item || (!item->isImage() && !item->isShape())) {
220  return;
221  }
222 
223  Image *image;
224  if (item->isShape()) {
225  image = new Image(item->shape()->cube(), item->shape()->footprint(), item->shape()->id());
226  }
227  else if (item->isImage()) {
228  image = item->image();
229  }
230 
231  m_images.append(image);
232 
233  if (!m_imageItemMap.value(image)) {
234  m_imageItemMap.insert(image, item);
235  }
236  }
237 
238 
246  // This is called once all selected images have been added to proxy model (internalModel())
247  // This is much faster than adding a single image at a time to the scene widget
248  m_sceneWidget->addImages(m_images);
249  m_fileListWidget->addImages(&m_images);
250  }
251 
252 
260  if (image) {
261  ImageList images;
262  images.append(image);
263 
264  m_sceneWidget->removeImages(images);
265  m_fileListWidget->removeImages(&(images));
266 
267  if ( m_imageItemMap.value( image ) ) {
268  m_imageItemMap.remove( image );
269  }
270  }
271  }
272 
273 
281 
282  if (!item) {
283  return;
284  }
285 
286  if (item->isImage()) {
287 
288  ImageList images;
289  images.append(item->image());
290 
291  m_sceneWidget->removeImages(images);
292  m_fileListWidget->removeImages(&(images));
293 
294  if ( m_imageItemMap.value( item->image() ) ) {
295  m_imageItemMap.remove( item->image());
296  }
297  }
298  }
299 
300 
306  ImageList selectedImages = m_sceneWidget->selectedImages();
307 
308  if (selectedImages.isEmpty() ) {
309  return;
310  }
311 
312  Image *currentImage = selectedImages.first();
313 
314  internalModel()->selectionModel()->clear();
315 
316  if ( ProjectItem *item = m_imageItemMap.value(currentImage) ) {
317  internalModel()->selectionModel()->setCurrentIndex(item->index(), QItemSelectionModel::Select);
318  }
319 
320  foreach (Image *image, selectedImages) {
321  if ( ProjectItem *item = m_imageItemMap.value(image) ) {
322  internalModel()->selectionModel()->select(item->index(), QItemSelectionModel::Select);
323  }
324  }
325  }
326 
327 
335  foreach (QAction *action, m_toolPad->actions()) {
336  if (action->toolTip() == "Control Net (c)") {
337  action->setEnabled(value);
338  if (value) {
339  MosaicControlNetTool *cnetTool = static_cast<MosaicControlNetTool *>(action->parent());
340  cnetTool->loadNetwork();
341  }
342  }
343  }
344  }
345 
346 
352  foreach (QAction *action, actions()) {
353  if (action->toolTip() == "Control Net (c)" && !m_directory->project()->activeControl()) {
354  continue;
355  }
356  action->setEnabled(true);
357  }
358  }
359 
360 
366  xmlReader->pushContentHandler( new XmlHandler(this) );
367  }
368 
369 
380  void Footprint2DView::save(QXmlStreamWriter &stream, Project *project,
381  FileName newProjectRoot) const {
382 
383  stream.writeStartElement("footprint2DView");
384  stream.writeAttribute("objectName", objectName());
385 
386  m_fileListWidget->save(stream, project, newProjectRoot);
387  m_sceneWidget->save(stream, project, newProjectRoot);
388 
389  stream.writeEndElement();
390  }
391 
392 
398 
399  m_footprintView = footprintView;
400  }
401 
402 
407  }
408 
409 
425  bool Footprint2DView::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
426  const QString &qName, const QXmlAttributes &atts) {
427  bool result = XmlStackedHandler::startElement(namespaceURI, localName, qName, atts);
428 
429  if (result) {
430  if (localName == "mosaicScene") {
431  m_footprintView->mosaicSceneWidget()->load(reader());
432  }
433  if (localName == "imageFileList") {
434  m_footprintView->m_fileListWidget->load(reader());
435  }
436  }
437  return result;
438  }
439 
440 
441  bool Footprint2DView::XmlHandler::endElement(const QString &namespaceURI,
442  const QString &localName, const QString &qName) {
443  bool result = XmlStackedHandler::endElement(namespaceURI, localName, qName);
444 
445  return result;
446  }
447 }
Footprint2DView(Directory *directory, QWidget *parent=0)
Constructor.
//TODO: Remove debug printout & comment // 2016-08-25 Tracie Sucharski - Checking Directory pointer f...
$Date$ $Revision$
void onItemsAdded()
Slot called once all selected images have been added to the proxy model.
void loadNetwork()
Load m_controlNetFile into memory - this will re-load the network if it&#39;s already open...
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
The main project for ipce.
Definition: Project.h:289
bool isImage() const
Returns true if an Image is stored in the data of the item.
A graphics view that resizes in a more friendly way.
File name manipulation and expansion.
Definition: FileName.h:116
XmlHandler(Footprint2DView *footprintView)
This function sets the Directory pointer for the Directory::XmlHandler class.
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.
This widget encompasses the entire mosaic scene.
ImageFileListWidget * m_fileListWidget
The file list widget.
View for displaying footprints of images in a QMos like way.
ImageFileListWidget * fileListWidget()
Accessor for the FileListWidget.
$Date$ $Revision$
void load(XmlStackedHandlerReader *xmlReader)
Loads the Footprint2DView from an XML file.
Control * activeControl()
Return the Active Control (control network)
Definition: Project.cpp:1903
void save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot) const
This method saves the FootprintColumns in the project and the settings associated with every column...
QMap< Image *, ProjectItem * > m_imageItemMap
Maps images to their items.
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.
void enableActions()
Enables toolbars and toolpad actions.
AbstractProjectItemView is a base class for views of a ProjectItemModel in Qt&#39;s model-view framework...
void onMosItemRemoved(Image *image)
Slot at removes the mosaic item and corresponding image file list item when a cube is closed using th...
virtual ProjectItemModel * internalModel()
Returns the internal model of the view.
void onItemRemoved(ProjectItem *item)
Slot to connect to the itemRemoved signal from the model.
Directory * m_directory
The directory.
bool eventFilter(QObject *watched, QEvent *event)
Event filter to filter out drag and drop events.
ToolPad * m_toolPad
The tool pad.
QItemSelectionModel * selectionModel()
Returns the internal selection model.
Cube * cube()
Get the Cube * associated with this display property.
Definition: Shape.cpp:325
QToolBar * m_activeToolBar
The active tool bar.
void onQueueSelectionChanged()
Slot to connect to the queueSelectionChanged signal from a MosiacSceneWidget.
void removeImages(ImageList *images)
Removes an imagelist from the FileListWidget.
~Footprint2DView()
Destructor.
ImageList selectedImages()
Returns a list of all the cubes selected in the scene.
virtual void dragMoveEvent(QDragMoveEvent *event)
Accepts the drag event if the internal model can accept the mime data.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
void addImages(ImageList *images)
This method adds the new images to the tree.
A single control point.
Definition: ControlPoint.h:369
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
geos::geom::MultiPolygon * footprint()
Get the footprint of this shape (if available).
Definition: Shape.cpp:395
Image * image() const
Returns the Image stored in the data of the item.
QString id() const
Get a unique, identifying string associated with this shape.
Definition: Shape.cpp:460
void append(Image *const &value)
Appends an image to the image list.
Definition: ImageList.cpp:153
virtual void dragEnterEvent(QDragEnterEvent *event)
Accepts the drag enter event if the internal model can accept the mime data.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Shape * shape() const
Returns the Shape stored in the data of the item.
A colored, grouped cube list.
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:146
MosaicSceneWidget * mosaicSceneWidget()
Accessor for the MosaicSceneWidget.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Project * project() const
Gets the Project for this directory.
Definition: Directory.cpp:1325
bool isShape() const
Returns true if an Shape is stored in the data of the item.
~XmlHandler()
The Destructor for Directory::XmlHandler.
void enableControlNetTool(bool value)
A slot function that is called when directory emits a siganl that an active control network is set...
Footprint2DView * m_footprintView
The Footprint2DView.
MosaicSceneWidget * m_sceneWidget
The scene widget.
Manage a stack of content handlers for reading XML files.
void onItemAdded(ProjectItem *item)
Slot to connect to the itemAdded signal from the model.
QToolBar * m_permToolBar
The permanent tool bar.
void save(QXmlStreamWriter &stream, Project *project, FileName newProjectRoot) const
Save the footprint view widgets (ImageFileListWidget and MosaicSceneWidget to an XML file...