Isis 3 Programmer Reference
GuiCameraList.cpp
Go to the documentation of this file.
1
23#include "GuiCameraList.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 "GuiCamera.h"
38#include "IException.h"
39#include "IString.h"
40#include "Project.h"
41#include "XmlStackedHandlerReader.h"
42
43namespace Isis {
52 GuiCameraList::GuiCameraList(QString name, QString path, QObject *parent) : QObject(parent) {
53 m_name = name;
54 m_path = path;
55 }
56
57
64 }
65
66
73 GuiCameraList::GuiCameraList(QList<GuiCameraQsp> guiCameras, QObject *parent) : QObject(parent) {
74 append(guiCameras);
75 }
76
77
86 QObject *parent) : QObject(parent) {
87 xmlReader->pushContentHandler(new XmlHandler(this, project));
88 }
89
90
97 QList<GuiCameraQsp>(src) {
98 m_name = src.m_name;
99 m_path = src.m_path;
100 }
101
102
107// GuiCameraList::GuiCameraList(QStringList &fileNames) {
108// foreach (QString fileName, fileNames) {
109// try {
110// GuiCameraQsp guiCamera = GuiCameraQsp(new GuiCamera(fileName);
111// append(guiCamera);
112// }
113// catch (IException &) {
114// }
115// }
116// }
117
118
124
125
135 emit countChanged(count());
136 }
137
138
146 void GuiCameraList::append(const QList<GuiCameraQsp> &value) {
148 emit countChanged(count());
149 }
150
151
158 bool countChanging = count();
160 if (countChanging) {
161 emit countChanged(count());
162 }
163 }
164
165
177 iterator result = QList<GuiCameraQsp>::erase(pos);
178 emit countChanged(count());
179 return result;
180 }
181
182
196 iterator result = QList<GuiCameraQsp>::erase(begin, end);
197 emit countChanged(count());
198 return result;
199 }
200
201
210 void GuiCameraList::insert(int i, GuiCameraQsp const &value) {
212
213 emit countChanged(count());
214 }
215
216
229 iterator result = QList<GuiCameraQsp>::insert(before, value);
230 emit countChanged(count());
231 return result;
232 }
233
234
244 emit countChanged(count());
245 }
246
247
258 emit countChanged(count());
259 }
260
261
272 emit countChanged(count());
273 }
274
275
287 int result = QList<GuiCameraQsp>::removeAll(value);
288
289 if (result != 0) {
290 emit countChanged(count());
291 }
292
293 return result;
294 }
295
296
306 emit countChanged(count());
307 }
308
309
319
320
330
331
343 bool result = QList<GuiCameraQsp>::removeOne(value);
344
345 if (result) {
346 emit countChanged(count());
347 }
348
349 return result;
350 }
351
352
360 void GuiCameraList::swap(QList<GuiCameraQsp> &other) {
362
363 if (count() != other.count()) {
364 emit countChanged(count());
365 }
366 }
367
368
380 emit countChanged(count());
381 return result;
382 }
383
384
394 emit countChanged(count());
395 return result;
396 }
397
398
408 emit countChanged(count());
409 return result;
410 }
411
412
422 GuiCameraList &GuiCameraList::operator+=(const QList<GuiCameraQsp> &other) {
424
425 if (other.count()) {
426 emit countChanged(count());
427 }
428
429 return *this;
430 }
431
432
444 emit countChanged(count());
445 return *this;
446 }
447
448
458 GuiCameraList &GuiCameraList::operator<<(const QList<GuiCameraQsp> &other) {
460
461 if (other.count()) {
462 emit countChanged(count());
463 }
464
465 return *this;
466 }
467
468
480 emit countChanged(count());
481 return *this;
482 }
483
484
495 GuiCameraList &GuiCameraList::operator=(const QList<GuiCameraQsp> &rhs) {
496 bool countChanging = (rhs.count() != count());
498
499 if (countChanging) {
500 emit countChanged(count());
501 }
502
503 return *this;
504 }
505
506
515 bool countChanging = (rhs.count() != count());
517
518 m_name = rhs.m_name;
519 m_path = rhs.m_path;
520
521 if (countChanging) {
522 emit countChanged(count());
523 }
524
525 return *this;
526 }
527
528
533// QList<QAction *> GuiCameraList::supportedActions(Project *project) {
534// QList<QAction *> actions;
535
536// // It turns out connect() statements cannot be templated, hence they aren't inside of
537// // createWorkOrder().
538// if (allSupport(ImageDisplayProperties::Color)) {
539// QAction *alphaAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ChangeTransparency);
540// if (!project) {
541// connect(alphaAction, SIGNAL(triggered()),
542// this, SLOT(askAndUpdateAlpha()));
543// }
544// actions.append(alphaAction);
545
546// QAction *colorAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ChangeColor);
547// if (!project) {
548// connect(colorAction, SIGNAL(triggered()),
549// this, SLOT(askAndUpdateColor()));
550// }
551// actions.append(colorAction);
552
553
554// QAction *ranColorAction = createWorkOrder(project, GuiCameraListActionWorkOrder::RandomizeColor);
555// if (!project) {
556// connect(ranColorAction, SIGNAL(triggered()),
557// this, SLOT(showRandomColor()));
558// }
559// actions.append(ranColorAction);
560// }
561
562
563// if (allSupport(ImageDisplayProperties::ShowLabel)) {
564// QAction *labelVisibleAction = createWorkOrder(project,
565// GuiCameraListActionWorkOrder::ToggleShowLabel);
566// if (!project) {
567// connect(labelVisibleAction, SIGNAL(triggered()),
568// this, SLOT(saveAndToggleShowLabel()));
569// }
570// actions.append(labelVisibleAction);
571// }
572
573
574// if (allSupport(ImageDisplayProperties::ShowFill)) {
575// QAction *fillAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ToggleShowFilled);
576// if (!project) {
577// connect(fillAction, SIGNAL(triggered()),
578// this, SLOT(saveAndToggleShowFill()));
579// }
580// actions.append(fillAction);
581// }
582
583
584// if (allSupport(ImageDisplayProperties::ShowDNs)) {
585// QAction *cubeDataAction = createWorkOrder(project,
586// GuiCameraListActionWorkOrder::ToggleShowCubeData);
587// if (!project) {
588// connect(cubeDataAction, SIGNAL(triggered()),
589// this, SLOT(saveAndToggleShowDNs()));
590// }
591// actions.append(cubeDataAction);
592// }
593
594
595// if (allSupport(ImageDisplayProperties::ShowOutline)) {
596// QAction *outlineAction = createWorkOrder(project,
597// GuiCameraListActionWorkOrder::ToggleShowOutline);
598// if (!project) {
599// connect(outlineAction, SIGNAL(triggered()),
600// this, SLOT(saveAndToggleShowOutline()));
601// }
602// actions.append(outlineAction);
603// }
604
605// actions.append(NULL);
606
607// if (!project) {
608// if (allSupport(ImageDisplayProperties::ZOrdering)) {
609// QAction *moveToTopAct = new QAction(tr("Bring to Front"), this);
610// QAction *moveUpAct = new QAction(tr("Bring Forward"), this);
611// QAction *moveToBottomAct = new QAction(tr("Send to Back"), this);
612// QAction *moveDownAct = new QAction(tr("Send Backward"), this);
613
614// foreach (Image *image, *this) {
615// connect(moveToTopAct, SIGNAL(triggered()),
616// image->displayProperties(), SIGNAL(moveToTop()));
617
618// connect(moveUpAct, SIGNAL(triggered()),
619// image->displayProperties(), SIGNAL(moveUpOne()));
620
621// connect(moveToBottomAct, SIGNAL(triggered()),
622// image->displayProperties(), SIGNAL(moveToBottom()));
623
624// connect(moveDownAct, SIGNAL(triggered()),
625// image->displayProperties(), SIGNAL(moveDownOne()));
626// }
627// actions.append(moveToTopAct);
628// actions.append(moveUpAct);
629// actions.append(moveToBottomAct);
630// actions.append(moveDownAct);
631// }
632
633// actions.append(NULL);
634
635// if (size() == 1 && allSupport(ImageDisplayProperties::Zooming)) {
636// QAction *zoomFit = new QAction(tr("Zoom Fit"), this);
637// connect(zoomFit, SIGNAL(triggered()),
638// first()->displayProperties(), SIGNAL(zoomFit()));
639// actions.append(zoomFit);
640// }
641// }
642
643// return actions;
644// }
645
646
653// bool GuiCameraList::allSupport(ImageDisplayProperties::Property prop) {
654// if (isEmpty())
655// return false;
656
657// foreach (Image *image, *this) {
658// if (!image->displayProperties()->supports(prop))
659// return false;
660// }
661
662// return true;
663// }
664
665
672 void GuiCameraList::setName(QString newName) {
673 m_name = newName;
674 }
675
676
683 void GuiCameraList::setPath(QString newPath) {
684 m_path = newPath;
685 }
686
687
693 QString GuiCameraList::name() const {
694 return m_name;
695 }
696
697
704 QString GuiCameraList::path() const {
705 return m_path;
706 }
707
708
712// void GuiCameraList::deleteFromDisk(Project *project) {
713// foreach (GuiCameraQsp guiCamera, *this) {
714// guiCamera->deleteFromDisk();
715// }
716
717// if (!m_path.isEmpty()) {
718// QFile::remove(project->imageDataRoot() + "/" + m_path + "/guicameras.xml");
719
720// QDir dir;
721// dir.rmdir(project->imageDataRoot() + "/" + m_path);
722// }
723// }
724
725
744 void GuiCameraList::save(QXmlStreamWriter &stream, const Project *project,
745 FileName newProjectRoot) const {
746// stream.writeStartElement("GuiCameraList");
747// stream.writeAttribute("name", m_name);
748// stream.writeAttribute("path", m_path);
749
750// FileName settingsFileName(
751// Project::targetBodyRoot(newProjectRoot.toString()) + "/" + m_path + "/targets.xml");
752
753// if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
754// throw IException(IException::Io,
755// QString("Failed to create directory [%1]")
756// .arg(settingsFileName.path()),
757// _FILEINFO_);
758// }
759
760// QFile GuiCameraListContentsFile(settingsFileName.toString());
761
762// if (!GuiCameraListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
763// throw IException(IException::Io,
764// QString("Unable to save target body information for [%1] because [%2] could not be opened"
765// " for writing")
766// .arg(m_name).arg(settingsFileName.original()),
767// _FILEINFO_);
768// }
769
770// QXmlStreamWriter targetBodyDetailsWriter(&GuiCameraListContentsFile);
771// targetBodyDetailsWriter.setAutoFormatting(true);
772// targetBodyDetailsWriter.writeStartDocument();
773
774// int countWidth = QString("%1L").arg(count()).size() - 1;
775// QChar paddingChar('0');
776
777// QLabel *progressLabel = new QLabel;
778
779// QProgressDialog progressDialog;
780// progressDialog.setLabel(progressLabel);
781// progressDialog.setRange(-1, count());
782// progressDialog.setValue(-1);
783
784// targetBodyDetailsWriter.writeStartElement("targets");
785// // Mapped is way faster than hundreds/thousands of run() calls... so use mapped for performance
786// QFuture<void *> future = QtConcurrent::mapped(*this,
787// CopyTargetBodyDataFunctor(project, newProjectRoot));
788
789// for (int i = 0; i < count(); i++) {
790// int newProgressValue = progressDialog.value() + 1;
791// progressLabel->setText(
792// tr("Saving Target Body Information for [%1] - %L2/%L3 done")
793// .arg(m_name)
794// .arg(newProgressValue, countWidth, 10, paddingChar)
795// .arg(count()));
796// progressDialog.setValue(newProgressValue);
797// future.resultAt(i);
798// }
799
800// progressLabel->setText(tr("Finalizing..."));
801// progressDialog.setRange(0, 0);
802// progressDialog.setValue(0);
803
804// foreach (GuiCameraQsp targetBody, *this) {
805// targetBody->save(targetBodyDetailsWriter, project, newProjectRoot);
806// }
807
808// targetBodyDetailsWriter.writeEndElement();
809
810// targetBodyDetailsWriter.writeEndDocument();
811
812// stream.writeEndElement();
813 }
814
815
816// GuiCameraList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const Project *project,
817// FileName newProjectRoot) {
818// m_project = project;
819// m_newProjectRoot = newProjectRoot;
820// }
821
822
823// GuiCameraList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const CopyTargetBodyDataFunctor &other) {
824// m_project = other.m_project;
825// m_newProjectRoot = other.m_newProjectRoot;
826// }
827
828
829// GuiCameraList::CopyTargetBodyDataFunctor::~CopyTargetBodyDataFunctor() {
830// }
831
832
833// void *GuiCameraList::CopyTargetBodyDataFunctor::operator()(GuiCameraQsp const &targetToCopy) {
834// targetToCopy->copyToNewProjectRoot(m_project, m_newProjectRoot);
835// return NULL;
836// }
837
838
839// GuiCameraList::CopyTargetBodyDataFunctor &GuiCameraList::CopyTargetBodyDataFunctor::operator=(
840// const CopyTargetBodyDataFunctor &rhs) {
841// m_project = rhs.m_project;
842// m_newProjectRoot = rhs.m_newProjectRoot;
843// return *this;
844// }
845
846
851// QStringList GuiCameraList::saveAndToggleShowLabel() {
852// QStringList results;
853
854// if (!isEmpty()) {
855// ImageDisplayProperties *firstDisplayProps = first()->displayProperties();
856// bool newValue = !firstDisplayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
857
858// foreach (Image *image, *this) {
859// ImageDisplayProperties *displayProps = image->displayProperties();
860
861// bool value = displayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
862// results.append(value? "shown" : "hidden");
863
864// image->displayProperties()->setShowLabel(newValue);
865// }
866// }
867
868// return results;
869// }
870
871
880 m_GuiCameraList = GuiCameraList;
881 m_project = project;
882 }
883
884
896 bool GuiCameraList::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
897 const QString &qName, const QXmlAttributes &atts) {
898 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
899 if (localName == "GuiCameraList") {
900 QString name = atts.value("name");
901 QString path = atts.value("path");
902
903 if (!name.isEmpty()) {
904 m_GuiCameraList->setName(name);
905 }
906
907 if (!path.isEmpty()) {
908 m_GuiCameraList->setPath(path);
909 }
910 }
911 else if (localName == "target") {
912// m_GuiCameraList->append(GuiCameraQsp(new TargetBody(m_project->targetBodyRoot() + "/" + m_GuiCameraList->path(),
913// reader())));
914 }
915 }
916
917 return true;
918 }
919
920
934 bool GuiCameraList::XmlHandler::endElement(const QString &namespaceURI, const QString &localName,
935 const QString &qName) {
936 if (localName == "GuiCameraList") {
937 XmlHandler handler(m_GuiCameraList, m_project);
938
940 reader.pushContentHandler(&handler);
941 reader.setErrorHandler(&handler);
942
943 QString GuiCameraListXmlPath = m_project->targetBodyRoot() + "/" + m_GuiCameraList->path() +
944 "/targets.xml";
945 QFile file(GuiCameraListXmlPath);
946
947 if (!file.open(QFile::ReadOnly)) {
949 QString("Unable to open [%1] with read access")
950 .arg(GuiCameraListXmlPath),
951 _FILEINFO_);
952 }
953
954 QXmlInputSource xmlInputSource(&file);
955 if (!reader.parse(xmlInputSource))
957 tr("Failed to open target body list XML [%1]").arg(GuiCameraListXmlPath),
958 _FILEINFO_);
959 }
960
961 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
962 }
963}
File name manipulation and expansion.
Definition FileName.h:100
XmlHandler used to save to xml files.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
XmlHandler(GuiCameraList *GuiCameraList, Project *project)
Change the visibility of the display name.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
List of GuiCameras saved as QSharedPointers.
GuiCameraQsp takeFirst()
Removes and returns the first GuiCamera in the list.
void removeFirst()
Removes the first GuiCamera in the list.
void clear()
Clears the list.
void setName(QString newName)
Gets a list of pre-connected actions that have to do with display, such as color, alpha,...
QString m_name
This functor is used for copying the GuiCamera objects between two projects quickly.
GuiCameraList(QString name, QString path, QObject *parent=NULL)
Create an gui camera list from a gui camera list name and path (does not read GuiCamera objects).
QString name() const
Get the human-readable name of this gui cameray list.
void push_back(GuiCameraQsp const &value)
Inserts a GuiCamera at the end of the list.
void insert(int i, GuiCameraQsp const &value)
Inserts a GuiCamera into the list at a given index.
GuiCameraQsp takeLast()
Removes and returns the last GuiCamera in the list.
int removeAll(GuiCameraQsp const &value)
Removes all occurances of a GuiCamera from the list.
bool removeOne(GuiCameraQsp const &value)
Removes the first occurance of a GuiCamera from the list.
void countChanged(int newCount)
Emitted when the number of GuiCameras in the list changes.
GuiCameraQsp takeAt(int i)
Removes and returns the GuiCamera at a specific index.
void removeAt(int i)
Removes the GuiCamera at a specific index.
void removeLast()
Removes the last GuiCamera in the list.
void prepend(GuiCameraQsp const &value)
Inserts a GuiCamera at the beginning of the list.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Delete all of the contained GuiCamera objects from disk (see GuiCamera::deleteFromDisk())
void append(GuiCameraQsp const &value)
Appends a single GuiCamera to the list.
QString path() const
Get the path to these gui camera objects in the list (relative to project root).
iterator erase(iterator pos)
Removes the GuiCamera associated with an iterator.
void swap(QList< GuiCameraQsp > &other)
Swaps the list with another GuiCameraList.
~GuiCameraList()
Create a gui camera list from a list of gui camera file names.
void setPath(QString newPath)
Set the relative path (from the project root) to this gui camera list's folder.
GuiCameraList & operator<<(const QList< GuiCameraQsp > &other)
Appends another GuiVameraList to the list and returns a reference to this.
void push_front(GuiCameraQsp const &value)
Inserts a GuiCamera at the front of the list.
GuiCameraList & operator=(const QList< GuiCameraQsp > &rhs)
Assigns a list of GuiCameras to the list.
GuiCameraList & operator+=(const QList< GuiCameraQsp > &other)
Appends another GuiCameraList to the list and returns a reference to this.
QString m_path
This stores the directory name that contains the GuiCamera objects in this list.
Isis exception class.
Definition IException.h:91
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
The main project for ipce.
Definition Project.h:289
Manage a stack of content handlers for reading XML files.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16