23 #include "ControlList.h" 26 #include <QColorDialog> 31 #include <QInputDialog> 33 #include <QProgressDialog> 34 #include <QtConcurrentMap> 35 #include <QXmlStreamWriter> 41 #include "XmlStackedHandlerReader.h" 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 " 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");
658 QFuture<void *> future = QtConcurrent::mapped(*
this,
660 for (
int i = 0; i < count(); i++) {
661 int newProgressValue = progressDialog.value() + 1;
662 progressLabel->setText(
663 tr(
"Saving Control Information for [%1] - %L2/%L3 done")
665 .arg(newProgressValue, countWidth, 10, paddingChar)
667 progressDialog.setValue(newProgressValue);
671 progressLabel->setText(tr(
"Finalizing..."));
672 progressDialog.setRange(0, 0);
673 progressDialog.setValue(0);
676 foreach (
Control *control, *
this) {
677 control->
save(controlDetailsWriter, project, newProjectRoot);
680 controlDetailsWriter.writeEndElement();
682 controlDetailsWriter.writeEndDocument();
684 stream.writeEndElement();
753 m_controlList = controlList;
770 const QString &qName,
const QXmlAttributes &atts) {
771 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
772 if (localName ==
"controlList") {
773 QString
name = atts.value(
"name");
774 QString
path = atts.value(
"path");
776 if (!
name.isEmpty()) {
777 m_controlList->setName(
name);
780 if (!
path.isEmpty()) {
781 m_controlList->setPath(
path);
784 else if (localName ==
"controlNet") {
785 m_controlList->append(
new Control(m_project->cnetRoot() +
"/" +
786 m_controlList->path(), reader()));
808 const QString &qName) {
809 if (localName ==
"controlList") {
814 reader.setErrorHandler(&handler);
816 QString controlListXmlPath = m_project->cnetRoot() +
"/" + m_controlList->path() +
817 "/controlNetworks.xml";
818 QFile file(controlListXmlPath);
820 if (!file.open(QFile::ReadOnly)) {
822 QString(
"Unable to open [%1] with read access")
823 .arg(controlListXmlPath),
827 QXmlInputSource xmlInputSource(&file);
828 if (!reader.parse(xmlInputSource))
830 tr(
"Failed to open control list XML [%1]").arg(controlListXmlPath),
834 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
This represents an ISIS control net in a project-based GUI interface.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this control list into XML format for saving/restoring capabilities.
QString path() const
Returns the path of the file name.
FileName m_newProjectRoot
The filename of the destination project's root.
QString cnetRoot() const
Get where control networks ought to be stored inside the project.
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 ipce.
~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)
QString path() const
Get the path to these controls in the control list (relative to project root).
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.
A type of error that occurred when performing an actual I/O operation.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Control object's member data to an XML stream.
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.
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.
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.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
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.
QString original() const
Returns the full file name including the file path.
ControlList & operator+=(const QList< Control *> &other)
Appends control pointers from the other list to this control list.
QString projectRoot() const
Get the top-level folder of the project.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
QString newProjectRoot() const
Get the top-level folder of the new project.
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.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
QString name() const
Get the human-readable name of this control list.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
ControlList & operator<<(const QList< Control *> &other)
Appends a list of other control pointers to this control list.
void push_back(Control *const &value)
Equivalent to append(value)
void swap(QList< Control *> &other)
Swaps this control list's control pointers with the other list of control pointers.
Namespace for ISIS/Bullet specific routines.
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.
ControlList & operator=(const QList< Control *> &rhs)
Assigns another list of control pointers to 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.
void deleteFromDisk(Project *project)
Delete all of the contained Controls from disk.
Manage a stack of content handlers for reading 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.