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
42namespace Isis {
51 GuiCameraList::GuiCameraList(QString name, QString path, QObject *parent) : QObject(parent) {
52 m_name = name;
53 m_path = path;
54 }
55
56
63 }
64
65
72 GuiCameraList::GuiCameraList(QList<GuiCameraQsp> guiCameras, QObject *parent) : QObject(parent) {
73 append(guiCameras);
74 }
75
76
83 QList<GuiCameraQsp>(src) {
84 m_name = src.m_name;
85 m_path = src.m_path;
86 }
87
88
93// GuiCameraList::GuiCameraList(QStringList &fileNames) {
94// foreach (QString fileName, fileNames) {
95// try {
96// GuiCameraQsp guiCamera = GuiCameraQsp(new GuiCamera(fileName);
97// append(guiCamera);
98// }
99// catch (IException &) {
100// }
101// }
102// }
103
104
110
111
121 emit countChanged(count());
122 }
123
124
132 void GuiCameraList::append(const QList<GuiCameraQsp> &value) {
134 emit countChanged(count());
135 }
136
137
144 bool countChanging = count();
146 if (countChanging) {
147 emit countChanged(count());
148 }
149 }
150
151
163 iterator result = QList<GuiCameraQsp>::erase(pos);
164 emit countChanged(count());
165 return result;
166 }
167
168
182 iterator result = QList<GuiCameraQsp>::erase(begin, end);
183 emit countChanged(count());
184 return result;
185 }
186
187
196 void GuiCameraList::insert(int i, GuiCameraQsp const &value) {
198
199 emit countChanged(count());
200 }
201
202
215 iterator result = QList<GuiCameraQsp>::insert(before, value);
216 emit countChanged(count());
217 return result;
218 }
219
220
230 emit countChanged(count());
231 }
232
233
244 emit countChanged(count());
245 }
246
247
258 emit countChanged(count());
259 }
260
261
273 int result = QList<GuiCameraQsp>::removeAll(value);
274
275 if (result != 0) {
276 emit countChanged(count());
277 }
278
279 return result;
280 }
281
282
292 emit countChanged(count());
293 }
294
295
305
306
316
317
329 bool result = QList<GuiCameraQsp>::removeOne(value);
330
331 if (result) {
332 emit countChanged(count());
333 }
334
335 return result;
336 }
337
338
346 void GuiCameraList::swap(QList<GuiCameraQsp> &other) {
348
349 if (count() != other.count()) {
350 emit countChanged(count());
351 }
352 }
353
354
366 emit countChanged(count());
367 return result;
368 }
369
370
380 emit countChanged(count());
381 return result;
382 }
383
384
394 emit countChanged(count());
395 return result;
396 }
397
398
408 GuiCameraList &GuiCameraList::operator+=(const QList<GuiCameraQsp> &other) {
410
411 if (other.count()) {
412 emit countChanged(count());
413 }
414
415 return *this;
416 }
417
418
430 emit countChanged(count());
431 return *this;
432 }
433
434
444 GuiCameraList &GuiCameraList::operator<<(const QList<GuiCameraQsp> &other) {
446
447 if (other.count()) {
448 emit countChanged(count());
449 }
450
451 return *this;
452 }
453
454
466 emit countChanged(count());
467 return *this;
468 }
469
470
481 GuiCameraList &GuiCameraList::operator=(const QList<GuiCameraQsp> &rhs) {
482 bool countChanging = (rhs.count() != count());
484
485 if (countChanging) {
486 emit countChanged(count());
487 }
488
489 return *this;
490 }
491
492
501 bool countChanging = (rhs.count() != count());
503
504 m_name = rhs.m_name;
505 m_path = rhs.m_path;
506
507 if (countChanging) {
508 emit countChanged(count());
509 }
510
511 return *this;
512 }
513
514
519// QList<QAction *> GuiCameraList::supportedActions(Project *project) {
520// QList<QAction *> actions;
521
522// // It turns out connect() statements cannot be templated, hence they aren't inside of
523// // createWorkOrder().
524// if (allSupport(ImageDisplayProperties::Color)) {
525// QAction *alphaAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ChangeTransparency);
526// if (!project) {
527// connect(alphaAction, SIGNAL(triggered()),
528// this, SLOT(askAndUpdateAlpha()));
529// }
530// actions.append(alphaAction);
531
532// QAction *colorAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ChangeColor);
533// if (!project) {
534// connect(colorAction, SIGNAL(triggered()),
535// this, SLOT(askAndUpdateColor()));
536// }
537// actions.append(colorAction);
538
539
540// QAction *ranColorAction = createWorkOrder(project, GuiCameraListActionWorkOrder::RandomizeColor);
541// if (!project) {
542// connect(ranColorAction, SIGNAL(triggered()),
543// this, SLOT(showRandomColor()));
544// }
545// actions.append(ranColorAction);
546// }
547
548
549// if (allSupport(ImageDisplayProperties::ShowLabel)) {
550// QAction *labelVisibleAction = createWorkOrder(project,
551// GuiCameraListActionWorkOrder::ToggleShowLabel);
552// if (!project) {
553// connect(labelVisibleAction, SIGNAL(triggered()),
554// this, SLOT(saveAndToggleShowLabel()));
555// }
556// actions.append(labelVisibleAction);
557// }
558
559
560// if (allSupport(ImageDisplayProperties::ShowFill)) {
561// QAction *fillAction = createWorkOrder(project, GuiCameraListActionWorkOrder::ToggleShowFilled);
562// if (!project) {
563// connect(fillAction, SIGNAL(triggered()),
564// this, SLOT(saveAndToggleShowFill()));
565// }
566// actions.append(fillAction);
567// }
568
569
570// if (allSupport(ImageDisplayProperties::ShowDNs)) {
571// QAction *cubeDataAction = createWorkOrder(project,
572// GuiCameraListActionWorkOrder::ToggleShowCubeData);
573// if (!project) {
574// connect(cubeDataAction, SIGNAL(triggered()),
575// this, SLOT(saveAndToggleShowDNs()));
576// }
577// actions.append(cubeDataAction);
578// }
579
580
581// if (allSupport(ImageDisplayProperties::ShowOutline)) {
582// QAction *outlineAction = createWorkOrder(project,
583// GuiCameraListActionWorkOrder::ToggleShowOutline);
584// if (!project) {
585// connect(outlineAction, SIGNAL(triggered()),
586// this, SLOT(saveAndToggleShowOutline()));
587// }
588// actions.append(outlineAction);
589// }
590
591// actions.append(NULL);
592
593// if (!project) {
594// if (allSupport(ImageDisplayProperties::ZOrdering)) {
595// QAction *moveToTopAct = new QAction(tr("Bring to Front"), this);
596// QAction *moveUpAct = new QAction(tr("Bring Forward"), this);
597// QAction *moveToBottomAct = new QAction(tr("Send to Back"), this);
598// QAction *moveDownAct = new QAction(tr("Send Backward"), this);
599
600// foreach (Image *image, *this) {
601// connect(moveToTopAct, SIGNAL(triggered()),
602// image->displayProperties(), SIGNAL(moveToTop()));
603
604// connect(moveUpAct, SIGNAL(triggered()),
605// image->displayProperties(), SIGNAL(moveUpOne()));
606
607// connect(moveToBottomAct, SIGNAL(triggered()),
608// image->displayProperties(), SIGNAL(moveToBottom()));
609
610// connect(moveDownAct, SIGNAL(triggered()),
611// image->displayProperties(), SIGNAL(moveDownOne()));
612// }
613// actions.append(moveToTopAct);
614// actions.append(moveUpAct);
615// actions.append(moveToBottomAct);
616// actions.append(moveDownAct);
617// }
618
619// actions.append(NULL);
620
621// if (size() == 1 && allSupport(ImageDisplayProperties::Zooming)) {
622// QAction *zoomFit = new QAction(tr("Zoom Fit"), this);
623// connect(zoomFit, SIGNAL(triggered()),
624// first()->displayProperties(), SIGNAL(zoomFit()));
625// actions.append(zoomFit);
626// }
627// }
628
629// return actions;
630// }
631
632
639// bool GuiCameraList::allSupport(ImageDisplayProperties::Property prop) {
640// if (isEmpty())
641// return false;
642
643// foreach (Image *image, *this) {
644// if (!image->displayProperties()->supports(prop))
645// return false;
646// }
647
648// return true;
649// }
650
651
658 void GuiCameraList::setName(QString newName) {
659 m_name = newName;
660 }
661
662
669 void GuiCameraList::setPath(QString newPath) {
670 m_path = newPath;
671 }
672
673
679 QString GuiCameraList::name() const {
680 return m_name;
681 }
682
683
690 QString GuiCameraList::path() const {
691 return m_path;
692 }
693
694
698// void GuiCameraList::deleteFromDisk(Project *project) {
699// foreach (GuiCameraQsp guiCamera, *this) {
700// guiCamera->deleteFromDisk();
701// }
702
703// if (!m_path.isEmpty()) {
704// QFile::remove(project->imageDataRoot() + "/" + m_path + "/guicameras.xml");
705
706// QDir dir;
707// dir.rmdir(project->imageDataRoot() + "/" + m_path);
708// }
709// }
710
711
730 void GuiCameraList::save(QXmlStreamWriter &stream, const Project *project,
731 FileName newProjectRoot) const {
732// stream.writeStartElement("GuiCameraList");
733// stream.writeAttribute("name", m_name);
734// stream.writeAttribute("path", m_path);
735
736// FileName settingsFileName(
737// Project::targetBodyRoot(newProjectRoot.toString()) + "/" + m_path + "/targets.xml");
738
739// if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
740// throw IException(IException::Io,
741// QString("Failed to create directory [%1]")
742// .arg(settingsFileName.path()),
743// _FILEINFO_);
744// }
745
746// QFile GuiCameraListContentsFile(settingsFileName.toString());
747
748// if (!GuiCameraListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
749// throw IException(IException::Io,
750// QString("Unable to save target body information for [%1] because [%2] could not be opened"
751// " for writing")
752// .arg(m_name).arg(settingsFileName.original()),
753// _FILEINFO_);
754// }
755
756// QXmlStreamWriter targetBodyDetailsWriter(&GuiCameraListContentsFile);
757// targetBodyDetailsWriter.setAutoFormatting(true);
758// targetBodyDetailsWriter.writeStartDocument();
759
760// int countWidth = QString("%1L").arg(count()).size() - 1;
761// QChar paddingChar('0');
762
763// QLabel *progressLabel = new QLabel;
764
765// QProgressDialog progressDialog;
766// progressDialog.setLabel(progressLabel);
767// progressDialog.setRange(-1, count());
768// progressDialog.setValue(-1);
769
770// targetBodyDetailsWriter.writeStartElement("targets");
771// // Mapped is way faster than hundreds/thousands of run() calls... so use mapped for performance
772// QFuture<void *> future = QtConcurrent::mapped(*this,
773// CopyTargetBodyDataFunctor(project, newProjectRoot));
774
775// for (int i = 0; i < count(); i++) {
776// int newProgressValue = progressDialog.value() + 1;
777// progressLabel->setText(
778// tr("Saving Target Body Information for [%1] - %L2/%L3 done")
779// .arg(m_name)
780// .arg(newProgressValue, countWidth, 10, paddingChar)
781// .arg(count()));
782// progressDialog.setValue(newProgressValue);
783// future.resultAt(i);
784// }
785
786// progressLabel->setText(tr("Finalizing..."));
787// progressDialog.setRange(0, 0);
788// progressDialog.setValue(0);
789
790// foreach (GuiCameraQsp targetBody, *this) {
791// targetBody->save(targetBodyDetailsWriter, project, newProjectRoot);
792// }
793
794// targetBodyDetailsWriter.writeEndElement();
795
796// targetBodyDetailsWriter.writeEndDocument();
797
798// stream.writeEndElement();
799 }
800
801
802// GuiCameraList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const Project *project,
803// FileName newProjectRoot) {
804// m_project = project;
805// m_newProjectRoot = newProjectRoot;
806// }
807
808
809// GuiCameraList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const CopyTargetBodyDataFunctor &other) {
810// m_project = other.m_project;
811// m_newProjectRoot = other.m_newProjectRoot;
812// }
813
814
815// GuiCameraList::CopyTargetBodyDataFunctor::~CopyTargetBodyDataFunctor() {
816// }
817
818
819// void *GuiCameraList::CopyTargetBodyDataFunctor::operator()(GuiCameraQsp const &targetToCopy) {
820// targetToCopy->copyToNewProjectRoot(m_project, m_newProjectRoot);
821// return NULL;
822// }
823
824
825// GuiCameraList::CopyTargetBodyDataFunctor &GuiCameraList::CopyTargetBodyDataFunctor::operator=(
826// const CopyTargetBodyDataFunctor &rhs) {
827// m_project = rhs.m_project;
828// m_newProjectRoot = rhs.m_newProjectRoot;
829// return *this;
830// }
831
832
837// QStringList GuiCameraList::saveAndToggleShowLabel() {
838// QStringList results;
839
840// if (!isEmpty()) {
841// ImageDisplayProperties *firstDisplayProps = first()->displayProperties();
842// bool newValue = !firstDisplayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
843
844// foreach (Image *image, *this) {
845// ImageDisplayProperties *displayProps = image->displayProperties();
846
847// bool value = displayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
848// results.append(value? "shown" : "hidden");
849
850// image->displayProperties()->setShowLabel(newValue);
851// }
852// }
853
854// return results;
855// }
856}
File name manipulation and expansion.
Definition FileName.h:100
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.
The main project for ipce.
Definition Project.h:287
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