15#include <QInputDialog>
17#include <QProgressDialog>
18#include <QtConcurrentMap>
19#include <QXmlStreamWriter>
22#include "IException.h"
25#include "XmlStackedHandlerReader.h"
70 xmlReader->pushContentHandler(
new XmlHandler(
this, project));
92 foreach (QString fileName, fileNames) {
119 for (
int i = 0; i < count(); i++) {
120 result.
add((*
this)[i]->fileName());
135 emit countChanged(count());
148 emit countChanged(count());
158 bool countChanging = count();
161 emit countChanged(count());
177 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());
423 emit countChanged(count());
442 emit countChanged(count());
461 emit countChanged(count());
480 emit countChanged(count());
495 bool countChanging = (rhs.count() != count());
499 emit countChanged(count());
514 bool countChanging = (rhs.count() != count());
521 emit countChanged(count());
579 foreach (
Shape *shape, *
this) {
617 stream.writeStartElement(
"shapeList");
618 stream.writeAttribute(
"name",
m_name);
619 stream.writeAttribute(
"path",
m_path);
624 if (!settingsFileName.
dir().mkpath(settingsFileName.
path())) {
626 QString(
"Failed to create directory [%1]")
627 .arg(settingsFileName.
path()),
631 QFile shapeListContentsFile(settingsFileName.
toString());
633 if (!shapeListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
635 QString(
"Unable to save shape information for [%1] because [%2] could not be opened for "
641 QXmlStreamWriter shapeDetailsWriter(&shapeListContentsFile);
642 shapeDetailsWriter.setAutoFormatting(
true);
643 shapeDetailsWriter.writeStartDocument();
645 int countWidth = QString(
"%1L").arg(count()).size() - 1;
646 QChar paddingChar(
'0');
648 QLabel *progressLabel =
new QLabel;
650 QProgressDialog progressDialog;
651 progressDialog.setLabel(progressLabel);
652 progressDialog.setRange(-1, count());
653 progressDialog.setValue(-1);
655 shapeDetailsWriter.writeStartElement(
"shapes");
657 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 Shape 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);
675 foreach (
Shape *shape, *
this) {
676 shape->
save(shapeDetailsWriter, project, newProjectRoot);
679 shapeDetailsWriter.writeEndElement();
681 shapeDetailsWriter.writeEndDocument();
683 stream.writeEndElement();
706 m_project = other.m_project;
707 m_newProjectRoot = other.m_newProjectRoot;
727 shapeToCopy->copyToNewProjectRoot(m_project, m_newProjectRoot);
742 m_newProjectRoot = rhs.m_newProjectRoot;
756 m_shapeList = shapeList;
768 const QString &qName,
const QXmlAttributes &atts) {
769 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
770 if (localName ==
"shapeList") {
771 QString
name = atts.value(
"name");
772 QString
path = atts.value(
"path");
774 if (!
name.isEmpty()) {
775 m_shapeList->setName(
name);
778 if (!
path.isEmpty()) {
779 m_shapeList->setPath(
path);
782 else if (localName ==
"shape") {
783 m_shapeList->append(
new Shape(m_project->shapeDataRoot() +
"/" + m_shapeList->path(),
802 const QString &qName) {
803 if (localName ==
"shapeList") {
808 reader.setErrorHandler(&handler);
810 QString shapeListXmlPath = m_project->shapeDataRoot() +
"/" + m_shapeList->path() +
812 QFile file(shapeListXmlPath);
814 if (!file.open(QFile::ReadOnly)) {
816 QString(
"Unable to open [%1] with read access")
817 .arg(shapeListXmlPath),
821 QXmlInputSource xmlInputSource(&file);
822 if (!reader.parse(xmlInputSource))
824 tr(
"Failed to open shape list XML [%1]").arg(shapeListXmlPath),
828 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
QString original() const
Returns the full file name including the file path.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
@ Io
A type of error that occurred when performing an actual I/O operation.
The main project for ipce.
static QString shapeDataRoot(QString projectRoot)
Appends the root directory name 'shapes' to the project .
QString shapeDataRoot() const
Accessor for the root directory of the shape model data.
Serial Number list generator.
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
This represents a shape in a project-based GUI interface.
void deleteFromDisk()
Delete the shape data from disk.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
This functor is used for copying the shapes between two projects quickly.
CopyShapeDataFunctor(const Project *project, FileName newProjectRoot)
Constructor for CopyShapeDataFunctor.
CopyShapeDataFunctor & operator=(const CopyShapeDataFunctor &rhs)
Assignment operator for CopyShapeDataFunctor.
FileName m_newProjectRoot
This stores the path to the root of the project that is going to be copied to.
void * operator()(Shape *const &shapeToCopy)
Copies the cub/ecub files for an shape into m_project.
~CopyShapeDataFunctor()
Destructor for CopyShapeDataFunctor.
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.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
XmlHandler(ShapeList *shapeList, Project *project)
Create an XML Handler (reader) that can populate the Shape list class data.
Internalizes a list of shapes and allows for operations on the entire list.
void insert(int i, Shape *const &value)
Inserts an shape into the shape list at an index.
void append(Shape *const &value)
Appends an shape to the shape list.
void deleteFromDisk(Project *project)
Delete all of the contained Shapes from disk.
void removeAt(int i)
Removes the shape at an index.
void setName(QString newName)
Set the human-readable name of this shape list.
Shape * takeLast()
Removes and returns the last shape.
iterator erase(iterator pos)
Erases a single shape from the shape list.
SerialNumberList serialNumberList()
Creates a SerialNumberList from the shape list.
void swap(QList< Shape * > &other)
Swaps the shape list with another list of shapes.
QString m_name
This stores the shape list's name.
void clear()
Clears the shape list.
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.
void removeFirst()
Removes the shape at the front of the shape list.
void removeLast()
Removes the shape at the end of the shape list.
QString path() const
Get the path to the shapes in the shape list (relative to project root).
int removeAll(Shape *const &value)
Removes all occurances of an shape.
QString name() const
Get the human-readable name of this shape list.
void prepend(Shape *const &value)
Inserts an shape at the beginning of the shape list.
Shape * takeAt(int i)
Removes the shape at an index and returns it.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this shape list into XML format for saving/restoring capabilities.
ShapeList(QString name, QString path, QObject *parent=NULL)
Creates an shape list from an shape list name and path (does not read Shapes).
void push_front(Shape *const &value)
Prepends an shape to the beginning of the shape list.
ShapeList & operator<<(const QList< Shape * > &other)
Appends a list of shapes to the end of the shape list.
bool removeOne(Shape *const &value)
Removes the first occurance of an shape.
ShapeList & operator=(const QList< Shape * > &rhs)
Assigns another list of shapes to the shape list.
void setPath(QString newPath)
Set the relative path (from the project root) to this shape list's folder.
Shape * takeFirst()
Removes and returns the first shape.
ShapeList & operator+=(const QList< Shape * > &other)
Appends a list of shapes to the end of the shape list.
Manage a stack of content handlers for reading XML files.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.