[qet] [4343] Change the way how an element or directory is copied, this isn' t the role of the new panel to manage the copy. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4343
Author: blacksun
Date: 2016-02-13 13:51:56 +0100 (Sat, 13 Feb 2016)
Log Message:
-----------
Change the way how an element or directory is copied, this isn't the role of the new panel to manage the copy.
We must to use elementcollectionhandler instead
Modified Paths:
--------------
trunk/qelectrotech.pro
trunk/sources/ElementsCollection/elementcollectionitem.cpp
trunk/sources/ElementsCollection/elementcollectionitem.h
trunk/sources/ElementsCollection/elementlocation.cpp
trunk/sources/ElementsCollection/elementlocation.h
trunk/sources/ElementsCollection/elementscollectionmodel.cpp
trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
trunk/sources/ElementsCollection/fileelementcollectionitem.h
trunk/sources/qetapp.cpp
trunk/sources/qetapp.h
Added Paths:
-----------
trunk/sources/ElementsCollection/elementcollectionhandler.cpp
trunk/sources/ElementsCollection/elementcollectionhandler.h
trunk/sources/ElementsCollection/ui/
trunk/sources/ElementsCollection/ui/renamedialog.cpp
trunk/sources/ElementsCollection/ui/renamedialog.h
trunk/sources/ElementsCollection/ui/renamedialog.ui
Modified: trunk/qelectrotech.pro
===================================================================
--- trunk/qelectrotech.pro 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/qelectrotech.pro 2016-02-13 12:51:56 UTC (rev 4343)
@@ -79,7 +79,8 @@
sources/editor/graphicspart \
sources/undocommand \
sources/diagramevent \
- sources/ElementsCollection
+ sources/ElementsCollection \
+ sources/ElementsCollection/ui
# Fichiers sources
@@ -91,7 +92,8 @@
$$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 @@
$$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 @@
# 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/
Added: trunk/sources/ElementsCollection/elementcollectionhandler.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionhandler.cpp (rev 0)
+++ trunk/sources/ElementsCollection/elementcollectionhandler.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#include "elementcollectionhandler.h"
+#include "renamedialog.h"
+#include <QFile>
+#include <QDir>
+
+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();
+}
Added: trunk/sources/ElementsCollection/elementcollectionhandler.h
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionhandler.h (rev 0)
+++ trunk/sources/ElementsCollection/elementcollectionhandler.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#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
Modified: trunk/sources/ElementsCollection/elementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -84,7 +84,7 @@
* @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);
}
Modified: trunk/sources/ElementsCollection/elementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.h 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/elementcollectionitem.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -43,7 +43,7 @@
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);
Modified: trunk/sources/ElementsCollection/elementlocation.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementlocation.cpp 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/elementlocation.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -59,6 +59,17 @@
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 @@
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 @@
{
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 @@
}
/**
- * @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
Modified: trunk/sources/ElementsCollection/elementlocation.h
===================================================================
--- trunk/sources/ElementsCollection/elementlocation.h 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/elementlocation.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -38,6 +38,7 @@
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 @@
bool isDirectory() const;
bool isFileSystem() const;
bool isProject() const;
+ bool exist() const;
QString collectionPath(bool protocol = true) const;
QString fileSystemPath() const;
Modified: trunk/sources/ElementsCollection/elementscollectionmodel.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.cpp 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -246,7 +246,7 @@
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::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;
Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -16,11 +16,11 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#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 @@
FileElementCollectionItem *parent = static_cast<FileElementCollectionItem*>(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 @@
//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 @@
//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 @@
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<childCount() ; i++)
+ {
+ if (static_cast<FileElementCollectionItem *>(child(i))->collectionPath() == drop_location.collectionPath())
+ return false;
+ }
+
return true;
+ }
else
return false;
}
@@ -232,11 +243,24 @@
if (isElement() && parent() && parent()->type() == FileElementCollectionItem::Type)
feci = static_cast<FileElementCollectionItem *>(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<childCount() ; i++)
+ if (static_cast<FileElementCollectionItem *>(child(i))->collectionPath() == location.collectionPath())
+ removeChild(i, 1);
+
+ insertNewItem(location.fileName());
+ return true;
+ }
+
return false;
}
@@ -278,7 +302,7 @@
*/
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 @@
* @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 @@
{
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 @@
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;
-}
Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.h 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -64,9 +64,9 @@
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;
Added: trunk/sources/ElementsCollection/ui/renamedialog.cpp
===================================================================
--- trunk/sources/ElementsCollection/ui/renamedialog.cpp (rev 0)
+++ trunk/sources/ElementsCollection/ui/renamedialog.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#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();
+}
Added: trunk/sources/ElementsCollection/ui/renamedialog.h
===================================================================
--- trunk/sources/ElementsCollection/ui/renamedialog.h (rev 0)
+++ trunk/sources/ElementsCollection/ui/renamedialog.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef RENAMEDIALOG_H
+#define RENAMEDIALOG_H
+
+#include <QDialog>
+#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
Added: trunk/sources/ElementsCollection/ui/renamedialog.ui
===================================================================
--- trunk/sources/ElementsCollection/ui/renamedialog.ui (rev 0)
+++ trunk/sources/ElementsCollection/ui/renamedialog.ui 2016-02-13 12:51:56 UTC (rev 4343)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>RenameDialog</class>
+ <widget class="QDialog" name="RenameDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>284</width>
+ <height>88</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Nouveau nom :</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="m_erase_pb">
+ <property name="text">
+ <string>Écraser</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="m_rename_pb">
+ <property name="text">
+ <string>Renommer</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QPushButton" name="m_cancel_pb">
+ <property name="text">
+ <string>Annuler</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2">
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item row="0" column="0" colspan="3">
+ <widget class="QLabel" name="m_label">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/qetapp.cpp 2016-02-13 12:51:56 UTC (rev 4343)
@@ -496,6 +496,30 @@
}
/**
+ * @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.
*/
Modified: trunk/sources/qetapp.h
===================================================================
--- trunk/sources/qetapp.h 2016-02-07 11:31:05 UTC (rev 4342)
+++ trunk/sources/qetapp.h 2016-02-13 12:51:56 UTC (rev 4343)
@@ -85,6 +85,8 @@
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 *);