Isis 3 Programmer Reference
TargetBodyList.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "TargetBodyList.h"
10
11//#include <QAction>
12#include <QDebug>
13#include <QDir>
14#include <QFile>
15#include <QFuture>
16#include <QInputDialog>
17#include <QLabel>
18#include <QProgressDialog>
19#include <QtConcurrentMap>
20#include <QXmlStreamWriter>
21
22#include "FileName.h"
23#include "IException.h"
24#include "IString.h"
25#include "Project.h"
26#include "TargetBody.h"
27
28namespace Isis {
37 TargetBodyList::TargetBodyList(QString name, QString path, QObject *parent) : QObject(parent) {
38 m_name = name;
39 m_path = path;
40 }
41
42
50
51
58 TargetBodyList::TargetBodyList(QList<TargetBodyQsp> targetBodys, QObject *parent) : QObject(parent) {
59 append(targetBodys);
60 }
61
62
69 QList<TargetBodyQsp>(other) {
70 m_name = other.m_name;
71 m_path = other.m_path;
72 }
73
74
79// TargetBodyList::TargetBodyList(QStringList &fileNames) {
80// foreach (QString fileName, fileNames) {
81// try {
82// TargetBodyQsp targetBody = TargetBodyQsp(new TargetBody(fileName);
83// append(targetBody);
84// }
85// catch (IException &) {
86// }
87// }
88// }
89
90
96
97
107 emit countChanged(count());
108 }
109
110
118 void TargetBodyList::append(const QList<TargetBodyQsp> &value) {
120 emit countChanged(count());
121 }
122
123
130 bool countChanging = count();
132 if (countChanging) {
133 emit countChanged(count());
134 }
135 }
136
137
146 iterator result = QList<TargetBodyQsp>::erase(pos);
147 emit countChanged(count());
148 return result;
149 }
150
151
165 iterator result = QList<TargetBodyQsp>::erase(begin, end);
166 emit countChanged(count());
167 return result;
168 }
169
170
179 void TargetBodyList::insert(int i, TargetBodyQsp const &value) {
181
182 emit countChanged(count());
183 }
184
185
198 iterator result = QList<TargetBodyQsp>::insert(before, value);
199 emit countChanged(count());
200 return result;
201 }
202
203
213 emit countChanged(count());
214 }
215
216
226 emit countChanged(count());
227 }
228
229
239 emit countChanged(count());
240 }
241
242
253 int result = QList<TargetBodyQsp>::removeAll(value);
254
255 if (result != 0) {
256 emit countChanged(count());
257 }
258
259 return result;
260 }
261
262
272 emit countChanged(count());
273 }
274
275
283 emit countChanged(count());
284 }
285
286
294 emit countChanged(count());
295 }
296
297
308 bool result = QList<TargetBodyQsp>::removeOne(value);
309
310 if (result) {
311 emit countChanged(count());
312 }
313
314 return result;
315 }
316
317
325 void TargetBodyList::swap(QList<TargetBodyQsp> &other) {
327
328 if (count() != other.count()) {
329 emit countChanged(count());
330 }
331 }
332
333
345 emit countChanged(count());
346 return result;
347 }
348
349
359 emit countChanged(count());
360 return result;
361 }
362
363
373 emit countChanged(count());
374 return result;
375 }
376
377
387 TargetBodyList &TargetBodyList::operator+=(const QList<TargetBodyQsp> &other) {
389
390 if (other.count()) {
391 emit countChanged(count());
392 }
393
394 return *this;
395 }
396
397
409 emit countChanged(count());
410 return *this;
411 }
412
413
423 TargetBodyList &TargetBodyList::operator<<(const QList<TargetBodyQsp> &other) {
425
426 if (other.count()) {
427 emit countChanged(count());
428 }
429
430 return *this;
431 }
432
433
445 emit countChanged(count());
446 return *this;
447 }
448
449
459 TargetBodyList &TargetBodyList::operator=(const QList<TargetBodyQsp> &rhs) {
460 bool countChanging = (rhs.count() != count());
462
463 if (countChanging) {
464 emit countChanged(count());
465 }
466
467 return *this;
468 }
469
470
479 bool countChanging = (rhs.count() != count());
481
482 m_name = rhs.m_name;
483 m_path = rhs.m_path;
484
485 if (countChanging) {
486 emit countChanged(count());
487 }
488
489 return *this;
490 }
491
492
497// QList<QAction *> TargetBodyList::supportedActions(Project *project) {
498// QList<QAction *> actions;
499
500// // It turns out connect() statements cannot be templated, hence they aren't inside of
501// // createWorkOrder().
502// if (allSupport(ImageDisplayProperties::Color)) {
503// QAction *alphaAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ChangeTransparency);
504// if (!project) {
505// connect(alphaAction, SIGNAL(triggered()),
506// this, SLOT(askAndUpdateAlpha()));
507// }
508// actions.append(alphaAction);
509
510// QAction *colorAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ChangeColor);
511// if (!project) {
512// connect(colorAction, SIGNAL(triggered()),
513// this, SLOT(askAndUpdateColor()));
514// }
515// actions.append(colorAction);
516
517
518// QAction *ranColorAction = createWorkOrder(project, TargetBodyListActionWorkOrder::RandomizeColor);
519// if (!project) {
520// connect(ranColorAction, SIGNAL(triggered()),
521// this, SLOT(showRandomColor()));
522// }
523// actions.append(ranColorAction);
524// }
525
526
527// if (allSupport(ImageDisplayProperties::ShowLabel)) {
528// QAction *labelVisibleAction = createWorkOrder(project,
529// TargetBodyListActionWorkOrder::ToggleShowLabel);
530// if (!project) {
531// connect(labelVisibleAction, SIGNAL(triggered()),
532// this, SLOT(saveAndToggleShowLabel()));
533// }
534// actions.append(labelVisibleAction);
535// }
536
537
538// if (allSupport(ImageDisplayProperties::ShowFill)) {
539// QAction *fillAction = createWorkOrder(project, TargetBodyListActionWorkOrder::ToggleShowFilled);
540// if (!project) {
541// connect(fillAction, SIGNAL(triggered()),
542// this, SLOT(saveAndToggleShowFill()));
543// }
544// actions.append(fillAction);
545// }
546
547
548// if (allSupport(ImageDisplayProperties::ShowDNs)) {
549// QAction *cubeDataAction = createWorkOrder(project,
550// TargetBodyListActionWorkOrder::ToggleShowCubeData);
551// if (!project) {
552// connect(cubeDataAction, SIGNAL(triggered()),
553// this, SLOT(saveAndToggleShowDNs()));
554// }
555// actions.append(cubeDataAction);
556// }
557
558
559// if (allSupport(ImageDisplayProperties::ShowOutline)) {
560// QAction *outlineAction = createWorkOrder(project,
561// TargetBodyListActionWorkOrder::ToggleShowOutline);
562// if (!project) {
563// connect(outlineAction, SIGNAL(triggered()),
564// this, SLOT(saveAndToggleShowOutline()));
565// }
566// actions.append(outlineAction);
567// }
568
569// actions.append(NULL);
570
571// if (!project) {
572// if (allSupport(ImageDisplayProperties::ZOrdering)) {
573// QAction *moveToTopAct = new QAction(tr("Bring to Front"), this);
574// QAction *moveUpAct = new QAction(tr("Bring Forward"), this);
575// QAction *moveToBottomAct = new QAction(tr("Send to Back"), this);
576// QAction *moveDownAct = new QAction(tr("Send Backward"), this);
577
578// foreach (Image *image, *this) {
579// connect(moveToTopAct, SIGNAL(triggered()),
580// image->displayProperties(), SIGNAL(moveToTop()));
581
582// connect(moveUpAct, SIGNAL(triggered()),
583// image->displayProperties(), SIGNAL(moveUpOne()));
584
585// connect(moveToBottomAct, SIGNAL(triggered()),
586// image->displayProperties(), SIGNAL(moveToBottom()));
587
588// connect(moveDownAct, SIGNAL(triggered()),
589// image->displayProperties(), SIGNAL(moveDownOne()));
590// }
591// actions.append(moveToTopAct);
592// actions.append(moveUpAct);
593// actions.append(moveToBottomAct);
594// actions.append(moveDownAct);
595// }
596
597// actions.append(NULL);
598
599// if (size() == 1 && allSupport(ImageDisplayProperties::Zooming)) {
600// QAction *zoomFit = new QAction(tr("Zoom Fit"), this);
601// connect(zoomFit, SIGNAL(triggered()),
602// first()->displayProperties(), SIGNAL(zoomFit()));
603// actions.append(zoomFit);
604// }
605// }
606
607// return actions;
608// }
609
610
617// bool TargetBodyList::allSupport(ImageDisplayProperties::Property prop) {
618// if (isEmpty())
619// return false;
620
621// foreach (Image *image, *this) {
622// if (!image->displayProperties()->supports(prop))
623// return false;
624// }
625
626// return true;
627// }
628
629
636 void TargetBodyList::setName(QString newName) {
637 m_name = newName;
638 }
639
640
647 void TargetBodyList::setPath(QString newPath) {
648 m_path = newPath;
649 }
650
651
657 QString TargetBodyList::name() const {
658 return m_name;
659 }
660
661
669 QString TargetBodyList::path() const {
670 return m_path;
671 }
672
673
677// void TargetBodyList::deleteFromDisk(Project *project) {
678// foreach (TargetBodyQsp targetBody, *this) {
679// targetBody->deleteFromDisk();
680// }
681
682// if (!m_path.isEmpty()) {
683// QFile::remove(project->imageDataRoot() + "/" + m_path + "/targets.xml");
684
685// QDir dir;
686// dir.rmdir(project->imageDataRoot() + "/" + m_path);
687// }
688// }
689
690
712 void TargetBodyList::save(QXmlStreamWriter &stream, const Project *project,
713 FileName newProjectRoot) const {
714// stream.writeStartElement("TargetBodyList");
715// stream.writeAttribute("name", m_name);
716// stream.writeAttribute("path", m_path);
717
718// FileName settingsFileName(
719// Project::targetBodyRoot(newProjectRoot.toString()) + "/" + m_path + "/targets.xml");
720
721// if (!settingsFileName.dir().mkpath(settingsFileName.path())) {
722// throw IException(IException::Io,
723// QString("Failed to create directory [%1]")
724// .arg(settingsFileName.path()),
725// _FILEINFO_);
726// }
727
728// QFile TargetBodyListContentsFile(settingsFileName.toString());
729
730// if (!TargetBodyListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
731// throw IException(IException::Io,
732// QString("Unable to save target body information for [%1] because [%2] could not be opened"
733// " for writing")
734// .arg(m_name).arg(settingsFileName.original()),
735// _FILEINFO_);
736// }
737
738// QXmlStreamWriter targetBodyDetailsWriter(&TargetBodyListContentsFile);
739// targetBodyDetailsWriter.setAutoFormatting(true);
740// targetBodyDetailsWriter.writeStartDocument();
741
742// int countWidth = QString("%1L").arg(count()).size() - 1;
743// QChar paddingChar('0');
744
745// QLabel *progressLabel = new QLabel;
746
747// QProgressDialog progressDialog;
748// progressDialog.setLabel(progressLabel);
749// progressDialog.setRange(-1, count());
750// progressDialog.setValue(-1);
751
752// targetBodyDetailsWriter.writeStartElement("targets");
753// // Mapped is way faster than hundreds/thousands of run() calls... so use mapped for performance
754// QFuture<void *> future = QtConcurrent::mapped(*this,
755// CopyTargetBodyDataFunctor(project, newProjectRoot));
756
757// for (int i = 0; i < count(); i++) {
758// int newProgressValue = progressDialog.value() + 1;
759// progressLabel->setText(
760// tr("Saving Target Body Information for [%1] - %L2/%L3 done")
761// .arg(m_name)
762// .arg(newProgressValue, countWidth, 10, paddingChar)
763// .arg(count()));
764// progressDialog.setValue(newProgressValue);
765// future.resultAt(i);
766// }
767
768// progressLabel->setText(tr("Finalizing..."));
769// progressDialog.setRange(0, 0);
770// progressDialog.setValue(0);
771
772// foreach (TargetBodyQsp targetBody, *this) {
773// targetBody->save(targetBodyDetailsWriter, project, newProjectRoot);
774// }
775
776// targetBodyDetailsWriter.writeEndElement();
777
778// targetBodyDetailsWriter.writeEndDocument();
779
780// stream.writeEndElement();
781 }
782
783
784// TargetBodyList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(const Project *project,
785// FileName newProjectRoot) {
786// m_project = project;
787// m_newProjectRoot = newProjectRoot;
788// }
789
790
791// TargetBodyList::CopyTargetBodyDataFunctor::CopyTargetBodyDataFunctor(
792// const CopyTargetBodyDataFunctor &other) {
793// m_project = other.m_project;
794// m_newProjectRoot = other.m_newProjectRoot;
795// }
796
797
798// TargetBodyList::CopyTargetBodyDataFunctor::~CopyTargetBodyDataFunctor() {
799// }
800
801
802// void *TargetBodyList::CopyTargetBodyDataFunctor::operator()(TargetBodyQsp const &targetToCopy) {
803// targetToCopy->copyToNewProjectRoot(m_project, m_newProjectRoot);
804// return NULL;
805// }
806
807
808// TargetBodyList::CopyTargetBodyDataFunctor &TargetBodyList::CopyTargetBodyDataFunctor::operator=(
809// const CopyTargetBodyDataFunctor &rhs) {
810// m_project = rhs.m_project;
811// m_newProjectRoot = rhs.m_newProjectRoot;
812// return *this;
813// }
814
815
820// QStringList TargetBodyList::saveAndToggleShowLabel() {
821// QStringList results;
822
823// if (!isEmpty()) {
824// ImageDisplayProperties *firstDisplayProps = first()->displayProperties();
825// bool newValue = !firstDisplayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
826
827// foreach (Image *image, *this) {
828// ImageDisplayProperties *displayProps = image->displayProperties();
829
830// bool value = displayProps->getValue(ImageDisplayProperties::ShowLabel).toBool();
831// results.append(value? "shown" : "hidden");
832
833// image->displayProperties()->setShowLabel(newValue);
834// }
835// }
836
837// return results;
838// }
839
840}
File name manipulation and expansion.
Definition FileName.h:100
The main project for ipce.
Definition Project.h:287
List for holding TargetBodies.
TargetBodyList & operator<<(const QList< TargetBodyQsp > &other)
Appends another TargetBodyList to the list.
QString m_name
This functor is used for copying the TargetBody objects between two projects quickly.
TargetBodyList & operator=(const QList< TargetBodyQsp > &rhs)
Assignment operator for a QList of TargetBodyQsp.
void setPath(QString newPath)
Set the relative path (from the project root) to this target body list's folder.
void removeLast()
Removes the last TargetBody from the list.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Delete all of the contained TargetBody objects from disk (see TargetBody::deleteFromDisk())
iterator erase(iterator pos)
Erases the TargetBody associated with an iterator.
QString path() const
Get the path to these target body objects in the list (relative to project root).
void swap(QList< TargetBodyQsp > &other)
Swaps the list with another TargetBodyList.
TargetBodyQsp takeLast()
Removes and returns the last TargetBody in the list.
void insert(int i, TargetBodyQsp const &value)
Inserts a TargetBody at a specific index.
void append(TargetBodyQsp const &value)
Appends a TargetBody to the list.
bool removeOne(TargetBodyQsp const &value)
Removes the first occurrence of a TargetBody from the list.
void push_front(TargetBodyQsp const &value)
Insertes a TargetBody at the front of the list.
TargetBodyList & operator+=(const QList< TargetBodyQsp > &other)
Appends another TargetBodyList to the list.
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).
QString name() const
Get the human-readable name of this target body list.
void removeFirst()
Removes the first TargetBody from the list.
int removeAll(TargetBodyQsp const &value)
Removes all occurrences of a TargetBody and returns the number removed.
void prepend(TargetBodyQsp const &value)
Inserts a TargetBody at the front of the list.
void push_back(TargetBodyQsp const &value)
Appends a TargetBody to the end of the list.
TargetBodyQsp takeFirst()
Removes and returns the first TargetBody in the list.
QString m_path
This stores the directory name that contains the TargetBody objects in this list.
~TargetBodyList()
Create an target body list from a list of target body file names.
void setName(QString newName)
Gets a list of pre-connected actions that have to do with display, such as color, alpha,...
void removeAt(int i)
Removes the TargetBody at a specific index.
void clear()
clears the list.
TargetBodyQsp takeAt(int i)
Removes and returns the TargetBody at a specific index.
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