Isis 3 Programmer Reference
TargetBodyList.cpp
Go to the documentation of this file.
1 
23 #include "TargetBodyList.h"
24 
25 //#include <QAction>
26 #include <QDebug>
27 #include <QDir>
28 #include <QFile>
29 #include <QFuture>
30 #include <QInputDialog>
31 #include <QLabel>
32 #include <QProgressDialog>
33 #include <QtConcurrentMap>
34 #include <QXmlStreamWriter>
35 
36 #include "FileName.h"
37 #include "IException.h"
38 #include "IString.h"
39 #include "Project.h"
40 #include "TargetBody.h"
41 #include "XmlStackedHandlerReader.h"
42 
43 namespace Isis {
52  TargetBodyList::TargetBodyList(QString name, QString path, QObject *parent) : QObject(parent) {
53  m_name = name;
54  m_path = path;
55  }
56 
57 
64  }
65 
66 
74  append(targetBodys);
75  }
76 
77 
86  QObject *parent) : QObject(parent) {
87  xmlReader->pushContentHandler(new XmlHandler(this, project));
88  }
89 
90 
97  QList<TargetBodyQsp>(other) {
98  m_name = other.m_name;
99  m_path = other.m_path;
100  }
101 
102 
107 // TargetBodyList::TargetBodyList(QStringList &fileNames) {
108 // foreach (QString fileName, fileNames) {
109 // try {
110 // TargetBodyQsp targetBody = TargetBodyQsp(new TargetBody(fileName);
111 // append(targetBody);
112 // }
113 // catch (IException &) {
114 // }
115 // }
116 // }
117 
118 
123  }
124 
125 
135  emit countChanged(count());
136  }
137 
138 
148  emit countChanged(count());
149  }
150 
151 
158  bool countChanging = count();
160  if (countChanging) {
161  emit countChanged(count());
162  }
163  }
164 
165 
174  iterator result = QList<TargetBodyQsp>::erase(pos);
175  emit countChanged(count());
176  return result;
177  }
178 
179 
193  iterator result = QList<TargetBodyQsp>::erase(begin, end);
194  emit countChanged(count());
195  return result;
196  }
197 
198 
207  void TargetBodyList::insert(int i, TargetBodyQsp const &value) {
209 
210  emit countChanged(count());
211  }
212 
213 
226  iterator result = QList<TargetBodyQsp>::insert(before, value);
227  emit countChanged(count());
228  return result;
229  }
230 
231 
241  emit countChanged(count());
242  }
243 
244 
254  emit countChanged(count());
255  }
256 
257 
267  emit countChanged(count());
268  }
269 
270 
281  int result = QList<TargetBodyQsp>::removeAll(value);
282 
283  if (result != 0) {
284  emit countChanged(count());
285  }
286 
287  return result;
288  }
289 
290 
300  emit countChanged(count());
301  }
302 
303 
311  emit countChanged(count());
312  }
313 
314 
322  emit countChanged(count());
323  }
324 
325 
336  bool result = QList<TargetBodyQsp>::removeOne(value);
337 
338  if (result) {
339  emit countChanged(count());
340  }
341 
342  return result;
343  }
344 
345 
355 
356  if (count() != other.count()) {
357  emit countChanged(count());
358  }
359  }
360 
361 
373  emit countChanged(count());
374  return result;
375  }
376 
377 
387  emit countChanged(count());
388  return result;
389  }
390 
391 
401  emit countChanged(count());
402  return result;
403  }
404 
405 
417 
418  if (other.count()) {
419  emit countChanged(count());
420  }
421 
422  return *this;
423  }
424 
425 
437  emit countChanged(count());
438  return *this;
439  }
440 
441 
451  TargetBodyList &TargetBodyList::operator<<(const QList<TargetBodyQsp> &other) {
453 
454  if (other.count()) {
455  emit countChanged(count());
456  }
457 
458  return *this;
459  }
460 
461 
473  emit countChanged(count());
474  return *this;
475  }
476 
477 
488  bool countChanging = (rhs.count() != count());
490 
491  if (countChanging) {
492  emit countChanged(count());
493  }
494 
495  return *this;
496  }
497 
498 
507  bool countChanging = (rhs.count() != count());
509 
510  m_name = rhs.m_name;
511  m_path = rhs.m_path;
512 
513  if (countChanging) {
514  emit countChanged(count());
515  }
516 
517  return *this;
518  }
519 
520 
525 // QList<QAction *> TargetBodyList::supportedActions(Project *project) {
526 // QList<QAction *> actions;
527 
528 // // It turns out connect() statements cannot be templated, hence they aren't inside of
529 // // createWorkOrder().
530 // if (allSupport(ImageDisplayProperties::Color)) {
531 // QAction *alphaAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ChangeTransparency);
532 // if (!project) {
533 // connect(alphaAction, SIGNAL(triggered()),
534 // this, SLOT(askAndUpdateAlpha()));
535 // }
536 // actions.append(alphaAction);
537 
538 // QAction *colorAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ChangeColor);
539 // if (!project) {
540 // connect(colorAction, SIGNAL(triggered()),
541 // this, SLOT(askAndUpdateColor()));
542 // }
543 // actions.append(colorAction);
544 
545 
546 // QAction *ranColorAction = createWorkOrder(project, TargetBodyListActionWorkOrder::RandomizeColor);
547 // if (!project) {
548 // connect(ranColorAction, SIGNAL(triggered()),
549 // this, SLOT(showRandomColor()));
550 // }
551 // actions.append(ranColorAction);
552 // }
553 
554 
555 // if (allSupport(ImageDisplayProperties::ShowLabel)) {
556 // QAction *labelVisibleAction = createWorkOrder(project,
557 // TargetBodyListActionWorkOrder::ToggleShowLabel);
558 // if (!project) {
559 // connect(labelVisibleAction, SIGNAL(triggered()),
560 // this, SLOT(saveAndToggleShowLabel()));
561 // }
562 // actions.append(labelVisibleAction);
563 // }
564 
565 
566 // if (allSupport(ImageDisplayProperties::ShowFill)) {
567 // QAction *fillAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ToggleShowFilled);
568 // if (!project) {
569 // connect(fillAction, SIGNAL(triggered()),
570 // this, SLOT(saveAndToggleShowFill()));
571 // }
572 // actions.append(fillAction);
573 // }
574 
575 
576 // if (allSupport(ImageDisplayProperties::ShowDNs)) {
577 // QAction *cubeDataAction = createWorkOrder(project,
578 // TargetBodyListActionWorkOrder::ToggleShowCubeData);
579 // if (!project) {
580 // connect(cubeDataAction, SIGNAL(triggered()),
581 // this, SLOT(saveAndToggleShowDNs()));
582 // }
583 // actions.append(cubeDataAction);
584 // }
585 
586 
587 // if (allSupport(ImageDisplayProperties::ShowOutline)) {
588 // QAction *outlineAction = createWorkOrder(project,
589 // TargetBodyListActionWorkOrder::ToggleShowOutline);
590 // if (!project) {
591 // connect(outlineAction, SIGNAL(triggered()),
592 // this, SLOT(saveAndToggleShowOutline()));
593 // }
594 // actions.append(outlineAction);
595 // }
596 
597 // actions.append(NULL);
598 
599 // if (!project) {
600 // if (allSupport(ImageDisplayProperties::ZOrdering)) {
601 // QAction *moveToTopAct = new QAction(tr("Bring to Front"), this);
602 // QAction *moveUpAct = new QAction(tr("Bring Forward"), this);
603 // QAction *moveToBottomAct = new QAction(tr("Send to Back"), this);
604 // QAction *moveDownAct = new QAction(tr("Send Backward"), this);
605 
606 // foreach (Image *image, *this) {
607 // connect(moveToTopAct, SIGNAL(triggered()),
608 // image->displayProperties(), SIGNAL(moveToTop()));
609 
610 // connect(moveUpAct, SIGNAL(triggered()),
611 // image->displayProperties(), SIGNAL(moveUpOne()));
612 
613 // connect(moveToBottomAct, SIGNAL(triggered()),
614 // image->displayProperties(), SIGNAL(moveToBottom()));
615 
616 // connect(moveDownAct, SIGNAL(triggered()),
617 // image->displayProperties(), SIGNAL(moveDownOne()));
618 // }
619 // actions.append(moveToTopAct);
620 // actions.append(moveUpAct);
621 // actions.append(moveToBottomAct);
622 // actions.append(moveDownAct);
623 // }
624 
625 // actions.append(NULL);
626 
627 // if (size() == 1 && allSupport(ImageDisplayProperties::Zooming)) {
628 // QAction *zoomFit = new QAction(tr("Zoom Fit"), this);
629 // connect(zoomFit, SIGNAL(triggered()),
630 // first()->displayProperties(), SIGNAL(zoomFit()));
631 // actions.append(zoomFit);
632 // }
633 // }
634 
635 // return actions;
636 // }
637 
638 
645 // bool TargetBodyList::allSupport(ImageDisplayProperties::Property prop) {
646 // if (isEmpty())
647 // return false;
648 
649 // foreach (Image *image, *this) {
650 // if (!image->displayProperties()->supports(prop))
651 // return false;
652 // }
653 
654 // return true;
655 // }
656 
657 
664  void TargetBodyList::setName(QString newName) {
665  m_name = newName;
666  }
667 
668 
675  void TargetBodyList::setPath(QString newPath) {
676  m_path = newPath;
677  }
678 
679 
685  QString TargetBodyList::name() const {
686  return m_name;
687  }
688 
689 
697  QString TargetBodyList::path() const {
698  return m_path;
699  }
700 
701 
705 // void TargetBodyList::deleteFromDisk(Project *project) {
706 // foreach (TargetBodyQsp targetBody, *this) {
707 // targetBody->deleteFromDisk();
708 // }
709 
710 // if (!m_path.isEmpty()) {
711 // QFile::remove(project->imageDataRoot() + "/" + m_path + "/targets.xml");
712 
713 // QDir dir;
714 // dir.rmdir(project->imageDataRoot() + "/" + m_path);
715 // }
716 // }
717 
718 
740  void TargetBodyList::save(QXmlStreamWriter &stream, const Project *project,
741  FileName newProjectRoot) const {
742 // stream.writeStartElement("TargetBodyList");
743 // stream.writeAttribute("name", m_name);
744 // stream.writeAttribute("path", m_path);
745 
746 // FileName settingsFileName(
747 // Project::targetBodyRoot(newProjectRoot.toString()) + "/" + m_path + "/targets.xml");
748 
749 // if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
750 // throw IException(IException::Io,
751 // QString("Failed to create directory [%1]")
752 // .arg(settingsFileName.path()),
753 // _FILEINFO_);
754 // }
755 
756 // QFile TargetBodyListContentsFile(settingsFileName.toString());
757 
758 // if (!TargetBodyListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
759 // throw IException(IException::Io,
760 // QString("Unable to save target body information for [%1] because [%2] could not be opened"
761 // " for writing")
762 // .arg(m_name).arg(settingsFileName.original()),
763 // _FILEINFO_);
764 // }
765 
766 // QXmlStreamWriter targetBodyDetailsWriter(&TargetBodyListContentsFile);
767 // targetBodyDetailsWriter.setAutoFormatting(true);
768 // targetBodyDetailsWriter.writeStartDocument();
769 
770 // int countWidth = QString("%1L").arg(count()).size() - 1;
771 // QChar paddingChar('0');
772 
773 // QLabel *progressLabel = new QLabel;
774 
775 // QProgressDialog progressDialog;
776 // progressDialog.setLabel(progressLabel);
777 // progressDialog.setRange(-1, count());
778 // progressDialog.setValue(-1);
779 
780 // targetBodyDetailsWriter.writeStartElement("targets");
781 // // Mapped is way faster than hundreds/thousands of run() calls... so use mapped for performance
782 // QFuture<void *> future = QtConcurrent::mapped(*this,
783 // CopyTargetBodyDataFunctor(project, newProjectRoot));
784 
785 // for (int i = 0; i < count(); i++) {
786 // int newProgressValue = progressDialog.value() + 1;
787 // progressLabel->setText(
788 // tr("Saving Target Body Information for [%1] - %L2/%L3 done")
789 // .arg(m_name)
790 // .arg(newProgressValue, countWidth, 10, paddingChar)
791 // .arg(count()));
792 // progressDialog.setValue(newProgressValue);
793 // future.resultAt(i);
794 // }
795 
796 // progressLabel->setText(tr("Finalizing..."));
797 // progressDialog.setRange(0, 0);
798 // progressDialog.setValue(0);
799 
800 // foreach (TargetBodyQsp targetBody, *this) {
801 // targetBody->save(targetBodyDetailsWriter, project, newProjectRoot);
802 // }
803 
804 // targetBodyDetailsWriter.writeEndElement();
805 
806 // targetBodyDetailsWriter.writeEndDocument();
807 
808 // stream.writeEndElement();
809  }
810 
811 
812 // TargetBodyList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const Project *project,
813 // FileName newProjectRoot) {
814 // m_project = project;
815 // m_newProjectRoot = newProjectRoot;
816 // }
817 
818 
819 // TargetBodyList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(
820 // const CopyTargetBodyDataFunctor &other) {
821 // m_project = other.m_project;
822 // m_newProjectRoot = other.m_newProjectRoot;
823 // }
824 
825 
826 // TargetBodyList::CopyTargetBodyDataFunctor::~CopyTargetBodyDataFunctor() {
827 // }
828 
829 
830 // void *TargetBodyList::CopyTargetBodyDataFunctor::operator()(TargetBodyQsp const &targetToCopy) {
831 // targetToCopy->copyToNewProjectRoot(m_project, m_newProjectRoot);
832 // return NULL;
833 // }
834 
835 
836 // TargetBodyList::CopyTargetBodyDataFunctor &TargetBodyList::CopyTargetBodyDataFunctor::operator=(
837 // const CopyTargetBodyDataFunctor &rhs) {
838 // m_project = rhs.m_project;
839 // m_newProjectRoot = rhs.m_newProjectRoot;
840 // return *this;
841 // }
842 
843 
848 // QStringList TargetBodyList::saveAndToggleShowLabel() {
849 // QStringList results;
850 
851 // if (!isEmpty()) {
852 // ImageDisplayProperties *firstDisplayProps = first()->displayProperties();
853 // bool newValue = !firstDisplayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
854 
855 // foreach (Image *image, *this) {
856 // ImageDisplayProperties *displayProps = image->displayProperties();
857 
858 // bool value = displayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
859 // results.append(value? "shown" : "hidden");
860 
861 // image->displayProperties()->setShowLabel(newValue);
862 // }
863 // }
864 
865 // return results;
866 // }
867 
868 
878  m_project = project;
879  }
880 
881 
893  bool TargetBodyList::XmlHandler::startElement(const QString &namespaceURI,
894  const QString &localName,
895  const QString &qName,
896  const QXmlAttributes &atts) {
897  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
898  if (localName == "TargetBodyList") {
899  QString name = atts.value("name");
900  QString path = atts.value("path");
901 
902  if (!name.isEmpty()) {
903  m_TargetBodyList->setName(name);
904  }
905 
906  if (!path.isEmpty()) {
907  m_TargetBodyList->setPath(path);
908  }
909  }
910  else if (localName == "target") {
911 // m_TargetBodyList->append(TargetBodyQsp(new TargetBody(m_project->targetBodyRoot()
912 // + "/" + m_TargetBodyList->path(),
913 // reader())));
914  }
915  }
916 
917  return true;
918  }
919 
920 
934  bool TargetBodyList::XmlHandler::endElement(const QString &namespaceURI,
935  const QString &localName,
936  const QString &qName) {
937  if (localName == "TargetBodyList") {
938  XmlHandler handler(m_TargetBodyList, m_project);
939 
941  reader.pushContentHandler(&handler);
942  reader.setErrorHandler(&handler);
943 
944  QString TargetBodyListXmlPath = m_project->targetBodyRoot() + "/" +
945  m_TargetBodyList->path() + "/targets.xml";
946  QFile file(TargetBodyListXmlPath);
947 
948  if (!file.open(QFile::ReadOnly)) {
950  QString("Unable to open [%1] with read access")
951  .arg(TargetBodyListXmlPath),
952  _FILEINFO_);
953  }
954 
955  QXmlInputSource xmlInputSource(&file);
956  if (!reader.parse(xmlInputSource))
958  tr("Failed to open target body list XML [%1]").arg(TargetBodyListXmlPath),
959  _FILEINFO_);
960  }
961 
962  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
963  }
964 }
TargetBodyList * m_TargetBodyList
The TargetBodyList to read into/save from.
QString m_name
This functor is used for copying the TargetBody objects between two projects quickly.
The main project for ipce.
Definition: Project.h:289
Project * m_project
The project that contains the TargetBodies.
bool removeOne(TargetBodyQsp const &value)
Removes the first occurrence of a TargetBody from the list.
File name manipulation and expansion.
Definition: FileName.h:116
TargetBodyQsp takeAt(int i)
Removes and returns the TargetBody at a specific index.
TargetBodyList & operator<<(const QList< TargetBodyQsp > &other)
Appends another TargetBodyList to the list.
TargetBodyQsp takeFirst()
Removes and returns the first TargetBody in the list.
List for holding TargetBodies.
void removeLast()
Removes the last TargetBody from the list.
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:171
QString path() const
Get the path to these target body objects in the list (relative to project root). ...
QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint)
Display an Angle for a debugging statement.
Definition: Angle.cpp:383
void removeFirst()
Removes the first TargetBody from the list.
~TargetBodyList()
Create an target body list from a list of target body file names.
XmlReader for working with TargetBody XML files.
QString m_path
This stores the directory name that contains the TargetBody objects in this list. ...
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
int removeAll(TargetBodyQsp const &value)
Removes all occurrences of a TargetBody and returns the number removed.
void removeAt(int i)
Removes the TargetBody at a specific index.
void push_front(TargetBodyQsp const &value)
Insertes a TargetBody at the front of the list.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
XmlHandler(TargetBodyList *TargetBodyList, Project *project)
Change the visibility of the display name.
void append(TargetBodyQsp const &value)
Appends a TargetBody to the list.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
void insert(int i, TargetBodyQsp const &value)
Inserts a TargetBody at a specific index.
void setPath(QString newPath)
Set the relative path (from the project root) to this target body list&#39;s folder.
iterator erase(iterator pos)
Erases the TargetBody associated with an iterator.
void swap(QList< TargetBodyQsp > &other)
Swaps the list with another TargetBodyList.
TargetBodyList & operator+=(const QList< TargetBodyQsp > &other)
Appends another TargetBodyList to the list.
void push_back(TargetBodyQsp const &value)
Appends a TargetBody to the end of the list.
QString name() const
Get the human-readable name of this target body list.
TargetBodyQsp takeLast()
Removes and returns the last TargetBody in the list.
TargetBodyList & operator=(const QList< TargetBodyQsp > &rhs)
Assignment operator for a QList of TargetBodyQsp.
Isis exception class.
Definition: IException.h:107
void clear()
clears the list.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
TargetBodyList(QString name, QString path, QObject *parent=NULL)
Create an target body list from an target body list name and path (does not read TargetBody objects)...
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
void setName(QString newName)
Gets a list of pre-connected actions that have to do with display, such as color, alpha...
Manage a stack of content handlers for reading XML files.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Delete all of the contained TargetBody objects from disk (see TargetBody::deleteFromDisk()) ...
void prepend(TargetBodyQsp const &value)
Inserts a TargetBody at the front of the list.