23#include "ExportImagesWorkOrder.h"
28#include <QInputDialog>
29#include <QtConcurrentMap>
32#include "CubeAttribute.h"
36#include "IException.h"
42 ExportImagesWorkOrder::ExportImagesWorkOrder(Project *project) :
46 m_isSynchronous =
false;
49 QAction::setText(tr(
"Export I&mages..."));
53 ExportImagesWorkOrder::ExportImagesWorkOrder(
const ExportImagesWorkOrder &other) :
58 ExportImagesWorkOrder::~ExportImagesWorkOrder() {
63 ExportImagesWorkOrder *ExportImagesWorkOrder::clone()
const {
64 return new ExportImagesWorkOrder(*
this);
76 bool ExportImagesWorkOrder::isExecutable(
ImageList *images) {
78 return (!images->isEmpty());
91 bool ExportImagesWorkOrder::setupExecution() {
92 bool success = WorkOrder::setupExecution();
97 if (imageList()->isEmpty()) {
99 foreach (
ImageList *list, project()->images()) {
100 imageListNames.append(list->
name());
103 imageListNames.sort();
105 QString choice = QInputDialog::getItem(NULL, tr(
"Select Image List"),
106 tr(
"Please choose a list of images to export."), imageListNames, 0,
false, &success);
108 internalData.append(choice);
110 QUndoCommand::setText(tr(
"Export image list [%1]").arg(choice));
113 QUndoCommand::setText(tr(
"Export [%1] images").arg(imageList()->count()));
116 QString destination = QFileDialog::getExistingDirectory(NULL, tr(
"Export Images"),
".");
118 if (destination.isEmpty()) {
121 internalData.append(destination);
123 setInternalData(internalData);
134 void ExportImagesWorkOrder::execute() {
137 if (list->isEmpty()) {
138 list = project()->imageList(internalData()[0]);
142 QString destination = internalData().last();
145 QFuture<void *> future = QtConcurrent::mapped(*list, functor);
147 setProgressRange(0, list->count());
149 QThreadPool::globalInstance()->releaseThread();
150 for (
int i = 0; i < list->count(); i++) {
157 QThreadPool::globalInstance()->reserveThread();
160 m_warning = functor.errors().toString();
167 void ExportImagesWorkOrder::postExecution() {
168 if (!m_warning.isEmpty()) {
169 project()->warn(m_warning);
181 ExportImagesWorkOrder::ProjectImageExportFunctor::ProjectImageExportFunctor(
182 QString destination) : m_errors(new
IException()), m_numErrors(new int(0)) {
184 m_destination = destination;
196 m_numErrors(other.m_numErrors) {
198 m_destination = other.m_destination;
224 imageToExport->closeCube();
227 QMutexLocker locker(&m_errorsLock);
247 if (*m_numErrors != 0) {
250 tr(
"Failed to export [%1] images").arg(*m_numErrors),
Manipulate and parse attributes of output cube filenames.
This functor is meant for QtConcurrentMap.
IException errors() const
Get the accumulated error list from this functor's run.
~ProjectImageExportFunctor()
Destroys the functor.
void * operator()(Image *const &imageToExport)
Write the given image's cube into the destination folder (preserves the base name).
ProjectImageExportFunctor(QString destination)
Create an image export functor that will copy the image's cubes into the given destination directory.
File name manipulation and expansion.
QString baseName() const
Returns the name of the file without the path and without extensions.
@ Unknown
A type of error that cannot be classified as any of the other error types.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
This represents a cube in a project-based GUI interface.
Internalizes a list of images and allows for operations on the entire list.
QString name() const
Get the human-readable name of this image list.
This is free and unencumbered software released into the public domain.