23 #include "ControlList.h"
26 #include <QColorDialog>
31 #include <QInputDialog>
33 #include <QProgressDialog>
34 #include <QtConcurrentMap>
35 #include <QXmlStreamWriter>
41 #include "XmlStackedHandlerReader.h"
86 xmlReader->pushContentHandler(
new XmlHandler(
this, project));
109 foreach (QString fileName, fileNames) {
124 emit deletingList(
this);
137 emit countChanged(count());
150 emit countChanged(count());
160 bool countChanging = count();
163 emit countChanged(count());
179 emit countChanged(count());
196 emit countChanged(count());
212 emit countChanged(count());
228 emit countChanged(count());
242 emit countChanged(count());
256 emit countChanged(count());
270 emit countChanged(count());
287 emit countChanged(count());
303 emit countChanged(count());
314 emit countChanged(count());
325 emit countChanged(count());
342 emit countChanged(count());
359 if (count() != other.count()) {
360 emit countChanged(count());
376 emit countChanged(count());
390 emit countChanged(count());
404 emit countChanged(count());
422 emit countChanged(count());
440 emit countChanged(count());
454 ControlList &ControlList::operator<<(const QList<Control *> &other) {
458 emit countChanged(count());
476 emit countChanged(count());
491 bool countChanging = (rhs.count() != count());
495 emit countChanged(count());
512 bool countChanging = (rhs.count() != count());
519 emit countChanged(count());
577 foreach (
Control *control, *
this) {
582 QFile::remove(project->
cnetRoot() +
"/" +
m_path +
"/controlNetworks.xml");
615 stream.writeStartElement(
"controlList");
616 stream.writeAttribute(
"name",
m_name);
617 stream.writeAttribute(
"path",
m_path);
621 "/controlNetworks.xml");
623 if (!settingsFileName.dir().mkpath(settingsFileName.
path())) {
625 QString(
"Failed to create directory [%1]")
626 .arg(settingsFileName.
path()),
630 QFile controlListContentsFile(settingsFileName.toString());
632 if (!controlListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
634 QString(
"Unable to save control information for [%1] because [%2] could not be opened "
636 .arg(
m_name).arg(settingsFileName.original()),
640 QXmlStreamWriter controlDetailsWriter(&controlListContentsFile);
641 controlDetailsWriter.setAutoFormatting(
true);
642 controlDetailsWriter.writeStartDocument();
644 int countWidth = QString(
"%1L").arg(count()).size() - 1;
645 QChar paddingChar(
'0');
647 QLabel *progressLabel =
new QLabel;
649 QProgressDialog progressDialog;
650 progressDialog.setLabel(progressLabel);
651 progressDialog.setRange(-1, count());
652 progressDialog.setValue(-1);
654 controlDetailsWriter.writeStartElement(
"controls");
656 QFuture<void *> future = QtConcurrent::mapped(*
this,
658 for (
int i = 0; i < count(); i++) {
659 int newProgressValue = progressDialog.value() + 1;
660 progressLabel->setText(
661 tr(
"Saving Control Information for [%1] - %L2/%L3 done")
663 .arg(newProgressValue, countWidth, 10, paddingChar)
665 progressDialog.setValue(newProgressValue);
669 progressLabel->setText(tr(
"Finalizing..."));
670 progressDialog.setRange(0, 0);
671 progressDialog.setValue(0);
673 foreach (
Control *control, *
this) {
674 control->
save(controlDetailsWriter, project, newProjectRoot);
677 controlDetailsWriter.writeEndElement();
679 controlDetailsWriter.writeEndDocument();
681 stream.writeEndElement();
750 m_controlList = controlList;
767 const QString &qName,
const QXmlAttributes &atts) {
768 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
769 if (localName ==
"controlList") {
770 QString
name = atts.value(
"name");
771 QString
path = atts.value(
"path");
773 if (!name.isEmpty()) {
774 m_controlList->setName(name);
777 if (!path.isEmpty()) {
778 m_controlList->setPath(path);
781 else if (localName ==
"controlNet") {
782 m_controlList->append(
new Control(m_project->cnetRoot() +
"/" +
783 m_controlList->path(), reader()));
805 const QString &qName) {
806 if (localName ==
"controlList") {
810 reader.pushContentHandler(&handler);
811 reader.setErrorHandler(&handler);
813 QString controlListXmlPath = m_project->cnetRoot() +
"/" + m_controlList->path() +
814 "/controlNetworks.xml";
815 QFile file(controlListXmlPath);
817 if (!file.open(QFile::ReadOnly)) {
819 QString(
"Unable to open [%1] with read access")
820 .arg(controlListXmlPath),
824 QXmlInputSource xmlInputSource(&file);
825 if (!reader.parse(xmlInputSource))
827 tr(
"Failed to open control list XML [%1]").arg(controlListXmlPath),
831 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
This represents an ISIS control net in a project-based GUI interface.
FileName m_newProjectRoot
The filename of the destination project's root.
ControlList(QString name, QString path, QObject *parent=NULL)
Create an control list from a control list name and path (does not read Controls).
The main project for cnetsuite.
~ControlList()
Destructor.
iterator erase(iterator pos)
Erases a control pointer from the control list at the specified position.
void deleteFromDisk()
Delete the control net from disk.
void insert(int i, Control *const &value)
Inserts a control pointer at the specified position in the control list.
File name manipulation and expansion.
Maintains a list of Controls so that control nets can easily be copied from one Project to another...
void setName(QString newName)
Set the human-readable name of this control list.
void push_front(Control *const &value)
Equivalent to prepend(value)
ControlList & operator<<(const QList< Control * > &other)
Appends a list of other control pointers to this control list.
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copies the files of the given Project to the given location.
const Project * m_project
Project to copy the control list to.
void swap(QList< Control * > &other)
Swaps this control list's control pointers with the other list of control pointers.
A type of error that occurred when performing an actual I/O operation.
QString cnetRoot() const
Get where control networks ought to be stored inside the project.
static QString cnetRoot(QString projectRoot)
Appends the root directory name 'cnets' to the project.
~CopyControlDataFunctor()
CopyControlDataFunctor destructor.
CopyControlDataFunctor & operator=(const CopyControlDataFunctor &rhs)
CopyControlDataFunctor assignment operator.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Control object's member data to an XML stream.
bool removeOne(Control *const &value)
Removes the first occurence of the control pointer from the control list.
QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint)
Display an Angle for a debugging statement.
void removeLast()
Removes the last control pointer from the control list.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this control list into XML format for saving/restoring capabilities.
QString m_name
Name of the ControlList.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
#define _FILEINFO_
Macro for the filename and line number.
XmlHandler(ControlList *controlList, Project *project)
Create an XML Handler (reader/writer) that can populate the ControlList class data.
QString name() const
Get the human-readable name of this control list.
Nested class used to write the ControlList object information to an XML file for the purposes of savi...
Control * takeFirst()
Removes the first control pointer from the control list and returns it.
void clear()
Clears the control list.
ControlList & operator+=(const QList< Control * > &other)
Appends control pointers from the other list to this control list.
void append(Control *const &value)
Appends a control pointer to the control list.
void prepend(Control *const &value)
Prepends a control pointer to the control list.
CopyControlDataFunctor(const Project *project, FileName newProjectRoot)
CopyControlDataFunctor constructor.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
void push_back(Control *const &value)
Equivalent to append(value)
Control * takeLast()
Removes the last control pointer from the control list and returns it.
void setPath(QString newPath)
Set the relative path (from the project root) to this control list's folder.
QString m_path
This stores the directory name that contains the controls in this control list.
Control * takeAt(int i)
Remove the control pointer at the specified index and returns it.
void removeAt(int i)
Removes the control pointer at the specified index.
ControlList & operator=(const QList< Control * > &rhs)
Assigns another list of control pointers to this control list.
void deleteFromDisk(Project *project)
Delete all of the contained Controls from disk.
QString path() const
Returns the path.
his enables stack-based XML parsing of XML files.
void removeFirst()
Removes the first control pointer from the control list.
void * operator()(Control *const &controlToCopy)
Copies the Control from one project to another.
int removeAll(Control *const &value)
Removes all occurences of the control pointer in the control list.
This functor is used for copying the control nets between two projects quickly.
QString path() const
Get the path to these controls in the control list (relative to project root).