Isis 3.0 Programmer Reference
Back | Home
ProjectItemModel.cpp
Go to the documentation of this file.
1 
23 #include "IsisDebug.h"
24 
25 #include "ProjectItemModel.h"
26 
27 #include <QItemSelection>
28 #include <QList>
29 #include <QMimeData>
30 #include <QModelIndex>
31 #include <QObject>
32 #include <QStandardItemModel>
33 #include <QString>
34 
35 #include "BundleSolutionInfo.h"
36 #include "Control.h"
37 #include "ControlList.h"
38 #include "GuiCameraList.h"
39 #include "ImageList.h"
40 #include "Project.h"
41 #include "ProjectItem.h"
42 #include "ShapeList.h"
43 #include "TargetBodyList.h"
44 
45 namespace Isis {
52  m_selectionModel = new QItemSelectionModel(this, this);
53  connect(m_selectionModel, SIGNAL(selectionChanged(const QItemSelection &,
54  const QItemSelection &) ),
55  this, SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
56 
57  connect( this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
58  this, SLOT(onRowsInserted(const QModelIndex &, int, int)) );
59 
60  connect( this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
61  this, SLOT(onRowsRemoved(const QModelIndex &, int, int)) );
62 
63  }
64 
65 
70 
71  }
72 
73 
87  bool ProjectItemModel::canDropMimeData(const QMimeData *data,
88  Qt::DropAction action,
89  int row, int column,
90  const QModelIndex &parent) const {
91  return false;
92  }
93 
94 
100  QItemSelectionModel *ProjectItemModel::selectionModel() {
101  return m_selectionModel;
102  }
103 
104 
115 
116  connect(project, SIGNAL( nameChanged(QString) ),
117  this, SLOT( onNameChanged(QString) ) );
118  connect(project, SIGNAL( bundleSolutionInfoAdded(BundleSolutionInfo *) ),
120  connect(project, SIGNAL( controlAdded(Control *) ),
121  this, SLOT( onControlAdded(Control *) ) );
122  connect(project, SIGNAL( controlListAdded(ControlList *) ),
123  this, SLOT( onControlListAdded(ControlList *) ) );
124  connect(project, SIGNAL( imagesAdded(ImageList *) ),
125  this, SLOT( onImagesAdded(ImageList *) ) );
126  connect(project, SIGNAL( shapesAdded(ShapeList *) ),
127  this, SLOT( onShapesAdded(ShapeList *) ) );
128  connect(project, SIGNAL( targetsAdded(TargetBodyList *) ),
129  this, SLOT( onTargetsAdded(TargetBodyList *) ) );
130  connect(project, SIGNAL( guiCamerasAdded(GuiCameraList *) ),
131  this, SLOT( onGuiCamerasAdded(GuiCameraList *) ) );
132  ProjectItem *projectItem = new ProjectItem(project);
133  appendRow(projectItem);
134 // qDebug()<<"ProjectItem::addProject after appendRow projectItem rowCount = "<<rowCount();
135  return projectItem;
136  }
137 
138 
145  return itemFromIndex( selectionModel()->currentIndex() );
146  }
147 
148 
155  QItemSelection selection = selectionModel()->selection();
156  QList<ProjectItem *> items;
157 
158  foreach ( QModelIndex index, selection.indexes() ) {
159  items.append( itemFromIndex(index) );
160  }
161 
162  return items;
163  }
164 
165 
176  ProjectItem *ProjectItemModel::findItemData(const QVariant &data, int role) {
177 
178 // qDebug()<<"ProjectItemModel::findItemData incoming data = "<<data;
179  for (int i=0; i<rowCount(); i++) {
180 // qDebug()<<"ProjectItemModel::findItemData BEFORE call: item(i)->findItemData...";
181  ProjectItem *projectItem = item(i)->findItemData(data, role);
182 // qDebug()<<"ProjectItemModel::findItemData AFTER call: item(i)->findItemData...";
183  if (projectItem) {
184  return projectItem;
185  }
186  }
187 
188  return 0;
189  }
190 
191 
198  if (!item) {
199  return;
200  }
201 // qDebug()<<"ProjectItemModel::removeItem item= "<<item;
202  if ( ProjectItem *parentItem = item->parent() ) {
203 // qDebug()<<"ProjectItemModel::removeItem ParentItem ";
204  removeRow( item->row(), parentItem->index() );
205  }
206  else {
207 // qDebug()<<"ProjectItemModel::removeItem item row = "<<item->row();
208  removeRow( item->row() );
209  }
210  }
211 
212 
219  foreach (ProjectItem *item, items) {
220  removeItem(item);
221  }
222  }
223 
224 
231  QStandardItemModel::appendRow(item);
232  }
233 
234 
242  QModelIndex ProjectItemModel::indexFromItem(const ProjectItem *item) {
243  return QStandardItemModel::indexFromItem(item);
244  }
245 
246 
254  QStandardItemModel::insertRow(row, item);
255  }
256 
257 
266  return static_cast<ProjectItem *>( QStandardItemModel::item(row) );
267  }
268 
269 
277  ProjectItem *ProjectItemModel::itemFromIndex(const QModelIndex &index) {
278  return static_cast<ProjectItem *>( QStandardItemModel::itemFromIndex(index) );
279  }
280 
281 
288  void ProjectItemModel::setItem(int row, ProjectItem *item) {
289  QStandardItemModel::setItem(row, item);
290  }
291 
292 
301  QList<QStandardItem *> items = QStandardItemModel::takeRow(row);
302 
303  if ( items.isEmpty() ) {
304  return 0;
305  }
306 
307  return static_cast<ProjectItem *>( items.first() );
308  }
309 
310 
317  void ProjectItemModel::onNameChanged(QString newName) {
318  Project *project = qobject_cast<Project *>( sender() );
319 
320  if (!project) {
321  return;
322  }
323 
324  for (int i=0; i<rowCount(); i++) {
325  ProjectItem *projectItem = item(i);
326  if (projectItem->project() == project) {
327  projectItem->setText(newName);
328  }
329  }
330  }
331 
332 
344  Project *project = qobject_cast<Project *>( sender() );
345 
346  if (!project) {
347  return;
348  }
349 
350  for (int i=0; i<rowCount(); i++) {
351  ProjectItem *projectItem = item(i);
352  if (projectItem->project() == project) {
353  for (int j=0; j < projectItem->rowCount(); j++) {
354  ProjectItem *resultsItem = projectItem->child(j);
355  if (resultsItem->text() == "Results") {
356  resultsItem->appendRow( new ProjectItem(bundleSolutionInfo) );
357  }
358  }
359  }
360  }
361  }
362 
363 
373  Project *project = qobject_cast<Project *>( sender() );
374 
375  if (!project) {
376  return;
377  }
378 
379  for (int i=0; i<rowCount(); i++) {
380  ProjectItem *projectItem = item(i);
381  if (projectItem->project() == project) {
382  for (int j=0; j < projectItem->rowCount(); j++) {
383  ProjectItem *controlsItem = projectItem->child(j);
384  if (controlsItem->text() == "Control Networks") {
385  for (int k=0; k < controlsItem->rowCount(); k++) {
386  ProjectItem *controlListItem = controlsItem->child(k);
387  ControlList *controlList = controlListItem->controlList();
388  if ( controlList && controlList->contains(control) ) {
389  controlListItem->appendRow( new ProjectItem(control) );
390  }
391  }
392  }
393  }
394  }
395  }
396 // qDebug()<<"ProjectItemModel::onControlAdded rowCount = "<<rowCount();
397  }
398 
399 
411  Project *project = qobject_cast<Project *>( sender() );
412 
413  if (!project) {
414  return;
415  }
416 
417  for (int i=0; i<rowCount(); i++) {
418  ProjectItem *projectItem = item(i);
419  if (projectItem->project() == project) {
420  for (int j=0; j < projectItem->rowCount(); j++) {
421  ProjectItem *controlsItem = projectItem->child(j);
422  if (controlsItem->text() == "Control Networks") {
423  controlsItem->appendRow( new ProjectItem(controlList) );
424  }
425  }
426  }
427  }
428  }
429 
430 
440 // qDebug()<<"ProjectItemModel::onImagesAdded before add rowCount = "<<rowCount();
441  Project *project = qobject_cast<Project *>( sender() );
442 
443  if (!project) {
444  return;
445  }
446 
447  for (int i=0; i<rowCount(); i++) {
448  ProjectItem *projectItem = item(i);
449  if (projectItem->project() == project) {
450  for (int j=0; j < projectItem->rowCount(); j++) {
451  ProjectItem *imagesItem = projectItem->child(j);
452  if (imagesItem->text() == "Images") {
453  imagesItem->appendRow( new ProjectItem(imageList) );
454  }
455  }
456  }
457  }
458 // qDebug()<<"ProjectItemModel::onImagesAdded after add rowCount = "<<rowCount();
459  }
460 
461 
470  Project *project = qobject_cast<Project *>( sender() );
471 
472  if (!project) {
473  return;
474  }
475  for (int i=0; i<rowCount(); i++) {
476  ProjectItem *projectItem = item(i);
477  if (projectItem->project() == project) {
478  for (int j=0; j < projectItem->rowCount(); j++) {
479  ProjectItem *shapesItem = projectItem->child(j);
480  if (shapesItem->text() == "Shapes") {
481  shapesItem->appendRow( new ProjectItem(shapes) );
482  }
483  }
484  }
485  }
486  }
487 
488 
498  Project *project = qobject_cast<Project *>( sender() );
499 
500  if (!project) {
501  return;
502  }
503 
504  for (int i=0; i<rowCount(); i++) {
505  ProjectItem *projectItem = item(i);
506  if (projectItem->project() == project) {
507  for (int j=0; j < projectItem->rowCount(); j++) {
508  ProjectItem *targetsItem = projectItem->child(j);
509  if (targetsItem->text() == "Target Body") {
510  foreach(TargetBodyQsp target, *targets) {
511  bool append = true;
512  for (int k=0; k < targetsItem->rowCount(); k++) {
513  ProjectItem *targetItem = targetsItem->child(k);
514  if (targetItem->targetBody() == target) {
515  append = false;
516  }
517  }
518  if (append) {
519  targetsItem->appendRow( new ProjectItem(target) );
520  }
521  }
522  }
523  }
524  }
525  }
526  }
527 
528 
538  Project *project = qobject_cast<Project *>( sender() );
539 
540  if (!project) {
541  return;
542  }
543 
544  for (int i=0; i<rowCount(); i++) {
545  ProjectItem *projectItem = item(i);
546  if (projectItem->project() == project) {
547  for (int j=0; j < projectItem->rowCount(); j++) {
548  ProjectItem *camerasItem = projectItem->child(j);
549  if (camerasItem->text() == "Sensors") {
550  foreach(GuiCameraQsp camera, *cameras) {
551  bool append = true;
552  for (int k=0; k < camerasItem->rowCount(); k++) {
553  ProjectItem *cameraItem = camerasItem->child(k);
554  if (cameraItem->guiCamera() == camera) {
555  append = false;
556  }
557  }
558  if (append) {
559  camerasItem->appendRow( new ProjectItem(camera) );
560  }
561  }
562  }
563  }
564  }
565  }
566  }
567 
568 
579  void ProjectItemModel::onSelectionChanged(const QItemSelection &selected,
580  const QItemSelection &deselected) {
582  foreach ( QModelIndex index, selected.indexes() ) {
583  selectedItems.append( itemFromIndex(index) );
584  }
585 
586  foreach (ProjectItem *item, selectedItems) {
587  if ( item->isImage() ) {
588  item->image()->displayProperties()->setSelected(true);
589  }
590  }
591 
592  QList<ProjectItem *> deselectedItems;
593  foreach ( QModelIndex index, deselected.indexes() ) {
594  deselectedItems.append( itemFromIndex(index) );
595  }
596 
597  foreach (ProjectItem *item, deselectedItems) {
598  if ( item->isImage() ) {
599  item->image()->displayProperties()->setSelected(false);
600  }
601  }
602  }
603 
604 
615  void ProjectItemModel::onRowsInserted(const QModelIndex &parent, int start, int end) {
616  for (int row=start; row <= end; row++) {
617  QModelIndex newIndex = index(row, 0, parent);
618  ProjectItem *item = itemFromIndex(newIndex);
619  emit itemAdded(item);
620  }
621  }
622 
623 
633  void ProjectItemModel::onRowsRemoved(const QModelIndex &parent, int start, int end) {
634  for (int row=start; row <= end; row++) {
635  QModelIndex newIndex = index(row, 0, parent);
636  ProjectItem *item = itemFromIndex(newIndex);
637 // qDebug()<<"ProjectItemModel::onRowsRemoved this = "<<this<<" item = "<<item;
638  emit itemRemoved(item);
639  }
640 // qDebug()<<"ProjectItemModel::onRowsRemoved Source model : "<<this<<" row count = "<<rowCount();
641  }
642 }
643 
QModelIndex indexFromItem(const ProjectItem *item)
Returns the QModelIndex corresponding to a given ProjectItem.
This represents an ISIS control net in a project-based GUI interface.
Definition: Control.h:57
Internalizes a list of shapes and allows for operations on the entire list.
Definition: ShapeList.h:33
void insertRow(int row, ProjectItem *item)
Inserts a top-level item at the given row.
void itemAdded(ProjectItem *)
This signal is emitted when a ProjectItem is added to the model.
ProjectItem * takeItem(int row)
Removes the top-level row and returns the removed item.
$Date$ $Revision$
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:44
void onControlAdded(Control *control)
Slot to connect to the controlAdded() signal from a project.
The main project for cnetsuite.
Definition: Project.h:105
void appendRow(ProjectItem *item)
Appends an item to the children of this item.
ProjectItem * itemFromIndex(const QModelIndex &index)
Returns the ProjectItem corresponding to a given QModelIndex.
TargetBodyQsp targetBody() const
Returns the TargetBodyQsp stored in the data of the item.
Container class for BundleAdjustment results.
Maintains a list of Controls so that control nets can easily be copied from one Project to another...
Definition: ControlList.h:34
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
You cannot drop mime data into the ProjectItemModel.
bool isImage() const
Returns true if an Image is stored in the data of the item.
ProjectItem * currentItem()
Returns the current item of the internal selection model.
void onImagesAdded(ImageList *images)
Slot to connect to the imagesAdded() signal from a Project.
List for holding TargetBodies.
void setSelected(bool)
Change the selected state associated with this cube.
void onControlListAdded(ControlList *controlList)
Slot to connect to the controlListAdded() signal from a Project.
ProjectItem * findItemData(const QVariant &value, int role=Qt::UserRole+1)
Finds and returns the first item in the model that contains the data in the role. ...
ProjectItem * parent() const
Returns the parent item of this item.
void onBundleSolutionInfoAdded(BundleSolutionInfo *bundleSolutionInfo)
Slot to connect to the bundleSolutionInfoAdded() signal from a project.
void onRowsRemoved(const QModelIndex &parent, int start, int end)
Slot to connect to the rowsAboutToBeRemoved() signal from QAbstractItemModel.
void onTargetsAdded(TargetBodyList *targets)
Slot to connect to the targetsAdded() signal from a Project.
Project * project() const
Returns the Project stored in the data of the item.
ProjectItem * findItemData(const QVariant &data, int role=Qt::UserRole+1)
Returns the first item found that contains the given data in the given role or a null pointer if no i...
Image * image() const
Returns the Image stored in the data of the item.
void appendRow(ProjectItem *item)
Appends a top-level item to the model.
ControlList * controlList() const
Returns the ControlList stored in the data of the item.
QItemSelectionModel * selectionModel()
Returns the internal selection model.
QSharedPointer< TargetBody > TargetBodyQsp
Defines A smart pointer to a TargetBody obj.
Definition: TargetBody.h:224
void onGuiCamerasAdded(GuiCameraList *cameras)
Slot to connect to the guiCamerasAdded() signal from a Project.
GuiCameraQsp guiCamera() const
Returns the GuiCameraQsp stored in the data of the item.
virtual void removeItems(QList< ProjectItem * > items)
Removes a list of items and their children from the model.
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
Definition: Image.cpp:285
ProjectItem * item(int row)
Returns the top-level item at the given row.
void onNameChanged(QString newName)
Slot to connect to the nameChanged() signal from a Project.
~ProjectItemModel()
Destructs the model.
List of GuiCameras saved as QSharedPointers.
Definition: GuiCameraList.h:35
void setItem(int row, ProjectItem *item)
Sets the item at the top-level row.
void onRowsInserted(const QModelIndex &parent, int start, int end)
Slot to connect to the rowsInserted() signal from QAbstractItemModel.
QSharedPointer< GuiCamera > GuiCameraQsp
GuiCameraQsp Represents a smart pointer to a GuiCamera object.
Definition: GuiCamera.h:188
$Date$ $Revision$
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Slot to connect to the selectionChanged() signal from a selection model.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Represents an item of a ProjectItemModel in Qt&#39;s model-view framework.
Definition: ProjectItem.h:113
QItemSelectionModel * m_selectionModel
The internal selection model.
ProjectItemModel(QObject *parent=0)
Constructs an empty model.
ProjectItem * child(int row) const
Returns the child item at a given row.
void onShapesAdded(ShapeList *shapes)
Slot to connect to the shapesAdded() signal from a Project.
ProjectItem * addProject(Project *project)
Adds a Project to the model.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:26:46