diff --git a/qelectrotech.pro b/qelectrotech.pro index f08b04886..9ddd59b87 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -79,7 +79,8 @@ INCLUDEPATH += sources \ sources/editor/graphicspart \ sources/undocommand \ sources/diagramevent \ - sources/ElementsCollection + sources/ElementsCollection \ + sources/ElementsCollection/ui # Fichiers sources @@ -91,7 +92,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) $$files(sources/editor/* $$files(sources/dvevent/*.h) \ $$files(sources/undocommand/*.h) \ $$files(sources/diagramevent/*.h) \ - $$files(sources/ElementsCollection/*.h) + $$files(sources/ElementsCollection/*.h) \ + $$files(sources/ElementsCollection/ui/*.h) SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/titleblock/*.cpp) $$files(sources/richtext/*.cpp) $$files(sources/ui/*.cpp) $$files(sources/qetgraphicsitem/*.cpp) $$files(sources/factory/*.cpp) \ $$files(sources/properties/*.cpp) \ @@ -101,7 +103,8 @@ SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/ $$files(sources/dvevent/*.cpp) \ $$files(sources/undocommand/*.cpp) \ $$files(sources/diagramevent/*.cpp) \ - $$files(sources/ElementsCollection/*.cpp) + $$files(sources/ElementsCollection/*.cpp) \ + $$files(sources/ElementsCollection/ui/*.cpp) # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc @@ -118,7 +121,8 @@ QT += xml svg network sql widgets printsupport # UI DESIGNER FILES AND GENERATION SOURCES FILES FORMS += $$files(sources/richtext/*.ui) \ $$files(sources/ui/*.ui) \ - $$files(sources/editor/ui/*.ui) + $$files(sources/editor/ui/*.ui) \ + $$files(sources/ElementsCollection/ui/*.ui) UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/ElementsCollection/elementcollectionhandler.cpp b/sources/ElementsCollection/elementcollectionhandler.cpp new file mode 100644 index 000000000..a2c67f3ff --- /dev/null +++ b/sources/ElementsCollection/elementcollectionhandler.cpp @@ -0,0 +1,156 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "elementcollectionhandler.h" +#include "renamedialog.h" +#include +#include + +ECHStrategy::ECHStrategy(ElementLocation &source, ElementLocation &destination) : + m_source(source), + m_destination (destination) +{} + +ECHStrategy::~ECHStrategy() {} + +/******************************************************/ + +ECHSFileToFile::ECHSFileToFile(ElementLocation &source, ElementLocation &destination) : + ECHStrategy(source, destination) +{} + +ElementLocation ECHSFileToFile::copy() +{ + //Check if the destination already have an item with the same name of the item to copy + ElementLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName()); + QString rename; + if (location.exist()) + { + RenameDialog rd(location.fileSystemPath()); + if (rd.exec() == QDialog::Accepted) + { + if (rd.selectedAction() == QET::Erase) + { + if (location.isDirectory()) + { + QDir dir(location.fileSystemPath()); + dir.removeRecursively(); + } + else + { + QFile file(location.fileSystemPath()); + file.remove(); + } + } + else if (rd.selectedAction() == QET::Rename) + { + rename = rd.newName(); + } + } + else + return ElementLocation(); + } + + if (m_source.isElement()) + return copyElement(m_source, m_destination, rename); + else + return copyDirectory(m_source, m_destination, rename); +} + +ElementLocation ECHSFileToFile::copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename) +{ + QDir source_dir(source.fileSystemPath()); + QDir destination_dir(destination.fileSystemPath()); + + if (!source_dir.exists() || !destination_dir.exists()) return ElementLocation(); + + QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename; + + //Create a new dir + if (destination_dir.mkdir(new_dir_name)) + { + //The new created directory + QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name); + + //Copy the qet_directory file + QFile::copy(source_dir.canonicalPath() + "/qet_directory", created_dir.canonicalPath() + "/qet_directory"); + + //Copy all dirs found in source_dir to destination_dir + ElementLocation created_location(created_dir.canonicalPath()); + foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) + { + ElementLocation sub_source(source.fileSystemPath() + "/" + str); + copyDirectory(sub_source, created_location); + } + + //Copy all elements found in source_dir to destination_dir + source_dir.setNameFilters(QStringList() << "*.elmt"); + foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) + { + ElementLocation sub_source(source.fileSystemPath() + "/" + str); + copyElement(sub_source, created_location); + } + + return created_location; + } + + return ElementLocation(); +} + +ElementLocation ECHSFileToFile::copyElement(ElementLocation &source, ElementLocation &destination, QString rename) +{ + QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename; + bool rb = QFile::copy(source.fileSystemPath(), destination.fileSystemPath() + "/" + new_elmt_name); + if (rb) + return ElementLocation (destination.fileSystemPath() + "/" + new_elmt_name); + else + return ElementLocation(); +} + +/******************************************************/ + +/** + * @brief ElementCollectionHandler::ElementCollectionHandler + * @param widget + */ +ElementCollectionHandler::ElementCollectionHandler() {} + +ElementCollectionHandler::~ElementCollectionHandler() +{ + if (m_strategy) delete m_strategy; +} + +/** + * @brief ElementCollectionHandler::copy + * Copy the content of collection represented by source to the collection represented by destination. + * Destination must be a directory, else the copy do nothing and return a null ElementLocation + * if destination have an item with the same name of source, a dialog ask to user what to do. + * @param source + * @param destination + * @return + */ +ElementLocation ElementCollectionHandler::copy(ElementLocation &source, ElementLocation &destination) +{ + if (!source.exist() || !destination.exist() || destination.isElement()) return ElementLocation(); + + if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination); + + if (m_strategy) + return m_strategy->copy(); + else + return ElementLocation(); +} diff --git a/sources/ElementsCollection/elementcollectionhandler.h b/sources/ElementsCollection/elementcollectionhandler.h new file mode 100644 index 000000000..e3cc75046 --- /dev/null +++ b/sources/ElementsCollection/elementcollectionhandler.h @@ -0,0 +1,64 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef ELEMENTCOLLECTIONHANDLER_H +#define ELEMENTCOLLECTIONHANDLER_H + +#include "elementlocation.h" + +class QWidget; + +class ECHStrategy +{ + public: + ECHStrategy(ElementLocation &source, ElementLocation &destination); + virtual ~ECHStrategy(); + virtual ElementLocation copy() =0; + + ElementLocation m_source, m_destination; +}; + +class ECHSFileToFile : public ECHStrategy +{ + public: + ECHSFileToFile (ElementLocation &source, ElementLocation &destination); + + ElementLocation copy(); + + private: + ElementLocation copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename = QString()); + ElementLocation copyElement(ElementLocation &source, ElementLocation &destination, QString rename = QString()); +}; + +/** + * @brief The ElementCollectionHandler class + * Provide several method to copy element or directory from a collection + * to another collection. + */ +class ElementCollectionHandler +{ + public: + ElementCollectionHandler(); + ~ElementCollectionHandler(); + + ElementLocation copy(ElementLocation &source, ElementLocation &destination); + + private: + ECHStrategy *m_strategy = nullptr; +}; + +#endif // ELEMENTCOLLECTIONHANDLER_H diff --git a/sources/ElementsCollection/elementcollectionitem.cpp b/sources/ElementsCollection/elementcollectionitem.cpp index f3ea5fa54..84bdad4b3 100644 --- a/sources/ElementsCollection/elementcollectionitem.cpp +++ b/sources/ElementsCollection/elementcollectionitem.cpp @@ -84,7 +84,7 @@ bool ElementCollectionItem::insertChild(int row, ElementCollectionItem *item) * @return The child at @row of this item. * If there isn't child at @row, return default ElementCollectionItem */ -ElementCollectionItem *ElementCollectionItem::child(int row) { +ElementCollectionItem *ElementCollectionItem::child(int row) const { return m_child_items.value(row); } diff --git a/sources/ElementsCollection/elementcollectionitem.h b/sources/ElementsCollection/elementcollectionitem.h index 4f8c2bb5d..599cd6bdc 100644 --- a/sources/ElementsCollection/elementcollectionitem.h +++ b/sources/ElementsCollection/elementcollectionitem.h @@ -43,7 +43,7 @@ class ElementCollectionItem void appendChild (ElementCollectionItem *item); bool removeChild (int row, int count); bool insertChild (int row, ElementCollectionItem *item); - ElementCollectionItem *child(int row); + ElementCollectionItem *child(int row) const; ElementCollectionItem *childWithCollectionName(QString name) const; ElementCollectionItem *lastItemForPath(const QString &path, QString &newt_item); int rowForInsertItem(const QString &collection_name); diff --git a/sources/ElementsCollection/elementlocation.cpp b/sources/ElementsCollection/elementlocation.cpp index 7d18cb24e..da577c528 100644 --- a/sources/ElementsCollection/elementlocation.cpp +++ b/sources/ElementsCollection/elementlocation.cpp @@ -59,6 +59,17 @@ ElementLocation::ElementLocation(const QMimeData *data) setPath(data->text()); } +ElementLocation &ElementLocation::operator=(const ElementLocation &other) +{ + m_collection_path = other.m_collection_path; + m_file_system_path = other.m_file_system_path; + m_project = other.m_project; + m_xml = other.m_xml; + m_uuid = other.m_uuid; + m_icon = other.m_icon; + return(*this); +} + ElementLocation::~ElementLocation() {} @@ -115,12 +126,12 @@ bool ElementLocation::setPath(QString path) if (path.startsWith("common://")) { tmp_path.remove("common://"); - p = QETApp::commonElementsDir() + tmp_path; + p = QETApp::commonElementsDirN() + "/" + tmp_path; } else { tmp_path.remove("custom://"); - p = QETApp::customElementsDir() + tmp_path; + p = QETApp::customElementsDirN() + "/" + tmp_path; } //This is an element @@ -153,47 +164,37 @@ bool ElementLocation::setPath(QString path) { if(path.endsWith(".elmt")) { - QFile file(path); - if (file.exists()) + m_file_system_path = path; + if (path.startsWith(QETApp::commonElementsDirN())) { - m_file_system_path = path; - if (path.startsWith(QETApp::commonElementsDir())) - { - path.remove(QETApp::commonElementsDir()); - path.prepend("common://"); - m_collection_path = path; - } - else if (path.startsWith(QETApp::customElementsDir())) - { - path.remove(QETApp::customElementsDir()); - path.prepend("custom://"); - m_collection_path = path; - } - return true; + path.remove(QETApp::commonElementsDirN() + "/"); + path.prepend("common://"); + m_collection_path = path; } - return false; + else if (path.startsWith(QETApp::customElementsDirN())) + { + path.remove(QETApp::customElementsDirN() + "/"); + path.prepend("custom://"); + m_collection_path = path; + } + return true; } else { - QDir dir(path); - if (dir.exists()) + m_file_system_path = path; + if (path.startsWith(QETApp::commonElementsDirN())) { - m_file_system_path = path; - if (path.startsWith(QETApp::commonElementsDir())) - { - path.remove(QETApp::commonElementsDir()); - path.prepend("common://"); - m_collection_path = path; - } - else if (path.startsWith(QETApp::customElementsDir())) - { - path.remove(QETApp::customElementsDir()); - path.prepend("custom://"); - m_collection_path = path; - } - return true; + path.remove(QETApp::commonElementsDirN() + "/"); + path.prepend("common://"); + m_collection_path = path; } - return false; + else if (path.startsWith(QETApp::customElementsDirN())) + { + path.remove(QETApp::customElementsDirN()) + "/"; + path.prepend("custom://"); + m_collection_path = path; + } + return true; } } @@ -260,9 +261,27 @@ bool ElementLocation::isProject() const } /** - * @brief ElementLocation::collectionPath - * @return the colletion relative to the collection + * @brief ElementLocation::exist + * @return True if this location represent an existing directory or element. */ +bool ElementLocation::exist() const +{ + if (isProject()) + return m_project->embeddedElementCollection()->exist(collectionPath(false)); + else + { + if (isDirectory()) + { + QDir dir(fileSystemPath()); + return dir.exists(); + } + else + { + return QFile::exists(fileSystemPath()); + } + } +} + /** * @brief ElementLocation::collectionPath * Return the path of the represented element relative to collection diff --git a/sources/ElementsCollection/elementlocation.h b/sources/ElementsCollection/elementlocation.h index 5f2918fa5..c321ac64d 100644 --- a/sources/ElementsCollection/elementlocation.h +++ b/sources/ElementsCollection/elementlocation.h @@ -38,6 +38,7 @@ class ElementLocation ElementLocation(QString path = QString()); ElementLocation(QString path, QETProject *project); ElementLocation(const QMimeData *data); + ElementLocation &operator=(const ElementLocation &other); ~ElementLocation(); bool setPath(QString path); @@ -47,6 +48,7 @@ class ElementLocation bool isDirectory() const; bool isFileSystem() const; bool isProject() const; + bool exist() const; QString collectionPath(bool protocol = true) const; QString fileSystemPath() const; diff --git a/sources/ElementsCollection/elementscollectionmodel.cpp b/sources/ElementsCollection/elementscollectionmodel.cpp index 374f3aaaa..2ab213428 100644 --- a/sources/ElementsCollection/elementscollectionmodel.cpp +++ b/sources/ElementsCollection/elementscollectionmodel.cpp @@ -246,7 +246,7 @@ QList ElementsCollectionModel::items() const void ElementsCollectionModel::addCommonCollection() { FileElementCollectionItem *feci = new FileElementCollectionItem(m_root_item); - if (feci->setRootPath(QETApp::commonElementsDir())) + if (feci->setRootPath(QETApp::commonElementsDirN())) m_root_item->appendChild(feci); else delete feci; @@ -259,7 +259,7 @@ void ElementsCollectionModel::addCommonCollection() void ElementsCollectionModel::addCustomCollection() { FileElementCollectionItem *feci = new FileElementCollectionItem(m_root_item); - if (feci->setRootPath(QETApp::customElementsDir())) + if (feci->setRootPath(QETApp::customElementsDirN())) m_root_item->appendChild(feci); else delete feci; diff --git a/sources/ElementsCollection/fileelementcollectionitem.cpp b/sources/ElementsCollection/fileelementcollectionitem.cpp index b770b4294..3cbf2eba7 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.cpp +++ b/sources/ElementsCollection/fileelementcollectionitem.cpp @@ -16,11 +16,11 @@ along with QElectroTech. If not, see . */ #include "fileelementcollectionitem.h" -#include "QDir" #include "qetapp.h" #include "elementslocation.h" #include "nameslist.h" #include "qeticons.h" +#include "elementcollectionhandler.h" /** * @brief FileElementCollectionItem::FileElementCollectionItem @@ -71,10 +71,11 @@ QString FileElementCollectionItem::fileSystemPath() const FileElementCollectionItem *parent = static_cast(m_parent_item); //Get the path of the parent. - if (parent->isCollectionRoot()) - return parent->fileSystemPath() + m_path; - else - return parent->fileSystemPath() + "/" + m_path; +// if (parent->isCollectionRoot()) +// return parent->fileSystemPath() + m_path; +// else +// return parent->fileSystemPath() + "/" + m_path; + return parent->fileSystemPath() + "/" + m_path; } /** @@ -104,7 +105,7 @@ QString FileElementCollectionItem::collectionPath() const //else this item is the root of collection path. if (!m_parent_item || m_parent_item->type() != FileElementCollectionItem::Type) { - if (m_path == QETApp::commonElementsDir()) + if (m_path == QETApp::commonElementsDirN()) return "common://"; else return "custom://"; @@ -154,7 +155,7 @@ QVariant FileElementCollectionItem::data(int column, int role) //This item have no parent or parent isn't a file element, so it is the root of a collection if (!m_parent_item || m_parent_item->type() != FileElementCollectionItem::Type) { - if (m_path == QETApp::commonElementsDir()) + if (m_path == QETApp::commonElementsDirN()) return QIcon(":/ico/16x16/qet.png"); else return QIcon(":/ico/16x16/go-home.png"); @@ -211,7 +212,17 @@ bool FileElementCollectionItem::canDropMimeData(const QMimeData *data, Qt::DropA if (isCommonCollection()) return false; if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri")) + { + //Return false if user try to drop a item from a folder to the same folder + ElementLocation drop_location(data->text()); + for (int i=0 ; i(child(i))->collectionPath() == drop_location.collectionPath()) + return false; + } + return true; + } else return false; } @@ -232,10 +243,23 @@ bool FileElementCollectionItem::dropMimeData(const QMimeData *data, Qt::DropActi if (isElement() && parent() && parent()->type() == FileElementCollectionItem::Type) feci = static_cast(parent()); - if (data->hasFormat("application/x-qet-element-uri")) - return feci->handleElementDrop(data); - else if (data->hasFormat("application/x-qet-category-uri")) - return feci->handleDirectoryDrop(data); + ElementCollectionHandler ech; + + ElementLocation source(data->text()); + ElementLocation destination(feci->fileSystemPath()); + ElementLocation location = ech.copy(source, destination); + + if (location.exist()) + { + //If this item have a child with the same path of location, + //we remove the existing child befor insert new child + for (int i=0 ; i(child(i))->collectionPath() == location.collectionPath()) + removeChild(i, 1); + + insertNewItem(location.fileName()); + return true; + } return false; } @@ -278,7 +302,7 @@ bool FileElementCollectionItem::isElement() const { */ bool FileElementCollectionItem::isCollectionRoot() const { - if (m_path == QETApp::commonElementsDir() || m_path == QETApp::customElementsDir()) + if (m_path == QETApp::commonElementsDirN() || m_path == QETApp::customElementsDirN()) return true; else return false; @@ -289,7 +313,7 @@ bool FileElementCollectionItem::isCollectionRoot() const * @return True if this item is part of the common element collection item */ bool FileElementCollectionItem::isCommonCollection() const { - return fileSystemPath().startsWith(QETApp::commonElementsDir()); + return fileSystemPath().startsWith(QETApp::commonElementsDirN()); } /** @@ -317,9 +341,9 @@ QString FileElementCollectionItem::name() { if (isCollectionRoot()) { - if (m_path == QETApp::commonElementsDir()) + if (m_path == QETApp::commonElementsDirN()) m_name = QObject::tr("Collection QET"); - else if (m_path == QETApp::customElementsDir()) + else if (m_path == QETApp::customElementsDirN()) m_name = QObject::tr("Collection utilisateur"); else m_name = QObject::tr("Collection inconnue"); @@ -443,70 +467,3 @@ void FileElementCollectionItem::populate() appendChild(feci); } } - -/** - * @brief FileElementCollectionItem::handleElementDrop - * Handle a drop data that represente an element. - * @param data - * @return true if the data is successfully dropped - */ -bool FileElementCollectionItem::handleElementDrop(const QMimeData *data) -{ - ElementLocation location(data->text()); - bool rb = QFile::copy(location.fileSystemPath(), fileSystemPath() + "/" + location.fileSystemPath().split("/").last()); - if (rb) insertNewItem(location.fileName()); - return rb; -} - -/** - * @brief FileElementCollectionItem::handleDirectoryDrop - * Handle a drop data that represent a directory - * @param data - * @return true if the data is successfully dropped - */ -bool FileElementCollectionItem::handleDirectoryDrop(const QMimeData *data) -{ - ElementLocation location(data->text()); - QDir origin_dir(location.fileSystemPath()); - - if (origin_dir.exists()) - { - bool rb = createSubDir(origin_dir, QDir(fileSystemPath())); - if(rb) insertNewItem(location.fileName()); - return rb; - } - else - return false; -} - -/** - * @brief FileElementCollectionItem::createSubDir - * Copy the directory @ dir_to_copy and the qet_directory file to destination. - * Also copy all directorys and elements find in @dir_to_copy recursively - * @param dir_to_copy - * @param destination - * @return true if the copy of @dir_to_copy to destination is successfull. - */ -bool FileElementCollectionItem::createSubDir(QDir dir_to_copy, QDir destination) -{ - if (destination.mkdir(dir_to_copy.dirName())) - { - QDir created_dir(destination.canonicalPath() + "/" + dir_to_copy.dirName()); - - //Copy the qet_directory file - QFile::copy(dir_to_copy.canonicalPath() + "/qet_directory", created_dir.canonicalPath() +"/qet_directory"); - - //Copy all dirs found in dir_to_copy to destination - foreach(QString str, dir_to_copy.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) - createSubDir(QDir(dir_to_copy.canonicalPath() + "/" + str), created_dir); - - //Copy all elements found in dir_to_copy to destination - dir_to_copy.setNameFilters(QStringList() << "*.elmt"); - foreach(QString str, dir_to_copy.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) - QFile::copy(dir_to_copy.canonicalPath() + "/" + str, created_dir.canonicalPath() + "/" + str); - - return true; - } - else - return false; -} diff --git a/sources/ElementsCollection/fileelementcollectionitem.h b/sources/ElementsCollection/fileelementcollectionitem.h index 5805fd9b8..e3f7e756e 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.h +++ b/sources/ElementsCollection/fileelementcollectionitem.h @@ -64,9 +64,9 @@ class FileElementCollectionItem : public ElementCollectionItem private: void setPathName(QString path_name); void populate(); - bool handleElementDrop (const QMimeData *data); - bool handleDirectoryDrop (const QMimeData *data); - bool createSubDir (QDir dir_to_copy, QDir destination); +// bool handleElementDrop (const QMimeData *data); +// bool handleDirectoryDrop (const QMimeData *data); +// bool createSubDir (QDir dir_to_copy, QDir destination); private: QString m_path; diff --git a/sources/ElementsCollection/ui/renamedialog.cpp b/sources/ElementsCollection/ui/renamedialog.cpp new file mode 100644 index 000000000..2190500f2 --- /dev/null +++ b/sources/ElementsCollection/ui/renamedialog.cpp @@ -0,0 +1,64 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "renamedialog.h" +#include "ui_renamedialog.h" + +RenameDialog::RenameDialog(QString path, QWidget *parent) : + QDialog(parent), + ui(new Ui::RenameDialog), + m_path(path) +{ + ui->setupUi(this); + m_name = m_path.split("/").last(); + if (m_name.endsWith(".elmt")) m_name.remove(".elmt"); + ui->m_label->setText(tr("L'élément « %1 » existe déjà. Que souhaitez-vous faire ?").arg(m_path)); + ui->lineEdit->setText(m_name + QDate::currentDate().toString("dd-MM-yy")); +} + +RenameDialog::~RenameDialog() +{ + delete ui; +} + +void RenameDialog::on_lineEdit_textEdited(const QString &arg1) +{ + if (arg1.isEmpty() || (arg1 == m_name)) + ui->m_rename_pb->setDisabled(true); + else + ui->m_rename_pb->setEnabled(true); +} + +void RenameDialog::on_m_erase_pb_clicked() +{ + m_action = QET::Erase; + accept(); +} + +void RenameDialog::on_m_rename_pb_clicked() +{ + m_action = QET::Rename; + m_new_name = ui->lineEdit->text(); + if (m_path.endsWith(".elmt")) m_new_name.append(".elmt"); + accept(); +} + +void RenameDialog::on_m_cancel_pb_clicked() +{ + m_action = QET::Abort; + reject(); +} diff --git a/sources/ElementsCollection/ui/renamedialog.h b/sources/ElementsCollection/ui/renamedialog.h new file mode 100644 index 000000000..77d84a436 --- /dev/null +++ b/sources/ElementsCollection/ui/renamedialog.h @@ -0,0 +1,53 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef RENAMEDIALOG_H +#define RENAMEDIALOG_H + +#include +#include "qet.h" + +namespace Ui { + class RenameDialog; +} + +class RenameDialog : public QDialog +{ + Q_OBJECT + + public: + explicit RenameDialog(QString path, QWidget *parent = 0); + ~RenameDialog(); + + QString newName() const {return m_new_name;} + QET::Action selectedAction() const {return m_action;} + + private slots: + void on_lineEdit_textEdited(const QString &arg1); + void on_m_erase_pb_clicked(); + void on_m_rename_pb_clicked(); + void on_m_cancel_pb_clicked(); + + private: + Ui::RenameDialog *ui; + QString m_path; + QString m_name; + QString m_new_name; + QET::Action m_action; +}; + +#endif // RENAMEDIALOG_H diff --git a/sources/ElementsCollection/ui/renamedialog.ui b/sources/ElementsCollection/ui/renamedialog.ui new file mode 100644 index 000000000..5eb631a41 --- /dev/null +++ b/sources/ElementsCollection/ui/renamedialog.ui @@ -0,0 +1,62 @@ + + + RenameDialog + + + + 0 + 0 + 284 + 88 + + + + Dialog + + + + + + Nouveau nom : + + + Qt::AlignCenter + + + + + + + Écraser + + + + + + + Renommer + + + + + + + Annuler + + + + + + + + + + TextLabel + + + + + + + + diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 9108703c8..78b4e5fd0 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -495,6 +495,30 @@ QString QETApp::customElementsDir() { return(configDir() + "elements/"); } +/** + * @brief QETApp::commonElementsDirN + * like QString QETApp::commonElementsDir but without "/" at the end + * @return + */ +QString QETApp::commonElementsDirN() +{ + QString path = commonElementsDir(); + if (path.endsWith("/")) path.remove(path.length()-1, 1); + return path; +} + +/** + * @brief QETApp::customElementsDirN + * like QString QETApp::customElementsDir but without "/" at the end + * @return + */ +QString QETApp::customElementsDirN() +{ + QString path = customElementsDir(); + if (path.endsWith("/")) path.remove(path.length()-1, 1); + return path; +} + /** @return the path of the directory containing the common title block templates collection. diff --git a/sources/qetapp.h b/sources/qetapp.h index bbe521050..6375c3042 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -85,6 +85,8 @@ class QETApp : public QETSingleApplication { static QString userName(); static QString commonElementsDir(); static QString customElementsDir(); + static QString commonElementsDirN(); + static QString customElementsDirN(); static QString commonTitleBlockTemplatesDir(); static QString customTitleBlockTemplatesDir(); static bool registerProject(QETProject *);