|
Isis 3 Programmer Reference
|
9 #include "ControlList.h"
12 #include <QColorDialog>
17 #include <QInputDialog>
19 #include <QProgressDialog>
20 #include <QtConcurrentMap>
21 #include <QXmlStreamWriter>
25 #include "IException.h"
27 #include "XmlStackedHandlerReader.h"
95 foreach (QString fileName, fileNames) {
110 emit deletingList(
this);
123 emit countChanged(count());
136 emit countChanged(count());
146 bool countChanging = count();
149 emit countChanged(count());
165 emit countChanged(count());
182 emit countChanged(count());
198 emit countChanged(count());
214 emit countChanged(count());
228 emit countChanged(count());
242 emit countChanged(count());
256 emit countChanged(count());
273 emit countChanged(count());
289 emit countChanged(count());
300 emit countChanged(count());
311 emit countChanged(count());
328 emit countChanged(count());
345 if (count() != other.count()) {
346 emit countChanged(count());
362 emit countChanged(count());
376 emit countChanged(count());
390 emit countChanged(count());
408 emit countChanged(count());
426 emit countChanged(count());
444 emit countChanged(count());
462 emit countChanged(count());
477 bool countChanging = (rhs.count() != count());
481 emit countChanged(count());
498 bool countChanging = (rhs.count() != count());
505 emit countChanged(count());
563 foreach (
Control *control, *
this) {
568 QFile::remove(project->
cnetRoot() +
"/" +
m_path +
"/controlNetworks.xml");
601 stream.writeStartElement(
"controlList");
602 stream.writeAttribute(
"name",
m_name);
603 stream.writeAttribute(
"path",
m_path);
607 "/controlNetworks.xml");
609 if (!settingsFileName.
dir().mkpath(settingsFileName.
path())) {
611 QString(
"Failed to create directory [%1]")
612 .arg(settingsFileName.
path()),
616 QFile controlListContentsFile(settingsFileName.
toString());
618 if (!controlListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
620 QString(
"Unable to save control information for [%1] because [%2] could not be opened "
626 QXmlStreamWriter controlDetailsWriter(&controlListContentsFile);
627 controlDetailsWriter.setAutoFormatting(
true);
628 controlDetailsWriter.writeStartDocument();
630 int countWidth = QString(
"%1L").arg(count()).size() - 1;
631 QChar paddingChar(
'0');
633 QLabel *progressLabel =
new QLabel;
635 QProgressDialog progressDialog;
636 progressDialog.setLabel(progressLabel);
637 progressDialog.setRange(-1, count());
638 progressDialog.setValue(-1);
640 controlDetailsWriter.writeStartElement(
"controls");
644 QFuture<void *> future = QtConcurrent::mapped(*
this,
646 for (
int i = 0; i < count(); i++) {
647 int newProgressValue = progressDialog.value() + 1;
648 progressLabel->setText(
649 tr(
"Saving Control Information for [%1] - %L2/%L3 done")
651 .arg(newProgressValue, countWidth, 10, paddingChar)
653 progressDialog.setValue(newProgressValue);
657 progressLabel->setText(tr(
"Finalizing..."));
658 progressDialog.setRange(0, 0);
659 progressDialog.setValue(0);
662 foreach (
Control *control, *
this) {
663 control->
save(controlDetailsWriter, project, newProjectRoot);
666 controlDetailsWriter.writeEndElement();
668 controlDetailsWriter.writeEndDocument();
670 stream.writeEndElement();
739 m_controlList = controlList;
756 const QString &qName,
const QXmlAttributes &atts) {
757 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
758 if (localName ==
"controlList") {
759 QString
name = atts.value(
"name");
760 QString
path = atts.value(
"path");
762 if (!
name.isEmpty()) {
763 m_controlList->setName(
name);
766 if (!
path.isEmpty()) {
767 m_controlList->setPath(
path);
770 else if (localName ==
"controlNet") {
771 m_controlList->append(
new Control(m_project->cnetRoot() +
"/" +
772 m_controlList->path(), reader()));
794 const QString &qName) {
795 if (localName ==
"controlList") {
800 reader.setErrorHandler(&handler);
802 QString controlListXmlPath = m_project->cnetRoot() +
"/" + m_controlList->path() +
803 "/controlNetworks.xml";
804 QFile file(controlListXmlPath);
806 if (!file.open(QFile::ReadOnly)) {
808 QString(
"Unable to open [%1] with read access")
809 .arg(controlListXmlPath),
813 QXmlInputSource xmlInputSource(&file);
814 if (!reader.parse(xmlInputSource))
816 tr(
"Failed to open control list XML [%1]").arg(controlListXmlPath),
820 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
void setPath(QString newPath)
Set the relative path (from the project root) to this control list's folder.
ControlList & operator<<(const QList< Control * > &other)
Appends a list of other control pointers to this control list.
ControlList & operator=(const QList< Control * > &rhs)
Assigns another list of control pointers to this control list.
@ Io
A type of error that occurred when performing an actual I/O operation.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this control list into XML format for saving/restoring capabilities.
QString cnetRoot() const
Get where control networks ought to be stored inside the project.
void setName(QString newName)
Set the human-readable name of this control list.
void deleteFromDisk()
Delete the control net from disk.
const Project * m_project
Project to copy the control list to.
File name manipulation and expansion.
Maintains a list of Controls so that control nets can easily be copied from one Project to another,...
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
ControlList(QString name, QString path, QObject *parent=NULL)
Create an control list from a control list name and path (does not read Controls).
~ControlList()
Destructor.
iterator erase(iterator pos)
Erases a control pointer from the control list at the specified position.
static QString cnetRoot(QString projectRoot)
Appends the root directory name 'cnets' to the project.
This represents an ISIS control net in a project-based GUI interface.
void removeLast()
Removes the last control pointer from the control list.
QString m_name
Name of the ControlList.
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copies the files of the given Project to the given location.
void swap(QList< Control * > &other)
Swaps this control list's control pointers with the other list of control pointers.
Manage a stack of content handlers for reading XML files.
void push_front(Control *const &value)
Equivalent to prepend(value)
QString path() const
Get the path to these controls in the control list (relative to project root).
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Control object's member data to an XML stream.
The main project for ipce.
CopyControlDataFunctor & operator=(const CopyControlDataFunctor &rhs)
CopyControlDataFunctor assignment operator.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
XmlHandler(ControlList *controlList, Project *project)
Create an XML Handler (reader/writer) that can populate the ControlList class data.
~CopyControlDataFunctor()
CopyControlDataFunctor destructor.
bool removeOne(Control *const &value)
Removes the first occurence of the control pointer from the control list.
QString newProjectRoot() const
Get the top-level folder of the new project.
This functor is used for copying the control nets between two projects quickly.
ControlList & operator+=(const QList< Control * > &other)
Appends control pointers from the other list to this control list.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
QString projectRoot() const
Get the top-level folder of the project.
void removeAt(int i)
Removes the control pointer at the specified index.
Nested class used to write the ControlList object information to an XML file for the purposes of savi...
void clear()
Clears the control list.
Control * takeFirst()
Removes the first control pointer from the control list and returns it.
void prepend(Control *const &value)
Prepends a control pointer to the control list.
Control * takeAt(int i)
Remove the control pointer at the specified index and returns it.
int removeAll(Control *const &value)
Removes all occurences of the control pointer in the control list.
QString name() const
Get the human-readable name of this control list.
void append(Control *const &value)
Appends a control pointer to the control list.
void deleteFromDisk(Project *project)
Delete all of the contained Controls from disk.
void removeFirst()
Removes the first control pointer from the control list.
QString original() const
Returns the full file name including the file path.
CopyControlDataFunctor(const Project *project, FileName newProjectRoot)
CopyControlDataFunctor constructor.
void * operator()(Control *const &controlToCopy)
Copies the Control from one project to another.
FileName m_newProjectRoot
The filename of the destination project's root.
Control * takeLast()
Removes the last control pointer from the control list and returns it.
QString m_path
This stores the directory name that contains the controls in this control list.
void insert(int i, Control *const &value)
Inserts a control pointer at the specified position in the control list.
QString path() const
Returns the path of the file name.
void push_back(Control *const &value)
Equivalent to append(value)
This is free and unencumbered software released into the public domain.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.