23 #include "ShapeList.h" 29 #include <QInputDialog> 31 #include <QProgressDialog> 32 #include <QtConcurrentMap> 33 #include <QXmlStreamWriter> 39 #include "XmlStackedHandlerReader.h" 106 foreach (QString fileName, fileNames) {
133 for (
int i = 0; i < count(); i++) {
134 result.
add((*
this)[i]->fileName());
149 emit countChanged(count());
162 emit countChanged(count());
172 bool countChanging = count();
175 emit countChanged(count());
191 emit countChanged(count());
210 emit countChanged(count());
226 emit countChanged(count());
242 emit countChanged(count());
256 emit countChanged(count());
270 emit countChanged(count());
284 emit countChanged(count());
301 emit countChanged(count());
317 emit countChanged(count());
328 emit countChanged(count());
339 emit countChanged(count());
356 emit countChanged(count());
373 if (count() != other.count()) {
374 emit countChanged(count());
390 emit countChanged(count());
404 emit countChanged(count());
418 emit countChanged(count());
437 emit countChanged(count());
456 emit countChanged(count());
471 ShapeList &ShapeList::operator<<(const QList<Shape *> &other) {
475 emit countChanged(count());
494 emit countChanged(count());
509 bool countChanging = (rhs.count() != count());
513 emit countChanged(count());
528 bool countChanging = (rhs.count() != count());
535 emit countChanged(count());
593 foreach (
Shape *shape, *
this) {
631 stream.writeStartElement(
"shapeList");
632 stream.writeAttribute(
"name",
m_name);
633 stream.writeAttribute(
"path",
m_path);
638 if (!settingsFileName.
dir().mkpath(settingsFileName.
path())) {
640 QString(
"Failed to create directory [%1]")
641 .arg(settingsFileName.
path()),
645 QFile shapeListContentsFile(settingsFileName.
toString());
647 if (!shapeListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
649 QString(
"Unable to save shape information for [%1] because [%2] could not be opened for " 655 QXmlStreamWriter shapeDetailsWriter(&shapeListContentsFile);
656 shapeDetailsWriter.setAutoFormatting(
true);
657 shapeDetailsWriter.writeStartDocument();
659 int countWidth = QString(
"%1L").arg(count()).size() - 1;
660 QChar paddingChar(
'0');
662 QLabel *progressLabel =
new QLabel;
664 QProgressDialog progressDialog;
665 progressDialog.setLabel(progressLabel);
666 progressDialog.setRange(-1, count());
667 progressDialog.setValue(-1);
669 shapeDetailsWriter.writeStartElement(
"shapes");
671 QFuture<void *> future = QtConcurrent::mapped(*
this,
674 for (
int i = 0; i < count(); i++) {
675 int newProgressValue = progressDialog.value() + 1;
676 progressLabel->setText(
677 tr(
"Saving Shape Information for [%1] - %L2/%L3 done")
679 .arg(newProgressValue, countWidth, 10, paddingChar)
681 progressDialog.setValue(newProgressValue);
685 progressLabel->setText(tr(
"Finalizing..."));
686 progressDialog.setRange(0, 0);
687 progressDialog.setValue(0);
689 foreach (
Shape *shape, *
this) {
690 shape->
save(shapeDetailsWriter, project, newProjectRoot);
693 shapeDetailsWriter.writeEndElement();
695 shapeDetailsWriter.writeEndDocument();
697 stream.writeEndElement();
770 m_shapeList = shapeList;
782 const QString &qName,
const QXmlAttributes &atts) {
783 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
784 if (localName ==
"shapeList") {
785 QString
name = atts.value(
"name");
786 QString
path = atts.value(
"path");
788 if (!
name.isEmpty()) {
789 m_shapeList->setName(
name);
792 if (!
path.isEmpty()) {
793 m_shapeList->setPath(
path);
796 else if (localName ==
"shape") {
797 m_shapeList->append(
new Shape(m_project->shapeDataRoot() +
"/" + m_shapeList->path(),
816 const QString &qName) {
817 if (localName ==
"shapeList") {
822 reader.setErrorHandler(&handler);
824 QString shapeListXmlPath = m_project->shapeDataRoot() +
"/" + m_shapeList->path() +
826 QFile file(shapeListXmlPath);
828 if (!file.open(QFile::ReadOnly)) {
830 QString(
"Unable to open [%1] with read access")
831 .arg(shapeListXmlPath),
835 QXmlInputSource xmlInputSource(&file);
836 if (!reader.parse(xmlInputSource))
838 tr(
"Failed to open shape list XML [%1]").arg(shapeListXmlPath),
842 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
ShapeList & operator+=(const QList< Shape *> &other)
Appends a list of shapes to the end of the shape list.
Internalizes a list of shapes and allows for operations on the entire list.
QString path() const
Returns the path of the file name.
QString path() const
Get the path to the shapes in the shape list (relative to project root).
The main project for ipce.
ShapeList & operator<<(const QList< Shape *> &other)
Appends a list of shapes to the end of the shape list.
File name manipulation and expansion.
void prepend(Shape *const &value)
Inserts an shape at the beginning of the shape list.
void deleteFromDisk(Project *project)
Delete all of the contained Shapes from disk.
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
static QString shapeDataRoot(QString projectRoot)
Appends the root directory name 'shapes' to the project .
void setPath(QString newPath)
Set the relative path (from the project root) to this shape list's folder.
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copy the cub/ecub files associated with this shape into the new project.
CopyShapeDataFunctor(const Project *project, FileName newProjectRoot)
Constructor for CopyShapeDataFunctor.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this shape list into XML format for saving/restoring capabilities.
A type of error that occurred when performing an actual I/O operation.
This functor is used for copying the shapes between two projects quickly.
const Project * m_project
This stores the name of the project that is going to be copied to.
This class is used to read an shapes.xml file into an shape list.
void setName(QString newName)
Set the human-readable name of this shape list.
void clear()
Clears the shape list.
FileName m_newProjectRoot
This stores the path to the root of the project that is going to be copied to.
QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint)
Display an Angle for a debugging statement.
void removeLast()
Removes the shape at the end of the shape list.
void removeFirst()
Removes the shape at the front of the shape list.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
ShapeList & operator=(const QList< Shape *> &rhs)
Assigns another list of shapes to the shape list.
void swap(QList< Shape *> &other)
Swaps the shape list with another list of shapes.
void removeAt(int i)
Removes the shape at an index.
QString shapeDataRoot() const
Accessor for the root directory of the shape model data.
#define _FILEINFO_
Macro for the filename and line number.
void append(Shape *const &value)
Appends an shape to the shape list.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
SerialNumberList serialNumberList()
Creates a SerialNumberList from the shape list.
QString original() const
Returns the full file name including the file path.
XmlHandler(ShapeList *shapeList, Project *project)
Create an XML Handler (reader) that can populate the Shape list class data.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
ShapeList(QString name, QString path, QObject *parent=NULL)
Creates an shape list from an shape list name and path (does not read Shapes).
QString m_path
This stores the directory name that contains the shapes in this shape list.
void push_back(Shape *const &value)
Appends an shape to the end of the shape list.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
void deleteFromDisk()
Delete the shape data from disk.
bool removeOne(Shape *const &value)
Removes the first occurance of an shape.
This represents a shape in a project-based GUI interface.
Shape * takeFirst()
Removes and returns the first shape.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
Shape * takeLast()
Removes and returns the last shape.
~CopyShapeDataFunctor()
Destructor for CopyShapeDataFunctor.
Namespace for ISIS/Bullet specific routines.
QString name() const
Get the human-readable name of this shape list.
void * operator()(Shape *const &shapeToCopy)
Copies the cub/ecub files for an shape into m_project.
Serial Number list generator.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
Manage a stack of content handlers for reading XML files.
void insert(int i, Shape *const &value)
Inserts an shape into the shape list at an index.
int removeAll(Shape *const &value)
Removes all occurances of an shape.
Shape * takeAt(int i)
Removes the shape at an index and returns it.
QString m_name
This stores the shape list's name.
void push_front(Shape *const &value)
Prepends an shape to the beginning of the shape list.
CopyShapeDataFunctor & operator=(const CopyShapeDataFunctor &rhs)
Assignment operator for CopyShapeDataFunctor.
iterator erase(iterator pos)
Erases a single shape from the shape list.