23 #include "ImageList.h"
26 #include <QColorDialog>
31 #include <QInputDialog>
33 #include <QProgressDialog>
34 #include <QtConcurrentMap>
35 #include <QXmlStreamWriter>
42 #include "XmlStackedHandlerReader.h"
87 xmlReader->pushContentHandler(
new XmlHandler(
this, project));
109 foreach (QString fileName, fileNames) {
136 for (
int i = 0; i < count(); i++) {
137 result->
add((*
this)[i]->fileName());
152 emit countChanged(count());
165 emit countChanged(count());
175 bool countChanging = count();
178 emit countChanged(count());
194 emit countChanged(count());
213 emit countChanged(count());
229 emit countChanged(count());
245 emit countChanged(count());
259 emit countChanged(count());
273 emit countChanged(count());
287 emit countChanged(count());
304 emit countChanged(count());
320 emit countChanged(count());
331 emit countChanged(count());
342 emit countChanged(count());
359 emit countChanged(count());
376 if (count() != other.count()) {
377 emit countChanged(count());
393 emit countChanged(count());
407 emit countChanged(count());
421 emit countChanged(count());
440 emit countChanged(count());
459 emit countChanged(count());
474 ImageList &ImageList::operator<<(const QList<Image *> &other) {
478 emit countChanged(count());
497 emit countChanged(count());
512 bool countChanging = (rhs.count() != count());
516 emit countChanged(count());
531 bool countChanging = (rhs.count() != count());
538 emit countChanged(count());
565 connect(alphaAction, SIGNAL(triggered()),
568 actions.append(alphaAction);
572 connect(colorAction, SIGNAL(triggered()),
575 actions.append(colorAction);
580 connect(ranColorAction, SIGNAL(triggered()),
583 actions.append(ranColorAction);
591 connect(labelVisibleAction, SIGNAL(triggered()),
594 actions.append(labelVisibleAction);
601 connect(fillAction, SIGNAL(triggered()),
604 actions.append(fillAction);
612 connect(cubeDataAction, SIGNAL(triggered()),
615 actions.append(cubeDataAction);
623 connect(outlineAction, SIGNAL(triggered()),
626 actions.append(outlineAction);
629 actions.append(NULL);
638 foreach (
Image *image, *
this) {
639 connect(moveToTopAct, SIGNAL(triggered()),
642 connect(moveUpAct, SIGNAL(triggered()),
645 connect(moveToBottomAct, SIGNAL(triggered()),
648 connect(moveDownAct, SIGNAL(triggered()),
651 actions.append(moveToTopAct);
652 actions.append(moveUpAct);
653 actions.append(moveToBottomAct);
654 actions.append(moveDownAct);
657 actions.append(NULL);
661 connect(zoomFit, SIGNAL(triggered()),
662 first()->displayProperties(), SIGNAL(zoomFit()));
663 actions.append(zoomFit);
683 foreach (
Image *image, *
this) {
743 foreach (
Image *image, *
this) {
781 stream.writeStartElement(
"imageList");
782 stream.writeAttribute(
"name",
m_name);
783 stream.writeAttribute(
"path",
m_path);
788 if (!settingsFileName.dir().mkpath(settingsFileName.
path())) {
790 QString(
"Failed to create directory [%1]")
791 .arg(settingsFileName.
path()),
795 QFile imageListContentsFile(settingsFileName.toString());
797 if (!imageListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
799 QString(
"Unable to save image information for [%1] because [%2] could not be opened for "
801 .arg(
m_name).arg(settingsFileName.original()),
805 QXmlStreamWriter imageDetailsWriter(&imageListContentsFile);
806 imageDetailsWriter.setAutoFormatting(
true);
807 imageDetailsWriter.writeStartDocument();
809 int countWidth = QString(
"%1L").arg(count()).size() - 1;
810 QChar paddingChar(
'0');
812 QLabel *progressLabel =
new QLabel;
814 QProgressDialog progressDialog;
815 progressDialog.setLabel(progressLabel);
816 progressDialog.setRange(-1, count());
817 progressDialog.setValue(-1);
819 imageDetailsWriter.writeStartElement(
"images");
821 QFuture<void *> future = QtConcurrent::mapped(*
this,
824 for (
int i = 0; i < count(); i++) {
825 int newProgressValue = progressDialog.value() + 1;
826 progressLabel->setText(
827 tr(
"Saving Image Information for [%1] - %L2/%L3 done")
829 .arg(newProgressValue, countWidth, 10, paddingChar)
831 progressDialog.setValue(newProgressValue);
835 progressLabel->setText(tr(
"Finalizing..."));
836 progressDialog.setRange(0, 0);
837 progressDialog.setValue(0);
839 foreach (
Image *image, *
this) {
840 image->
save(imageDetailsWriter, project, newProjectRoot);
843 imageDetailsWriter.writeEndElement();
845 imageDetailsWriter.writeEndDocument();
847 stream.writeEndElement();
920 if (count() == alphaValues.count()) {
921 for (
int i = 0; i < count(); i++) {
924 color.setAlpha(alphaValues[i].
toInt());
941 if (count() == colorValues.count()) {
942 for (
int i = 0; i < count(); i++) {
943 QString colorData = colorValues[i].split(
" ")[column];
944 (*this)[i]->displayProperties()->setColor(Color::fromRGBAString(colorData));
961 if (count() == showLabelValues.count()) {
962 for (
int i = 0; i < count(); i++) {
981 if (count() == showFillValues.count()) {
982 for (
int i = 0; i < count(); i++) {
984 dispProps->
setShowFill(showFillValues[i] ==
"shown");
1000 if (count() == showDNsValues.count()) {
1001 for (
int i = 0; i < count(); i++) {
1003 dispProps->
setShowDNs(showDNsValues[i] ==
"shown");
1019 if (count() == showOutlineValues.count()) {
1020 for (
int i = 0; i < count(); i++) {
1042 bool result =
false;
1046 *alphaResult = QInputDialog::getInt(NULL,
"Transparency Value",
1047 "Set the cube's transparency\nValues are 0 (invisible) to 255 (solid)",
1049 0, 255, 1, &result);
1070 *colorResult = QColor();
1074 *colorResult = QColorDialog::getColor(
1076 "Cube Display Color",
1077 QColorDialog::ShowAlphaChannel);
1080 return colorResult->isValid();
1094 foreach (
Image *image, *
this) {
1097 QColor displayColor = displayProperties->
getValue(
1100 results.append(QString::number(displayColor.alpha()));
1102 displayColor.setAlpha(newAlpha);
1103 displayProperties->
setColor(displayColor);
1122 if (newColor.isValid()) {
1123 foreach (
Image *image, *
this) {
1126 QColor displayColor = displayProperties->
getValue(
1129 results.append(Color::toRGBAString(displayColor));
1131 displayProperties->
setColor(newColor);
1149 foreach (
Image *image, *
this) {
1154 QColor displayColor = displayProperties->
getValue(
1158 ranColor.setAlpha(displayColor.alpha());
1162 QString(
"%1 %2").arg(Color::toRGBAString(displayColor))
1163 .arg(Color::toRGBAString(ranColor)));
1165 displayProperties->
setColor(ranColor);
1201 foreach (
Image *image, *
this) {
1221 foreach (
Image *image, *
this) {
1225 results.append(value?
"shown" :
"hidden");
1249 foreach (
Image *image, *
this) {
1253 results.append(value?
"shown" :
"hidden");
1277 foreach (
Image *image, *
this) {
1281 results.append(value?
"shown" :
"hidden");
1305 foreach (
Image *image, *
this) {
1309 results.append(value?
"shown" :
"hidden");
1328 m_imageList = imageList;
1329 m_project = project;
1340 const QString &qName,
const QXmlAttributes &atts) {
1341 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
1342 if (localName ==
"imageList") {
1343 QString
name = atts.value(
"name");
1344 QString
path = atts.value(
"path");
1346 if (!name.isEmpty()) {
1347 m_imageList->setName(name);
1350 if (!path.isEmpty()) {
1351 m_imageList->setPath(path);
1354 else if (localName ==
"image") {
1355 m_imageList->append(
new Image(m_project->imageDataRoot() +
"/" + m_imageList->path(),
1374 const QString &qName) {
1375 if (localName ==
"imageList") {
1379 reader.pushContentHandler(&handler);
1380 reader.setErrorHandler(&handler);
1382 QString imageListXmlPath = m_project->imageDataRoot() +
"/" + m_imageList->path() +
1384 QFile file(imageListXmlPath);
1386 if (!file.open(QFile::ReadOnly)) {
1388 QString(
"Unable to open [%1] with read access")
1389 .arg(imageListXmlPath),
1393 QXmlInputSource xmlInputSource(&file);
1394 if (!reader.parse(xmlInputSource))
1396 tr(
"Failed to open image list XML [%1]").arg(imageListXmlPath),
1400 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
QVariant getValue(int property) const
Get a property's associated data.
bool supports(int property)
Support may come later, please make sure you are connected to the supportAdded signal.
Image * takeLast()
Removes and returns the last image.
QString path() const
Get the path to the images in the image list (relative to project root).
True if the cube should show a fill area if possible (bool)
QStringList saveAndToggleShowDNs()
Changes the visibility of the DNs of the first image in the image list and synchronizes the visibilit...
void push_back(Image *const &value)
Appends an image to the end of the image list.
CopyImageDataFunctor(const Project *project, FileName newProjectRoot)
Constructor for CopyImageDataFunctor.
Internalizes a list of images and allows for operations on the entire list.
ImageList & operator<<(const QList< Image * > &other)
Appends a list of images to the end of the image list.
The main project for cnetsuite.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
int removeAll(Image *const &value)
Removes all occurances of an image.
QStringList saveAndApplyRandomColor()
Sets the color values of every image to a random color.
void showRandomColor()
This applies a new semi-random color to every image's display property for every image in this image ...
This functor is used for copying the images between two projects quickly.
File name manipulation and expansion.
void deleteFromDisk()
Delete the image data from disk.
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
void deleteFromDisk(Project *project)
Delete all of the contained Images from disk.
Show or hide each image's fill area.
void applyShowLabel(QStringList showLabelValues)
Sets the visibility of the display names of the images in the image list based on a list of values...
QString name() const
Get the human-readable name of this image list.
QStringList saveAndToggleShowOutline()
Changes the visibility of the outline of the first image in the image list and synchronizes the visib...
int toInt(const QString &string)
Global function to convert from a string to an integer.
void applyColors(QStringList colorValues, int column=0)
Sets the colors values of the images based on a list of values.
SerialNumberList * serialNumberList()
Creates a SerialNumberList from the image list.
void setShowDNs(bool)
Change the visibility of DNs associated with this cube.
~CopyImageDataFunctor()
Destructor for CopyImageDataFunctor.
True if the cube should be outlined (bool)
bool removeOne(Image *const &value)
Removes the first occurance of an image.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
void removeAt(int i)
Removes the image at an index.
QString m_path
This stores the directory name that contains the images in this image list.
QAction * createWorkOrder(Project *project, ImageListActionWorkOrder::Action action)
Creates an ImageListActionWorkOrder and sets the image list as the data for the work order...
A type of error that occurred when performing an actual I/O operation.
QString m_name
This stores the image list's name.
CopyImageDataFunctor & operator=(const CopyImageDataFunctor &rhs)
Assignment operator for CopyImageDataFunctor.
True if the cube should show DN values if possible (bool)
bool askAlpha(int *alphaResult) const
Prompts the user for an alpha value.
True if the cube should show its display name (bool)
void prepend(Image *const &value)
Inserts an image at the beginning of the image list.
QDebug operator<<(QDebug dbg, const Isis::Angle &angleToPrint)
Display an Angle for a debugging statement.
void copyToNewProjectRoot(const Project *project, FileName newProjectRoot)
Copy the cub/ecub files associated with this image into the new project.
QList< QAction * > supportedActions(Project *project=NULL)
Gets a list of pre-connected actions that have to do with display.
ImageList & operator+=(const QList< Image * > &other)
Appends a list of images to the end of the image list.
Change the alpha values of the image list.
Set each image in the list to a random color.
This is the GUI communication mechanism for cubes.
void push_front(Image *const &value)
Prepends an image to the beginning of the image list.
void setShowLabel(bool)
Change the visibility of the display name associated with this cube.
const Project * m_project
This stores the name of the project that is going to be copied to.
#define _FILEINFO_
Macro for the filename and line number.
void swap(QList< Image * > &other)
Swaps the image list with another list of images.
void applyShowFill(QStringList showFillValues)
Sets the visibility of the fill areas of the images in the image list based on a list of values...
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this image list into XML format for saving/restoring capabilities.
void clear()
Clears the image list.
This represents a cube in a project-based GUI interface.
void setColor(QColor newColor)
Change the color associated with this cube.
void removeFirst()
Removes the image at the front of the image list.
void applyShowOutline(QStringList showOutlineValues)
Sets the visibility of the outlines of the images in the image list based on a list of values...
void setPath(QString newPath)
Set the relative path (from the project root) to this image list's folder.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
QStringList saveAndApplyAlpha(int newAlpha)
Sets the alpha value of every image in the image list to a specificed value.
Image * takeAt(int i)
Removes the image at an index and returns it.
void applyAlphas(QStringList alphaValues)
Sets the alpha values of the images based on a list of values.
void append(Image *const &value)
Appends an image to the image list.
Property
This is a list of properties and actions that are possible.
void setShowOutline(bool)
Change the visibility of the outline associated with this cube.
void askAndUpdateColor()
Prompt the user for a new color.
void insert(int i, Image *const &value)
Inserts an image into the image list at an index.
Show or hide each image's outline.
Data ignored. Tells if the cube supports the zoomFit action.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Image properties out to an XML file.
bool askNewColor(QColor *colorResult) const
Prompts the user for color values.
Data ignored. Tells if the cube supports the "move*" actions.
Image * takeFirst()
Removes and returns the first image.
XmlHandler(ImageList *imageList, Project *project)
Create an XML Handler (reader) that can populate the Image list class data.
Show or hide each image's DNs.
Change the color values of the image list.
void applyShowDNs(QStringList showDNsValues)
Sets the visibility of the DNs of the images in the image list based on a list of values...
iterator erase(iterator pos)
Erases a single image from the image list.
This class is used to read an images.xml file into an image list.
QStringList saveAndToggleShowLabel()
Changes the visibility of the display name of the first image in the image list and synchronizes the ...
FileName m_newProjectRoot
This stores the path to the root of the project that is going to be copied to.
bool allSupport(ImageDisplayProperties::Property prop)
Check if all images in the image list support a display property.
void askAndUpdateAlpha()
Prompt the user for a new alpha value.
The color of the cube, default randomized (QColor)
void removeLast()
Removes the image at the end of the image list.
ImageList(QString name, QString path, QObject *parent=NULL)
Creates an image list from an image list name and path (does not read Images).
static QString imageDataRoot(QString projectRoot)
Appends the root directory name 'images' to the project .
Serial Number list generator.
ImageList & operator=(const QList< Image * > &rhs)
Assigns another list of images to the image list.
void setName(QString newName)
Set the human-readable name of this image list.
QString path() const
Returns the path.
his enables stack-based XML parsing of XML files.
QStringList saveAndToggleShowFill()
Changes the visibility of the fill area of the first image in the image list and synchronizes the vis...
QString imageDataRoot() const
Accessor for the root directory of the image data.
void * operator()(Image *const &imageToCopy)
Copies the cub/ecub files for an image into m_project.
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon. ...
QStringList saveAndApplyColor(QColor newColor)
Sets the color values of every image to a specificed set of values.
Show or hide each image's display name.
void setShowFill(bool)
Change the visibility of the fill area associated with this cube.