mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Remove elementLocation and use elementsLocation instead
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4377 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
/******************************************************/
|
||||
|
||||
ECHStrategy::ECHStrategy(ElementLocation &source, ElementLocation &destination) :
|
||||
ECHStrategy::ECHStrategy(ElementsLocation &source, ElementsLocation &destination) :
|
||||
m_source(source),
|
||||
m_destination (destination)
|
||||
{}
|
||||
@@ -33,14 +33,14 @@ ECHStrategy::~ECHStrategy() {}
|
||||
|
||||
/******************************************************/
|
||||
|
||||
ECHSFileToFile::ECHSFileToFile(ElementLocation &source, ElementLocation &destination) :
|
||||
ECHSFileToFile::ECHSFileToFile(ElementsLocation &source, ElementsLocation &destination) :
|
||||
ECHStrategy(source, destination)
|
||||
{}
|
||||
|
||||
ElementLocation ECHSFileToFile::copy()
|
||||
ElementsLocation 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());
|
||||
ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName());
|
||||
QString rename;
|
||||
if (location.exist())
|
||||
{
|
||||
@@ -66,7 +66,7 @@ ElementLocation ECHSFileToFile::copy()
|
||||
}
|
||||
}
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
if (m_source.isElement())
|
||||
@@ -75,12 +75,12 @@ ElementLocation ECHSFileToFile::copy()
|
||||
return copyDirectory(m_source, m_destination, rename);
|
||||
}
|
||||
|
||||
ElementLocation ECHSFileToFile::copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename)
|
||||
ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename)
|
||||
{
|
||||
QDir source_dir(source.fileSystemPath());
|
||||
QDir destination_dir(destination.fileSystemPath());
|
||||
|
||||
if (!source_dir.exists() || !destination_dir.exists()) return ElementLocation();
|
||||
if (!source_dir.exists() || !destination_dir.exists()) return ElementsLocation();
|
||||
|
||||
QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename;
|
||||
|
||||
@@ -94,10 +94,10 @@ ElementLocation ECHSFileToFile::copyDirectory(ElementLocation &source, ElementLo
|
||||
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());
|
||||
ElementsLocation created_location(created_dir.canonicalPath());
|
||||
foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
ElementLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
copyDirectory(sub_source, created_location);
|
||||
}
|
||||
|
||||
@@ -105,36 +105,36 @@ ElementLocation ECHSFileToFile::copyDirectory(ElementLocation &source, ElementLo
|
||||
source_dir.setNameFilters(QStringList() << "*.elmt");
|
||||
foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
ElementLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
copyElement(sub_source, created_location);
|
||||
}
|
||||
|
||||
return created_location;
|
||||
}
|
||||
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
ElementLocation ECHSFileToFile::copyElement(ElementLocation &source, ElementLocation &destination, QString rename)
|
||||
ElementsLocation ECHSFileToFile::copyElement(ElementsLocation &source, ElementsLocation &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);
|
||||
return ElementsLocation (destination.fileSystemPath() + "/" + new_elmt_name);
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/******************************************************/
|
||||
|
||||
ECHSXmlToFile::ECHSXmlToFile(ElementLocation &source, ElementLocation &destination) :
|
||||
ECHSXmlToFile::ECHSXmlToFile(ElementsLocation &source, ElementsLocation &destination) :
|
||||
ECHStrategy(source, destination)
|
||||
{}
|
||||
|
||||
ElementLocation ECHSXmlToFile::copy()
|
||||
ElementsLocation ECHSXmlToFile::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());
|
||||
ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName());
|
||||
QString rename;
|
||||
if (location.exist())
|
||||
{
|
||||
@@ -160,7 +160,7 @@ ElementLocation ECHSXmlToFile::copy()
|
||||
}
|
||||
}
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
if (m_source.isElement())
|
||||
@@ -169,11 +169,11 @@ ElementLocation ECHSXmlToFile::copy()
|
||||
return copyDirectory(m_source, m_destination, rename);
|
||||
}
|
||||
|
||||
ElementLocation ECHSXmlToFile::copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename)
|
||||
ElementsLocation ECHSXmlToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename)
|
||||
{
|
||||
QDir destination_dir(destination.fileSystemPath());
|
||||
|
||||
if (!(destination_dir.exists() && source.exist())) return ElementLocation();
|
||||
if (!(destination_dir.exists() && source.exist())) return ElementsLocation();
|
||||
|
||||
QString new_dir_name = rename.isEmpty() ? source.fileName() : rename;
|
||||
|
||||
@@ -181,7 +181,7 @@ ElementLocation ECHSXmlToFile::copyDirectory(ElementLocation &source, ElementLoc
|
||||
if (destination_dir.mkdir(new_dir_name))
|
||||
{
|
||||
QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name);
|
||||
ElementLocation created_location(created_dir.canonicalPath());
|
||||
ElementsLocation created_location(created_dir.canonicalPath());
|
||||
|
||||
//Create the qet-directory file
|
||||
QDomDocument document;
|
||||
@@ -198,7 +198,7 @@ ElementLocation ECHSXmlToFile::copyDirectory(ElementLocation &source, ElementLoc
|
||||
QStringList directories_names = project_collection->directoriesNames( project_collection->directory(source.collectionPath(false)) );
|
||||
foreach(QString name, directories_names)
|
||||
{
|
||||
ElementLocation sub_source_dir(source.projectCollectionPath() + "/" + name);
|
||||
ElementsLocation sub_source_dir(source.projectCollectionPath() + "/" + name);
|
||||
copyDirectory(sub_source_dir, created_location);
|
||||
}
|
||||
|
||||
@@ -206,19 +206,19 @@ ElementLocation ECHSXmlToFile::copyDirectory(ElementLocation &source, ElementLoc
|
||||
QStringList elements_names = project_collection->elementsNames( project_collection->directory(source.collectionPath(false))) ;
|
||||
foreach (QString name, elements_names)
|
||||
{
|
||||
ElementLocation source_element(source.projectCollectionPath() + "/" + name);
|
||||
ElementsLocation source_element(source.projectCollectionPath() + "/" + name);
|
||||
copyElement(source_element, created_location);
|
||||
}
|
||||
|
||||
return created_location;
|
||||
}
|
||||
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
ElementLocation ECHSXmlToFile::copyElement(ElementLocation &source, ElementLocation &destination, QString rename)
|
||||
ElementsLocation ECHSXmlToFile::copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename)
|
||||
{
|
||||
if (!(destination.exist() && source.exist())) return ElementLocation();
|
||||
if (!(destination.exist() && source.exist())) return ElementsLocation();
|
||||
|
||||
QString new_element_name = rename.isEmpty() ? source.fileName() : rename;
|
||||
|
||||
@@ -229,23 +229,23 @@ ElementLocation ECHSXmlToFile::copyElement(ElementLocation &source, ElementLocat
|
||||
//Create the .elmt file
|
||||
QString filepath = destination.fileSystemPath() + "/" + new_element_name;
|
||||
if (QET::writeXmlFile(document, filepath))
|
||||
return ElementLocation(filepath);
|
||||
return ElementsLocation(filepath);
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/******************************************************/
|
||||
|
||||
ECHSToXml::ECHSToXml(ElementLocation &source, ElementLocation &destination) :
|
||||
ECHSToXml::ECHSToXml(ElementsLocation &source, ElementsLocation &destination) :
|
||||
ECHStrategy(source, destination)
|
||||
{}
|
||||
|
||||
ElementLocation ECHSToXml::copy()
|
||||
ElementsLocation ECHSToXml::copy()
|
||||
{
|
||||
if (!(m_source.exist() && m_destination.isDirectory() && m_destination.isProject())) return ElementLocation();
|
||||
if (!(m_source.exist() && m_destination.isDirectory() && m_destination.isProject())) return ElementsLocation();
|
||||
|
||||
//Check if the destination already have an item with the same name of the item to copy
|
||||
ElementLocation location(m_destination.projectCollectionPath() + "/" + m_source.fileName());
|
||||
ElementsLocation location(m_destination.projectCollectionPath() + "/" + m_source.fileName());
|
||||
|
||||
QString rename;
|
||||
if (location.exist())
|
||||
@@ -257,7 +257,7 @@ ElementLocation ECHSToXml::copy()
|
||||
rename = rd.newName();
|
||||
}
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
return m_destination.projectCollection()->copy(m_source, m_destination, rename);
|
||||
@@ -285,9 +285,9 @@ ElementCollectionHandler::~ElementCollectionHandler()
|
||||
* @param destination
|
||||
* @return
|
||||
*/
|
||||
ElementLocation ElementCollectionHandler::copy(ElementLocation &source, ElementLocation &destination)
|
||||
ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, ElementsLocation &destination)
|
||||
{
|
||||
if (!source.exist() || !destination.exist() || destination.isElement()) return ElementLocation();
|
||||
if (!source.exist() || !destination.exist() || destination.isElement()) return ElementsLocation();
|
||||
|
||||
if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination);
|
||||
if (source.isProject() && destination.isFileSystem()) m_strategy = new ECHSXmlToFile(source, destination);
|
||||
@@ -296,5 +296,5 @@ ElementLocation ElementCollectionHandler::copy(ElementLocation &source, ElementL
|
||||
if (m_strategy)
|
||||
return m_strategy->copy();
|
||||
else
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#ifndef ELEMENTCOLLECTIONHANDLER_H
|
||||
#define ELEMENTCOLLECTIONHANDLER_H
|
||||
|
||||
#include "elementlocation.h"
|
||||
#include "elementslocation.h"
|
||||
|
||||
class QWidget;
|
||||
|
||||
@@ -29,11 +29,11 @@ class QWidget;
|
||||
class ECHStrategy
|
||||
{
|
||||
public:
|
||||
ECHStrategy(ElementLocation &source, ElementLocation &destination);
|
||||
ECHStrategy(ElementsLocation &source, ElementsLocation &destination);
|
||||
virtual ~ECHStrategy();
|
||||
virtual ElementLocation copy() =0;
|
||||
virtual ElementsLocation copy() =0;
|
||||
|
||||
ElementLocation m_source, m_destination;
|
||||
ElementsLocation m_source, m_destination;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -43,12 +43,12 @@ class ECHStrategy
|
||||
class ECHSFileToFile : public ECHStrategy
|
||||
{
|
||||
public:
|
||||
ECHSFileToFile (ElementLocation &source, ElementLocation &destination);
|
||||
ElementLocation copy();
|
||||
ECHSFileToFile (ElementsLocation &source, ElementsLocation &destination);
|
||||
ElementsLocation copy();
|
||||
|
||||
private:
|
||||
ElementLocation copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename = QString());
|
||||
ElementLocation copyElement(ElementLocation &source, ElementLocation &destination, QString rename = QString());
|
||||
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -58,12 +58,12 @@ class ECHSFileToFile : public ECHStrategy
|
||||
class ECHSXmlToFile : public ECHStrategy
|
||||
{
|
||||
public:
|
||||
ECHSXmlToFile (ElementLocation &source, ElementLocation &destination);
|
||||
ElementLocation copy();
|
||||
ECHSXmlToFile (ElementsLocation &source, ElementsLocation &destination);
|
||||
ElementsLocation copy();
|
||||
|
||||
private:
|
||||
ElementLocation copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename = QString());
|
||||
ElementLocation copyElement(ElementLocation &source, ElementLocation &destination, QString rename = QString());
|
||||
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -74,8 +74,8 @@ class ECHSXmlToFile : public ECHStrategy
|
||||
class ECHSToXml : public ECHStrategy
|
||||
{
|
||||
public:
|
||||
ECHSToXml (ElementLocation &source, ElementLocation &destination);
|
||||
ElementLocation copy();
|
||||
ECHSToXml (ElementsLocation &source, ElementsLocation &destination);
|
||||
ElementsLocation copy();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ class ElementCollectionHandler
|
||||
ElementCollectionHandler();
|
||||
~ElementCollectionHandler();
|
||||
|
||||
ElementLocation copy(ElementLocation &source, ElementLocation &destination);
|
||||
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination);
|
||||
|
||||
private:
|
||||
ECHStrategy *m_strategy = nullptr;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#define ELEMENTCOLLECTIONITEM_H
|
||||
|
||||
#include <QVariant>
|
||||
#include "elementlocation.h"
|
||||
|
||||
class QMimeData;
|
||||
class ElementCollectionItem;
|
||||
|
||||
@@ -1,504 +0,0 @@
|
||||
/*
|
||||
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 "elementlocation.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetproject.h"
|
||||
#include "elementscollectioncache.h"
|
||||
#include "xmlelementcollection.h"
|
||||
#include "elementfactory.h"
|
||||
#include "element.h"
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::ElementLocation
|
||||
* @param path : path of item in file system
|
||||
*/
|
||||
ElementLocation::ElementLocation(QString path)
|
||||
{
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::ElementLocation
|
||||
* @param path : path of item embedded in @project
|
||||
* The path must be in form : embed://dir/subdir/myElement.elmt
|
||||
* @param project : project
|
||||
*/
|
||||
ElementLocation::ElementLocation(QString path, QETProject *project) :
|
||||
m_project(project)
|
||||
{
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::ElementLocation
|
||||
* Constructor, build an ElementLocation from a QMimeData, the mime data format
|
||||
* must be "application/x-qet-element-uri" or "application/x-qet-category-uri".
|
||||
* This location can be null even if format is valid.
|
||||
* @param data
|
||||
*/
|
||||
ElementLocation::ElementLocation(const QMimeData *data)
|
||||
{
|
||||
if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri"))
|
||||
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()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::setPath
|
||||
* Set the path of this item.
|
||||
* If the path is for a file collection, the path can be in file system or relative to the beginning
|
||||
* of the colection, in this case the path must start with (common:// or custom://).
|
||||
* @param path
|
||||
* @return true if the element pointed by path exist, else false
|
||||
*/
|
||||
bool ElementLocation::setPath(QString path)
|
||||
{
|
||||
QString tmp_path = path;
|
||||
|
||||
//There is a project, the path is for an embedded coolection.
|
||||
if (m_project)
|
||||
{
|
||||
if (path.startsWith("embed://"))
|
||||
{
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//The path start with project, we get the project and the path from the string
|
||||
else if (tmp_path.startsWith("project"))
|
||||
{
|
||||
QRegExp rx("^project([0-9]+)\\+(embed:\\/\\/.*)$", Qt::CaseInsensitive);
|
||||
if (rx.exactMatch(tmp_path))
|
||||
{
|
||||
bool conv_ok;
|
||||
uint project_id = rx.capturedTexts().at(1).toUInt(&conv_ok);
|
||||
if (conv_ok)
|
||||
{
|
||||
QETProject *project = QETApp::project(project_id);
|
||||
if (project)
|
||||
{
|
||||
m_collection_path = rx.capturedTexts().at(2);
|
||||
m_project = project;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//The path is in file system, the given path is relative to common or custom collection
|
||||
else if (path.startsWith("common://") || path.startsWith("custom://"))
|
||||
{
|
||||
QString p;
|
||||
if (path.startsWith("common://"))
|
||||
{
|
||||
tmp_path.remove("common://");
|
||||
p = QETApp::commonElementsDirN() + "/" + tmp_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_path.remove("custom://");
|
||||
p = QETApp::customElementsDirN() + "/" + tmp_path;
|
||||
}
|
||||
|
||||
//This is an element
|
||||
if (path.endsWith(".elmt"))
|
||||
{
|
||||
QFile file(p);
|
||||
if (file.exists())
|
||||
{
|
||||
m_file_system_path = p;
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//They must be a directory
|
||||
else
|
||||
{
|
||||
QDir dir(p);
|
||||
if(dir.exists())
|
||||
{
|
||||
m_file_system_path = p;
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//In this case, the path is supposed to be relative to the file system.
|
||||
else
|
||||
{
|
||||
if(path.endsWith(".elmt"))
|
||||
{
|
||||
m_file_system_path = path;
|
||||
if (path.startsWith(QETApp::commonElementsDirN()))
|
||||
{
|
||||
path.remove(QETApp::commonElementsDirN()+="/");
|
||||
path.prepend("common://");
|
||||
m_collection_path = path;
|
||||
}
|
||||
else if (path.startsWith(QETApp::customElementsDirN()))
|
||||
{
|
||||
path.remove(QETApp::customElementsDirN()+="/");
|
||||
path.prepend("custom://");
|
||||
m_collection_path = path;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file_system_path = path;
|
||||
if (path.startsWith(QETApp::commonElementsDirN()))
|
||||
{
|
||||
path.remove(QETApp::commonElementsDirN()+="/");
|
||||
path.prepend("common://");
|
||||
m_collection_path = path;
|
||||
}
|
||||
else if (path.startsWith(QETApp::customElementsDirN()))
|
||||
{
|
||||
path.remove(QETApp::customElementsDirN()+="/");
|
||||
path.prepend("custom://");
|
||||
m_collection_path = path;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::isNull
|
||||
* @return True represent nothing
|
||||
*/
|
||||
bool ElementLocation::isNull() const
|
||||
{
|
||||
if (isFileSystem() || isProject())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::setProject
|
||||
* @param project : set the project of this location to @project.
|
||||
*/
|
||||
void ElementLocation::setProject(QETProject *project) {
|
||||
m_project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::isElement
|
||||
* @return true if this location represent an element
|
||||
*/
|
||||
bool ElementLocation::isElement() const {
|
||||
return m_collection_path.endsWith(".elmt");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::isDirectory
|
||||
* @return true if this location represent a directory
|
||||
*/
|
||||
bool ElementLocation::isDirectory() const
|
||||
{
|
||||
return (!isElement() && !m_collection_path.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::isFileSystem
|
||||
* @return True if this location represent a file system item.
|
||||
*/
|
||||
bool ElementLocation::isFileSystem() const
|
||||
{
|
||||
if (m_project) return false;
|
||||
if (m_file_system_path.isEmpty()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::isProject
|
||||
* @return True if this location represent an item from a project.
|
||||
*/
|
||||
bool ElementLocation::isProject() const
|
||||
{
|
||||
if (m_project && !m_collection_path.isEmpty())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::exist
|
||||
* @return True if this location represent an existing directory or element.
|
||||
*/
|
||||
bool ElementLocation::exist() const
|
||||
{
|
||||
if (m_project)
|
||||
return m_project->embeddedElementCollection()->exist(collectionPath(false));
|
||||
else
|
||||
{
|
||||
if (fileSystemPath().isEmpty()) return false;
|
||||
|
||||
if (isDirectory())
|
||||
{
|
||||
QDir dir(fileSystemPath());
|
||||
return dir.exists();
|
||||
}
|
||||
else if (isElement())
|
||||
return QFile::exists(fileSystemPath());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::projectCollection
|
||||
* @return If this location represente a item in an embedded project collection, return this collection
|
||||
* else return nullptr.
|
||||
*/
|
||||
XmlElementCollection *ElementLocation::projectCollection() const
|
||||
{
|
||||
if (m_project)
|
||||
return m_project->embeddedElementCollection();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::nameList
|
||||
* @return the namelist of the represented element or directory.
|
||||
* If namelist can't be set, return a empty namelist
|
||||
*/
|
||||
NamesList ElementLocation::nameList()
|
||||
{
|
||||
NamesList nl;
|
||||
|
||||
if (isElement())
|
||||
nl.fromXml(xml());
|
||||
|
||||
if (isDirectory())
|
||||
{
|
||||
if (m_project)
|
||||
nl.fromXml(m_project->embeddedElementCollection()->directory(collectionPath(false)));
|
||||
else
|
||||
{
|
||||
//Open the qet_directory file, to get the traductions name of this dir
|
||||
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
||||
if (dir_conf.exists() && dir_conf.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
//Get the content of the file
|
||||
QDomDocument document;
|
||||
if (document.setContent(&dir_conf))
|
||||
{
|
||||
QDomElement root = document.documentElement();
|
||||
if (root.tagName() == "qet-directory")
|
||||
nl.fromXml(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::collectionPath
|
||||
* Return the path of the represented element relative to collection
|
||||
* if @protocol is true the path is prepended by the collection type (common://, custom:// or embed://)
|
||||
* else if false, only the collection path is returned without the collection type.
|
||||
* @param protocol
|
||||
* @return the path
|
||||
*/
|
||||
QString ElementLocation::collectionPath(bool protocol) const
|
||||
{
|
||||
if (protocol)
|
||||
return m_collection_path;
|
||||
else
|
||||
{
|
||||
QString path = m_collection_path;
|
||||
return path.remove(QRegularExpression("common://|custom://|embed://"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::projectCollectionPath
|
||||
* @return The path is in form : project0+embed://dir/subdir/myElement.elmt
|
||||
* If this item represent a file system thing, return a null QString;
|
||||
*/
|
||||
QString ElementLocation::projectCollectionPath() const
|
||||
{
|
||||
if (isFileSystem())
|
||||
return QString();
|
||||
else
|
||||
return QString("project" + QString::number(QETApp::projectId(m_project)) + "+" + collectionPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::fileSystemPath
|
||||
* @return The file system path of this element, (the separator is always '/' see QDir::toNativeSeparators())
|
||||
* If this element is embedded in a project return an empty string;
|
||||
*/
|
||||
QString ElementLocation::fileSystemPath() const
|
||||
{
|
||||
if (!m_project)
|
||||
return m_file_system_path;
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::project
|
||||
* @return the project of this location if he was set.
|
||||
*/
|
||||
QETProject *ElementLocation::project() const {
|
||||
return m_project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::xml
|
||||
* @return The definition of this element.
|
||||
* The definition can be null.
|
||||
*/
|
||||
QDomElement ElementLocation::xml()
|
||||
{
|
||||
if (!m_xml.isNull())
|
||||
return m_xml;
|
||||
|
||||
if (!m_project)
|
||||
{
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
m_xml = docu.documentElement().cloneNode().toElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString str = m_collection_path;
|
||||
if (isElement())
|
||||
{
|
||||
QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://"));
|
||||
m_xml = element.firstChildElement("definition");
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement element = m_project->embeddedElementCollection()->directory(str.remove("embed://"));
|
||||
m_xml = element;
|
||||
}
|
||||
}
|
||||
|
||||
return m_xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::uuid
|
||||
* @return The uuid of the pointed element
|
||||
*/
|
||||
QUuid ElementLocation::uuid()
|
||||
{
|
||||
if (!m_uuid.isNull()) return m_uuid;
|
||||
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
|
||||
if (!list_.isEmpty())
|
||||
m_uuid = QUuid(list_.first().attribute("uuid"));
|
||||
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::icon
|
||||
* @return The icon of the represented element.
|
||||
* If icon can't be set, return a null QIcon
|
||||
*/
|
||||
QIcon ElementLocation::icon()
|
||||
{
|
||||
if (!m_icon.isNull()) return m_icon;
|
||||
|
||||
if (!m_project)
|
||||
{
|
||||
ElementsCollectionCache *cache = QETApp::collectionCache();
|
||||
if (cache->fetchElement(*this))
|
||||
m_icon = QIcon(cache->pixmap());
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementFactory *factory = ElementFactory::Instance();
|
||||
int state;
|
||||
Element *elmt = factory->createElement(*this, 0, &state);
|
||||
|
||||
if (state == 0)
|
||||
m_icon = QIcon(elmt->pixmap());
|
||||
}
|
||||
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::name
|
||||
* @return The name of the represented element in the current local
|
||||
*/
|
||||
QString ElementLocation::name()
|
||||
{
|
||||
if (!m_project)
|
||||
{
|
||||
ElementsCollectionCache *cache = QETApp::collectionCache();
|
||||
if (cache->fetchElement(*this))
|
||||
return cache->name();
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
else
|
||||
{
|
||||
NamesList nl;
|
||||
nl.fromXml(xml());
|
||||
return nl.name(fileName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::fileName
|
||||
* @return Return the file name of this element whatever the storage system (file system, xml collection)
|
||||
*/
|
||||
QString ElementLocation::fileName() const
|
||||
{
|
||||
if (m_collection_path.isEmpty()) return QString();
|
||||
|
||||
QStringList qsl = m_collection_path.split("/");
|
||||
if (qsl.isEmpty()) return QString();
|
||||
else return qsl.last();
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
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 ELEMENTLOCATION_H
|
||||
#define ELEMENTLOCATION_H
|
||||
|
||||
#include "nameslist.h"
|
||||
#include <QString>
|
||||
#include <QDomElement>
|
||||
#include <QUuid>
|
||||
#include <QIcon>
|
||||
|
||||
class QETProject;
|
||||
class QMimeData;
|
||||
class XmlElementCollection;
|
||||
|
||||
/**
|
||||
* @brief The ElementLocation class
|
||||
* This class represent the location of an element or a directory in the file system
|
||||
* or an embedded collection of a project.
|
||||
* They also provide common things about an element, like the icon, uuid etc...
|
||||
*/
|
||||
class ElementLocation
|
||||
{
|
||||
public:
|
||||
ElementLocation(QString path = QString());
|
||||
ElementLocation(QString path, QETProject *project);
|
||||
ElementLocation(const QMimeData *data);
|
||||
ElementLocation &operator=(const ElementLocation &other);
|
||||
~ElementLocation();
|
||||
|
||||
bool setPath(QString path);
|
||||
bool isNull() const;
|
||||
void setProject(QETProject *project);
|
||||
bool isElement() const;
|
||||
bool isDirectory() const;
|
||||
bool isFileSystem() const;
|
||||
bool isProject() const;
|
||||
bool exist() const;
|
||||
XmlElementCollection *projectCollection() const;
|
||||
NamesList nameList();
|
||||
|
||||
QString collectionPath(bool protocol = true) const;
|
||||
QString projectCollectionPath() const;
|
||||
QString fileSystemPath() const;
|
||||
|
||||
QETProject *project() const;
|
||||
|
||||
QDomElement xml();
|
||||
QUuid uuid();
|
||||
QIcon icon();
|
||||
QString name();
|
||||
QString fileName() const;
|
||||
|
||||
private:
|
||||
QString m_collection_path;
|
||||
QString m_file_system_path;
|
||||
QETProject *m_project = nullptr;
|
||||
QDomElement m_xml;
|
||||
QUuid m_uuid;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
#endif // ELEMENTLOCATION_H
|
||||
@@ -167,7 +167,7 @@ QVariant FileElementCollectionItem::data(int column, int role)
|
||||
{
|
||||
if (m_icon.isNull())
|
||||
{
|
||||
ElementLocation loc(collectionPath());
|
||||
ElementsLocation loc(collectionPath());
|
||||
m_icon = loc.icon();
|
||||
}
|
||||
return m_icon;
|
||||
@@ -214,7 +214,7 @@ bool FileElementCollectionItem::canDropMimeData(const QMimeData *data, Qt::DropA
|
||||
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());
|
||||
ElementsLocation drop_location(data->text());
|
||||
for (int i=0 ; i<childCount() ; i++)
|
||||
{
|
||||
if (static_cast<FileElementCollectionItem *>(child(i))->collectionPath() == drop_location.collectionPath())
|
||||
@@ -245,9 +245,9 @@ bool FileElementCollectionItem::dropMimeData(const QMimeData *data, Qt::DropActi
|
||||
|
||||
ElementCollectionHandler ech;
|
||||
|
||||
ElementLocation source(data->text());
|
||||
ElementLocation destination(feci->fileSystemPath());
|
||||
ElementLocation location = ech.copy(source, destination);
|
||||
ElementsLocation source(data->text());
|
||||
ElementsLocation destination(feci->fileSystemPath());
|
||||
ElementsLocation location = ech.copy(source, destination);
|
||||
|
||||
if (location.exist())
|
||||
{
|
||||
@@ -375,7 +375,7 @@ QString FileElementCollectionItem::name()
|
||||
}
|
||||
else if (isElement())
|
||||
{
|
||||
ElementLocation loc(collectionPath());
|
||||
ElementsLocation loc(collectionPath());
|
||||
m_name = loc.name();
|
||||
}
|
||||
return m_name;
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#define FILEELEMENTCOLLECTIONITEM_H
|
||||
|
||||
#include "elementcollectionitem.h"
|
||||
#include "elementlocation.h"
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
|
||||
/**
|
||||
* @brief The FileElementCollectionItem class
|
||||
@@ -69,7 +69,6 @@ class FileElementCollectionItem : public ElementCollectionItem
|
||||
|
||||
private:
|
||||
QString m_path;
|
||||
ElementLocation m_location;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "nameslist.h"
|
||||
#include "elementlocation.h"
|
||||
#include "qetxml.h"
|
||||
#include "elementslocation.h"
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::XmlElementCollection
|
||||
@@ -322,8 +323,7 @@ QDomElement XmlElementCollection::directory(const QString &path)
|
||||
*/
|
||||
QString XmlElementCollection::addElement(const QString &path)
|
||||
{
|
||||
|
||||
ElementLocation location(path);
|
||||
ElementsLocation location(path);
|
||||
if (!location.isElement() || location.fileSystemPath().isEmpty()) return QString();
|
||||
if (exist(QString("import/" + location.collectionPath(false)))) return QString();
|
||||
|
||||
@@ -388,20 +388,16 @@ QString XmlElementCollection::addElement(const QString &path)
|
||||
* @brief XmlElementCollection::copy
|
||||
* Copy the content represented by source (an element or a directory) to destination.
|
||||
* Destination must be a directory of this collection.
|
||||
*
|
||||
* WARNING :
|
||||
* for now, only work if source represent a file or directory from filesystem.
|
||||
*
|
||||
* @param source : content to copy
|
||||
* @param destination : destination of the copy, must be a directory of this collection
|
||||
* @param rename : rename the copy with @rename else use the name of source
|
||||
* @param deep_copy : if true copy all childs of source (only if source is directory)
|
||||
* @return the ElementLocation that represent the copy, if copy failed return a null ElementLocation
|
||||
*/
|
||||
ElementLocation XmlElementCollection::copy(ElementLocation &source, ElementLocation &destination, QString rename, bool deep_copy)
|
||||
ElementsLocation XmlElementCollection::copy(ElementsLocation &source, ElementsLocation &destination, QString rename, bool deep_copy)
|
||||
{
|
||||
if (!(source.exist() && destination.isDirectory() && destination.isProject() && destination.projectCollection() == this))
|
||||
return ElementLocation();
|
||||
return ElementsLocation();
|
||||
|
||||
if (source.isElement())
|
||||
return copyElement(source, destination, rename);
|
||||
@@ -447,13 +443,13 @@ bool XmlElementCollection::exist(const QString &path)
|
||||
* @param deep_copy :if true copy all childs of source
|
||||
* @return the ElementLocation that represent the copy, if copy failed return a null ElementLocation
|
||||
*/
|
||||
ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename, bool deep_copy)
|
||||
ElementsLocation XmlElementCollection::copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename, bool deep_copy)
|
||||
{
|
||||
QString new_dir_name = rename.isEmpty() ? source.fileName() : rename;
|
||||
|
||||
//Get the xml directory where the new directory must be added
|
||||
QDomElement parent_dir_dom = directory(destination.collectionPath(false));
|
||||
if (parent_dir_dom.isNull()) return ElementLocation();
|
||||
if (parent_dir_dom.isNull()) return ElementsLocation();
|
||||
|
||||
//Remove the previous directory with the same path
|
||||
QDomElement element = child(destination.collectionPath(false) + "/" + new_dir_name);
|
||||
@@ -462,18 +458,18 @@ ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, Ele
|
||||
|
||||
|
||||
|
||||
ElementLocation created_location;
|
||||
ElementsLocation created_location;
|
||||
|
||||
//Copy with a file system collection source
|
||||
if (source.isFileSystem())
|
||||
{
|
||||
QDir source_dir(source.fileSystemPath());
|
||||
if (!source_dir.exists()) return ElementLocation();
|
||||
if (!source_dir.exists()) return ElementsLocation();
|
||||
|
||||
|
||||
QDir dir(source.fileSystemPath());
|
||||
QDomElement elmt_dom = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir, new_dir_name);
|
||||
if (elmt_dom.isNull()) return ElementLocation();
|
||||
if (elmt_dom.isNull()) return ElementsLocation();
|
||||
|
||||
parent_dir_dom.appendChild(elmt_dom);
|
||||
|
||||
@@ -484,7 +480,7 @@ ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, Ele
|
||||
//Append all directories of source to the new created directory
|
||||
foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
ElementLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
copyDirectory(sub_source, created_location);
|
||||
}
|
||||
|
||||
@@ -492,7 +488,7 @@ ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, Ele
|
||||
source_dir.setNameFilters(QStringList() << "*.elmt");
|
||||
foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
ElementLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
|
||||
copyElement(sub_source, created_location);
|
||||
}
|
||||
}
|
||||
@@ -501,10 +497,10 @@ ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, Ele
|
||||
//Copy with a xml collection source
|
||||
else
|
||||
{
|
||||
if (!source.projectCollection()) return ElementLocation();
|
||||
if (!source.projectCollection()) return ElementsLocation();
|
||||
|
||||
QDomNode other_collection_node = source.projectCollection()->child(source.collectionPath(false)).cloneNode(true);
|
||||
if (other_collection_node.isNull()) return ElementLocation();
|
||||
if (other_collection_node.isNull()) return ElementsLocation();
|
||||
|
||||
QDomElement other_collection_dom_dir = other_collection_node.toElement();
|
||||
other_collection_dom_dir.setAttribute("name", new_dir_name);
|
||||
@@ -523,7 +519,7 @@ ElementLocation XmlElementCollection::copyDirectory(ElementLocation &source, Ele
|
||||
* @param rename : rename the copy with @rename else use the name of source
|
||||
* @return
|
||||
*/
|
||||
ElementLocation XmlElementCollection::copyElement(ElementLocation &source, ElementLocation &destination, QString rename)
|
||||
ElementsLocation XmlElementCollection::copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename)
|
||||
{
|
||||
QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename;
|
||||
|
||||
@@ -534,7 +530,7 @@ ElementLocation XmlElementCollection::copyElement(ElementLocation &source, Eleme
|
||||
{
|
||||
QFile file(source.fileSystemPath());
|
||||
elmt_dom = QETXML::fileSystemElementToXmlCollectionElement(m_dom_document, file, new_elmt_name);
|
||||
if (elmt_dom.isNull()) return ElementLocation();
|
||||
if (elmt_dom.isNull()) return ElementsLocation();
|
||||
}
|
||||
//Copy with a xml collection source
|
||||
else
|
||||
@@ -553,8 +549,8 @@ ElementLocation XmlElementCollection::copyElement(ElementLocation &source, Eleme
|
||||
|
||||
//Get the xml directory where the new element must be added
|
||||
QDomElement dir_dom = directory(destination.collectionPath(false));
|
||||
if (dir_dom.isNull()) return ElementLocation();
|
||||
if (dir_dom.isNull()) return ElementsLocation();
|
||||
dir_dom.appendChild(elmt_dom);
|
||||
|
||||
return ElementLocation(destination.projectCollectionPath() + "/" + new_elmt_name);
|
||||
return ElementsLocation(destination.projectCollectionPath() + "/" + new_elmt_name);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#ifndef XMLELEMENTCOLLECTION_H
|
||||
#define XMLELEMENTCOLLECTION_H
|
||||
|
||||
#include "elementlocation.h"
|
||||
#include <QObject>
|
||||
#include <QDomElement>
|
||||
|
||||
@@ -47,12 +46,12 @@ class XmlElementCollection : public QObject
|
||||
QDomElement element(const QString &path);
|
||||
QDomElement directory(const QString &path);
|
||||
QString addElement (const QString &path);
|
||||
ElementLocation copy (ElementLocation &source, ElementLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
bool exist (const QString &path);
|
||||
|
||||
private:
|
||||
ElementLocation copyDirectory(ElementLocation &source, ElementLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
ElementLocation copyElement(ElementLocation &source, ElementLocation &destination, QString rename = QString());
|
||||
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "xmlelementcollection.h"
|
||||
#include "nameslist.h"
|
||||
#include "qetapp.h"
|
||||
#include "elementlocation.h"
|
||||
#include "elementcollectionhandler.h"
|
||||
#include <algorithm>
|
||||
|
||||
@@ -86,7 +85,7 @@ QVariant XmlProjectElementCollectionItem::data(int column, int role)
|
||||
{
|
||||
if (m_icon.isNull())
|
||||
{
|
||||
ElementLocation loc(embeddedPath(), m_project);
|
||||
ElementsLocation loc(embeddedPath(), m_project);
|
||||
m_icon = loc.icon();
|
||||
}
|
||||
return m_icon;
|
||||
@@ -135,7 +134,7 @@ bool XmlProjectElementCollectionItem::canDropMimeData(const QMimeData *data, Qt:
|
||||
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());
|
||||
ElementsLocation drop_location(data->text());
|
||||
for (int i=0 ; i<childCount() ; i++)
|
||||
{
|
||||
if (static_cast<XmlProjectElementCollectionItem *>(child(i))->collectionPath() == drop_location.collectionPath())
|
||||
@@ -176,9 +175,9 @@ bool XmlProjectElementCollectionItem::dropMimeData(const QMimeData *data, Qt::Dr
|
||||
|
||||
ElementCollectionHandler ech;
|
||||
|
||||
ElementLocation source(data->text());
|
||||
ElementLocation destination(xpeci->collectionPath());
|
||||
ElementLocation location = ech.copy(source, destination);
|
||||
ElementsLocation source(data->text());
|
||||
ElementsLocation destination(xpeci->collectionPath());
|
||||
ElementsLocation location = ech.copy(source, destination);
|
||||
|
||||
if (location.exist())
|
||||
{
|
||||
@@ -234,7 +233,7 @@ QString XmlProjectElementCollectionItem::name()
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementLocation location (embeddedPath(), m_project);
|
||||
ElementsLocation location (embeddedPath(), m_project);
|
||||
m_name = location.name();
|
||||
return m_name;
|
||||
}
|
||||
@@ -283,7 +282,7 @@ bool XmlProjectElementCollectionItem::isElement() const
|
||||
*/
|
||||
QString XmlProjectElementCollectionItem::collectionPath() const
|
||||
{
|
||||
ElementLocation loc (embeddedPath(), m_project);
|
||||
ElementsLocation loc (embeddedPath(), m_project);
|
||||
return loc.projectCollectionPath();
|
||||
}
|
||||
|
||||
|
||||
@@ -221,24 +221,38 @@ bool ElementsCollectionCache::fetchElement(ElementDefinition *element)
|
||||
/**
|
||||
* @brief ElementsCollectionCache::fetchElement
|
||||
* Retrieve the data for a given element, using the cache if available,
|
||||
* filling it otherwise. Data are then available through pixmap() and name() methods
|
||||
* @param location The definition of an element
|
||||
* filling it otherwise. Data are then available through pixmap() and name() methods.
|
||||
* @param location The definition of an element.
|
||||
* @see pixmap()
|
||||
* @see name()
|
||||
* @return True if the retrieval succeeded, false otherwise
|
||||
* @return True if the retrieval succeeded, false otherwise.
|
||||
*/
|
||||
bool ElementsCollectionCache::fetchElement(ElementLocation location)
|
||||
bool ElementsCollectionCache::fetchElement(ElementsLocation &location)
|
||||
{
|
||||
if (fetchNameFromCache(location.collectionPath(), location.uuid()) &&
|
||||
fetchPixmapFromCache(location.collectionPath(), location.uuid()))
|
||||
return true;
|
||||
else if (fetchData(location))
|
||||
{
|
||||
cacheName(location.collectionPath(), location.uuid());
|
||||
cachePixmap(location.collectionPath(), location.uuid());
|
||||
return true;
|
||||
// can we use the cache with this element?
|
||||
bool use_cache = cache_db_.isOpen() && !location.isProject();
|
||||
|
||||
// attempt to fetch the element name from the cache database
|
||||
if (!use_cache) {
|
||||
return(fetchData(location));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString element_path = location.toString();
|
||||
bool got_name = fetchNameFromCache(element_path, location.uuid());
|
||||
bool got_pixmap = fetchPixmapFromCache(element_path, location.uuid());
|
||||
|
||||
if (got_name && got_pixmap) {
|
||||
return(true);
|
||||
}
|
||||
|
||||
if (fetchData(location))
|
||||
{
|
||||
cacheName(element_path, location.uuid());
|
||||
cachePixmap(element_path, location.uuid());
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,30 +289,6 @@ bool ElementsCollectionCache::fetchData(const ElementsLocation &location) {
|
||||
return(!state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionCache::fetchData
|
||||
* Retrieve the data by building the full CustomElement object matching the given location,
|
||||
* without using the cache. Data are then available through pixmap() and name() methods
|
||||
* @param location : location of a given element
|
||||
* @return True if the retrieval succeeded, false otherwise
|
||||
*/
|
||||
bool ElementsCollectionCache::fetchData(ElementLocation &location)
|
||||
{
|
||||
int state;
|
||||
Element *element = ElementFactory::Instance()->createElement(location, 0, &state);
|
||||
|
||||
if(state)
|
||||
qDebug() << "ElementsCollectionCache::fetchData() 2: Le chargement du composant" << qPrintable(location.fileSystemPath()) << "a echoue avec le code d'erreur" << state;
|
||||
else
|
||||
{
|
||||
current_name_ = element->name();
|
||||
current_pixmap_ = element->pixmap();
|
||||
}
|
||||
|
||||
delete element;
|
||||
return (!state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionCache::fetchNameFromCache
|
||||
* Retrieve the name for an element, given its path and uuid
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include "elementslocation.h"
|
||||
#include "elementlocation.h"
|
||||
|
||||
class ElementsCollection;
|
||||
class ElementsCategory;
|
||||
@@ -47,11 +46,10 @@ class ElementsCollectionCache : public QObject
|
||||
void beginCollection(ElementsCollection *);
|
||||
void endCollection(ElementsCollection *);
|
||||
bool fetchElement(ElementDefinition *);
|
||||
bool fetchElement(ElementLocation location);
|
||||
bool fetchElement(ElementsLocation &location);
|
||||
QString name() const;
|
||||
QPixmap pixmap() const;
|
||||
bool fetchData(const ElementsLocation &);
|
||||
bool fetchData(ElementLocation &location);
|
||||
bool fetchNameFromCache(const QString &path, const QUuid &uuid);
|
||||
bool fetchPixmapFromCache(const QString &path, const QUuid &uuid);
|
||||
bool cacheName(const QString &path, const QUuid &uuid = QUuid::createUuid());
|
||||
|
||||
@@ -17,25 +17,31 @@
|
||||
*/
|
||||
#include "elementslocation.h"
|
||||
#include "qetapp.h"
|
||||
#include "xmlelementcollection.h"
|
||||
#include "qetproject.h"
|
||||
#include "elementscollectioncache.h"
|
||||
#include "elementfactory.h"
|
||||
#include "element.h"
|
||||
|
||||
// make this class usable with QVariant
|
||||
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
||||
|
||||
/**
|
||||
Constructeur par defaut
|
||||
*/
|
||||
ElementsLocation::ElementsLocation() : project_(0) {
|
||||
}
|
||||
* @brief ElementsLocation::ElementsLocation
|
||||
* Constructor
|
||||
*/
|
||||
ElementsLocation::ElementsLocation()
|
||||
{}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param p Chemin de l'emplacement de l'element
|
||||
@param pr Projet de l'emplacement de l'element
|
||||
*/
|
||||
ElementsLocation::ElementsLocation(const QString &p, QETProject *pr) :
|
||||
project_(pr)
|
||||
ElementsLocation::ElementsLocation(const QString &path, QETProject *project) :
|
||||
m_project(project)
|
||||
{
|
||||
setPath(p);
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,18 +55,31 @@ ElementsLocation::~ElementsLocation() {
|
||||
@param other Autre emplacement d'element a copier
|
||||
*/
|
||||
ElementsLocation::ElementsLocation(const ElementsLocation &other) :
|
||||
path_(other.path_),
|
||||
project_(other.project_)
|
||||
m_collection_path(other.m_collection_path),
|
||||
m_project(other.m_project)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::ElementLocation
|
||||
* Constructor, build an ElementLocation from a QMimeData, the mime data format
|
||||
* must be "application/x-qet-element-uri" or "application/x-qet-category-uri".
|
||||
* This location can be null even if format is valid.
|
||||
* @param data
|
||||
*/
|
||||
ElementsLocation::ElementsLocation(const QMimeData *data)
|
||||
{
|
||||
if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri"))
|
||||
setPath(data->text());
|
||||
}
|
||||
|
||||
/**
|
||||
Operateur d'affectation
|
||||
@param other Autre emplacement d'element a affecter
|
||||
*/
|
||||
ElementsLocation &ElementsLocation::operator=(const ElementsLocation &other) {
|
||||
path_ = other.path_;
|
||||
project_ = other.project_;
|
||||
m_collection_path = other.m_collection_path;
|
||||
m_project = other.m_project;
|
||||
return(*this);
|
||||
}
|
||||
|
||||
@@ -71,8 +90,8 @@ ElementsLocation &ElementsLocation::operator=(const ElementsLocation &other) {
|
||||
*/
|
||||
bool ElementsLocation::operator==(const ElementsLocation &other) const {
|
||||
return(
|
||||
path_ == other.path_ &&\
|
||||
project_ == other.project_
|
||||
m_collection_path == other.m_collection_path &&\
|
||||
m_project == other.m_project
|
||||
);
|
||||
}
|
||||
|
||||
@@ -83,8 +102,8 @@ bool ElementsLocation::operator==(const ElementsLocation &other) const {
|
||||
*/
|
||||
bool ElementsLocation::operator!=(const ElementsLocation &other) const {
|
||||
return(
|
||||
path_ != other.path_ ||\
|
||||
project_ != other.project_
|
||||
m_collection_path != other.m_collection_path ||\
|
||||
m_project != other.m_project
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,32 +112,198 @@ bool ElementsLocation::operator!=(const ElementsLocation &other) const {
|
||||
*/
|
||||
QString ElementsLocation::baseName() const {
|
||||
QRegExp regexp("^.*([^/]+)\\.elmt$");
|
||||
if (regexp.exactMatch(path_)) {
|
||||
if (regexp.exactMatch(m_collection_path)) {
|
||||
return(regexp.capturedTexts().at(1));
|
||||
}
|
||||
return(QString());
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le chemin virtuel de cet emplacement
|
||||
*/
|
||||
QString ElementsLocation::path() const {
|
||||
return(path_);
|
||||
* @brief ElementsLocation::collectionPath
|
||||
* Return the path of the represented element relative to collection
|
||||
* if @protocol is true the path is prepended by the collection type (common://, custom:// or embed://)
|
||||
* else if false, only the collection path is returned without the collection type.
|
||||
* @param protocol
|
||||
* @return the path
|
||||
*/
|
||||
QString ElementsLocation::collectionPath(bool protocol) const
|
||||
{
|
||||
if (protocol)
|
||||
return m_collection_path;
|
||||
else
|
||||
{
|
||||
QString path = m_collection_path;
|
||||
return path.remove(QRegularExpression("common://|custom://|embed://"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Change le chemin virtuel de cet emplacement
|
||||
@param p Nouveau chemin virtuel
|
||||
*/
|
||||
void ElementsLocation::setPath(const QString &p) {
|
||||
* @brief ElementsLocation::projectCollectionPath
|
||||
* @return The path is in form : project0+embed://dir/subdir/myElement.elmt
|
||||
* If this item represent a file system thing, return a null QString;
|
||||
*/
|
||||
QString ElementsLocation::projectCollectionPath() const
|
||||
{
|
||||
if (isFileSystem())
|
||||
return QString();
|
||||
else
|
||||
return QString("project" + QString::number(QETApp::projectId(m_project)) + "+" + collectionPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::fileSystemPath
|
||||
* @return The file system path of this element, (the separator is always '/' see QDir::toNativeSeparators())
|
||||
* If this element is embedded in a project return an empty string;
|
||||
*/
|
||||
QString ElementsLocation::fileSystemPath() const
|
||||
{
|
||||
if (!m_project)
|
||||
return m_file_system_path;
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::path
|
||||
* @return The path of this location.
|
||||
* OBSOLETE, use instead collectionPath(true)
|
||||
*/
|
||||
QString ElementsLocation::path() const {
|
||||
return(m_collection_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::setPath
|
||||
* Set the path of this item.
|
||||
* If the path is for a file collection, the path can be in file system or relative to the beginning
|
||||
* of the colection, in this case the path must start with (common:// or custom://).
|
||||
* @param path
|
||||
* @return true if the element pointed by path exist, else false
|
||||
*/
|
||||
bool ElementsLocation::setPath(const QString &path)
|
||||
{
|
||||
QString tmp_path = path;
|
||||
#ifdef Q_OS_WIN32
|
||||
// sous Windows : on convertit les backslashs en slashs
|
||||
path_ = QDir::fromNativeSeparators(p);
|
||||
#else
|
||||
// ailleurs : si on detecte des backslashs, on tente d'etre "compatible"
|
||||
path_ = p;
|
||||
path_.replace("\\", "/");
|
||||
//On windows, we convert backslash to slash
|
||||
tmp_path = QDir::fromNativeSeparators(path);
|
||||
|
||||
#endif
|
||||
|
||||
//There is a project, the path is for an embedded coolection.
|
||||
if (m_project)
|
||||
{
|
||||
if (path.startsWith("embed://"))
|
||||
{
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//The path start with project, we get the project and the path from the string
|
||||
else if (tmp_path.startsWith("project"))
|
||||
{
|
||||
QRegExp rx("^project([0-9]+)\\+(embed:\\/\\/.*)$", Qt::CaseInsensitive);
|
||||
if (rx.exactMatch(tmp_path))
|
||||
{
|
||||
bool conv_ok;
|
||||
uint project_id = rx.capturedTexts().at(1).toUInt(&conv_ok);
|
||||
if (conv_ok)
|
||||
{
|
||||
QETProject *project = QETApp::project(project_id);
|
||||
if (project)
|
||||
{
|
||||
m_collection_path = rx.capturedTexts().at(2);
|
||||
m_project = project;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//The path is in file system, the given path is relative to common or custom collection
|
||||
else if (path.startsWith("common://") || path.startsWith("custom://"))
|
||||
{
|
||||
QString p;
|
||||
if (path.startsWith("common://"))
|
||||
{
|
||||
tmp_path.remove("common://");
|
||||
p = QETApp::commonElementsDirN() + "/" + tmp_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_path.remove("custom://");
|
||||
p = QETApp::customElementsDirN() + "/" + tmp_path;
|
||||
}
|
||||
|
||||
//This is an element
|
||||
if (path.endsWith(".elmt"))
|
||||
{
|
||||
QFile file(p);
|
||||
if (file.exists())
|
||||
{
|
||||
m_file_system_path = p;
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//They must be a directory
|
||||
else
|
||||
{
|
||||
QDir dir(p);
|
||||
if(dir.exists())
|
||||
{
|
||||
m_file_system_path = p;
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//In this case, the path is supposed to be relative to the file system.
|
||||
else
|
||||
{
|
||||
QString path_ = path;
|
||||
if(path_.endsWith(".elmt"))
|
||||
{
|
||||
m_file_system_path = path_;
|
||||
if (path_.startsWith(QETApp::commonElementsDirN()))
|
||||
{
|
||||
path_.remove(QETApp::commonElementsDirN()+="/");
|
||||
path_.prepend("common://");
|
||||
m_collection_path = path_;
|
||||
}
|
||||
else if (path_.startsWith(QETApp::customElementsDirN()))
|
||||
{
|
||||
path_.remove(QETApp::customElementsDirN()+="/");
|
||||
path_.prepend("custom://");
|
||||
m_collection_path = path_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file_system_path = path_;
|
||||
if (path_.startsWith(QETApp::commonElementsDirN()))
|
||||
{
|
||||
path_.remove(QETApp::commonElementsDirN()+="/");
|
||||
path_.prepend("common://");
|
||||
m_collection_path = path_;
|
||||
}
|
||||
else if (path_.startsWith(QETApp::customElementsDirN()))
|
||||
{
|
||||
path_.remove(QETApp::customElementsDirN()+="/");
|
||||
path_.prepend("custom://");
|
||||
m_collection_path = path_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,9 +314,9 @@ void ElementsLocation::setPath(const QString &p) {
|
||||
chemin d'un element.
|
||||
*/
|
||||
bool ElementsLocation::addToPath(const QString &string) {
|
||||
if (path_.endsWith(".elmt", Qt::CaseInsensitive)) return(false);
|
||||
if (!path_.endsWith("/") && !string.startsWith("/")) path_ += "/";
|
||||
path_ += string;
|
||||
if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive)) return(false);
|
||||
if (!m_collection_path.endsWith("/") && !string.startsWith("/")) m_collection_path += "/";
|
||||
m_collection_path += string;
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -142,7 +327,7 @@ bool ElementsLocation::addToPath(const QString &string) {
|
||||
ElementsLocation ElementsLocation::parent() const {
|
||||
ElementsLocation copy(*this);
|
||||
QRegExp re1("^([a-z]+://)(.*)/*$");
|
||||
if (re1.exactMatch(path_)) {
|
||||
if (re1.exactMatch(m_collection_path)) {
|
||||
QString path_proto = re1.capturedTexts().at(1);
|
||||
QString path_path = re1.capturedTexts().at(2);
|
||||
QString parent_path = path_path.remove(QRegExp("/*[^/]+$"));
|
||||
@@ -156,7 +341,7 @@ ElementsLocation ElementsLocation::parent() const {
|
||||
un projet.
|
||||
*/
|
||||
QETProject *ElementsLocation::project() const {
|
||||
return(project_);
|
||||
return(m_project);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,14 +349,14 @@ QETProject *ElementsLocation::project() const {
|
||||
Indiquer 0 pour que cet emplacement ne soit plus lie a un projet.
|
||||
*/
|
||||
void ElementsLocation::setProject(QETProject *project) {
|
||||
project_ = project;
|
||||
m_project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si l'emplacement semble utilisable (chemin virtuel non vide).
|
||||
*/
|
||||
bool ElementsLocation::isNull() const {
|
||||
return(path_.isEmpty());
|
||||
return(m_collection_path.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,13 +364,13 @@ bool ElementsLocation::isNull() const {
|
||||
*/
|
||||
QString ElementsLocation::toString() const {
|
||||
QString result;
|
||||
if (project_) {
|
||||
int project_id = QETApp::projectId(project_);
|
||||
if (m_project) {
|
||||
int project_id = QETApp::projectId(m_project);
|
||||
if (project_id != -1) {
|
||||
result += "project" + QString().setNum(project_id) + "+";
|
||||
}
|
||||
}
|
||||
result += path_;
|
||||
result += m_collection_path;
|
||||
return(result);
|
||||
}
|
||||
|
||||
@@ -202,16 +387,16 @@ void ElementsLocation::fromString(const QString &string) {
|
||||
if (conv_ok) {
|
||||
QETProject *the_project = QETApp::project(project_id);
|
||||
if (the_project) {
|
||||
path_ = embedded.capturedTexts().at(2);
|
||||
project_ = the_project;
|
||||
m_collection_path = embedded.capturedTexts().at(2);
|
||||
m_project = the_project;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallback : le chemin devient la chaine complete et aucun projet n'est utilise
|
||||
path_ = string;
|
||||
project_ = 0;
|
||||
m_collection_path = string;
|
||||
m_project = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,6 +410,235 @@ ElementsLocation ElementsLocation::locationFromString(const QString &string) {
|
||||
return(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::isElement
|
||||
* @return true if this location represent an element
|
||||
*/
|
||||
bool ElementsLocation::isElement() const {
|
||||
return m_collection_path.endsWith(".elmt");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::isDirectory
|
||||
* @return true if this location represent a directory
|
||||
*/
|
||||
bool ElementsLocation::isDirectory() const {
|
||||
return (!isElement() && !m_collection_path.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::isFileSystem
|
||||
* @return
|
||||
*/
|
||||
bool ElementsLocation::isFileSystem() const
|
||||
{
|
||||
if (m_project) return false;
|
||||
if (m_file_system_path.isEmpty()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::isProject
|
||||
* @return True if this location represent an item from a project.
|
||||
*/
|
||||
bool ElementsLocation::isProject() const
|
||||
{
|
||||
if (m_project && !m_collection_path.isEmpty())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::exist
|
||||
* @return True if this location represent an existing directory or element.
|
||||
*/
|
||||
bool ElementsLocation::exist() const
|
||||
{
|
||||
if (m_project)
|
||||
return m_project->embeddedElementCollection()->exist(collectionPath(false));
|
||||
else
|
||||
{
|
||||
if (fileSystemPath().isEmpty()) return false;
|
||||
|
||||
if (isDirectory())
|
||||
{
|
||||
QDir dir(fileSystemPath());
|
||||
return dir.exists();
|
||||
}
|
||||
else if (isElement())
|
||||
return QFile::exists(fileSystemPath());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::projectCollection
|
||||
* @return If this location represente a item in an embedded project collection, return this collection
|
||||
* else return nullptr.
|
||||
*/
|
||||
XmlElementCollection *ElementsLocation::projectCollection() const
|
||||
{
|
||||
if (m_project)
|
||||
return m_project->embeddedElementCollection();
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::nameList
|
||||
* @return the namelist of the represented element or directory.
|
||||
* If namelist can't be set, return a empty namelist
|
||||
*/
|
||||
NamesList ElementsLocation::nameList()
|
||||
{
|
||||
NamesList nl;
|
||||
|
||||
if (isElement())
|
||||
nl.fromXml(xml());
|
||||
|
||||
if (isDirectory())
|
||||
{
|
||||
if (m_project)
|
||||
nl.fromXml(m_project->embeddedElementCollection()->directory(collectionPath(false)));
|
||||
else
|
||||
{
|
||||
//Open the qet_directory file, to get the traductions name of this dir
|
||||
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
||||
if (dir_conf.exists() && dir_conf.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
//Get the content of the file
|
||||
QDomDocument document;
|
||||
if (document.setContent(&dir_conf))
|
||||
{
|
||||
QDomElement root = document.documentElement();
|
||||
if (root.tagName() == "qet-directory")
|
||||
nl.fromXml(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::xml
|
||||
* @return The definition of this element.
|
||||
* The definition can be null.
|
||||
*/
|
||||
QDomElement ElementsLocation::xml()
|
||||
{
|
||||
if (!m_xml.isNull())
|
||||
return m_xml;
|
||||
|
||||
if (!m_project)
|
||||
{
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
m_xml = docu.documentElement().cloneNode().toElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString str = m_collection_path;
|
||||
if (isElement())
|
||||
{
|
||||
QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://"));
|
||||
m_xml = element.firstChildElement("definition");
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement element = m_project->embeddedElementCollection()->directory(str.remove("embed://"));
|
||||
m_xml = element;
|
||||
}
|
||||
}
|
||||
|
||||
return m_xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::uuid
|
||||
* @return The uuid of the pointed element
|
||||
*/
|
||||
QUuid ElementsLocation::uuid()
|
||||
{
|
||||
if (!m_uuid.isNull()) return m_uuid;
|
||||
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
|
||||
if (!list_.isEmpty())
|
||||
m_uuid = QUuid(list_.first().attribute("uuid"));
|
||||
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::icon
|
||||
* @return The icon of the represented element.
|
||||
* If icon can't be set, return a null QIcon
|
||||
*/
|
||||
QIcon ElementsLocation::icon()
|
||||
{
|
||||
if (!m_icon.isNull()) return m_icon;
|
||||
|
||||
if (!m_project)
|
||||
{
|
||||
ElementsCollectionCache *cache = QETApp::collectionCache();
|
||||
if (cache->fetchElement(*this))
|
||||
m_icon = QIcon(cache->pixmap());
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementFactory *factory = ElementFactory::Instance();
|
||||
int state;
|
||||
Element *elmt = factory->createElement(*this, 0, &state);
|
||||
|
||||
if (state == 0)
|
||||
m_icon = QIcon(elmt->pixmap());
|
||||
}
|
||||
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::name
|
||||
* @return The name of the represented element in the current local
|
||||
*/
|
||||
QString ElementsLocation::name()
|
||||
{
|
||||
if (!m_project)
|
||||
{
|
||||
ElementsCollectionCache *cache = QETApp::collectionCache();
|
||||
if (cache->fetchElement(*this))
|
||||
return cache->name();
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
else
|
||||
{
|
||||
NamesList nl;
|
||||
nl.fromXml(xml());
|
||||
return nl.name(fileName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::fileName
|
||||
* @return Return the file name of this element whatever the storage system (file system, xml collection)
|
||||
*/
|
||||
QString ElementsLocation::fileName() const
|
||||
{
|
||||
// if (m_collection_path.isEmpty()) return QString();
|
||||
|
||||
// QStringList qsl = m_collection_path.split("/");
|
||||
// if (qsl.isEmpty()) return QString();
|
||||
// else return qsl.last();
|
||||
return baseName();
|
||||
}
|
||||
|
||||
/**
|
||||
@param location A standard element location
|
||||
@return a hash identifying this location
|
||||
|
||||
@@ -17,46 +17,74 @@
|
||||
*/
|
||||
#ifndef ELEMENTS_LOCATION_H
|
||||
#define ELEMENTS_LOCATION_H
|
||||
#include <QtCore>
|
||||
|
||||
#include "nameslist.h"
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
class QETProject;
|
||||
class XmlElementCollection;
|
||||
|
||||
/**
|
||||
Cette classe represente la localisation, l'emplacement d'un element ou
|
||||
d'une categorie, voire d'une collection... dans une collection. Elle
|
||||
encapsule un chemin virtuel.
|
||||
*/
|
||||
class ElementsLocation {
|
||||
// constructors, destructor et operateur d'affectation
|
||||
class ElementsLocation
|
||||
{
|
||||
public:
|
||||
ElementsLocation();
|
||||
explicit ElementsLocation(const QString &, QETProject * = 0);
|
||||
ElementsLocation(const ElementsLocation &);
|
||||
virtual ~ElementsLocation();
|
||||
ElementsLocation &operator=(const ElementsLocation &);
|
||||
bool operator==(const ElementsLocation &) const;
|
||||
bool operator!=(const ElementsLocation &) const;
|
||||
ElementsLocation();
|
||||
ElementsLocation(const QString &path, QETProject *project = nullptr);
|
||||
ElementsLocation(const ElementsLocation &);
|
||||
ElementsLocation(const QMimeData *data);
|
||||
virtual ~ElementsLocation();
|
||||
ElementsLocation &operator=(const ElementsLocation &);
|
||||
bool operator==(const ElementsLocation &) const;
|
||||
bool operator!=(const ElementsLocation &) const;
|
||||
|
||||
// methods
|
||||
public:
|
||||
QString baseName() const;
|
||||
QString path() const;
|
||||
void setPath(const QString &);
|
||||
bool addToPath(const QString &);
|
||||
ElementsLocation parent() const;
|
||||
QETProject *project() const;
|
||||
void setProject(QETProject *);
|
||||
bool isNull() const;
|
||||
QString toString() const;
|
||||
void fromString(const QString &);
|
||||
static ElementsLocation locationFromString(const QString &);
|
||||
QString baseName() const;
|
||||
|
||||
QString collectionPath(bool protocol = true) const;
|
||||
QString projectCollectionPath() const;
|
||||
QString fileSystemPath() const;
|
||||
QString path() const;
|
||||
bool setPath(const QString &path);
|
||||
bool addToPath(const QString &);
|
||||
|
||||
ElementsLocation parent() const;
|
||||
QETProject *project() const;
|
||||
void setProject(QETProject *);
|
||||
bool isNull() const;
|
||||
QString toString() const;
|
||||
void fromString(const QString &);
|
||||
static ElementsLocation locationFromString(const QString &);
|
||||
|
||||
bool isElement() const;
|
||||
bool isDirectory() const;
|
||||
bool isFileSystem() const;
|
||||
bool isProject() const;
|
||||
bool exist() const;
|
||||
|
||||
XmlElementCollection *projectCollection() const;
|
||||
NamesList nameList();
|
||||
|
||||
QDomElement xml();
|
||||
QUuid uuid();
|
||||
QIcon icon();
|
||||
QString name();
|
||||
QString fileName() const;
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QString path_;
|
||||
QETProject *project_;
|
||||
QString m_collection_path;
|
||||
QString m_file_system_path;
|
||||
QETProject *m_project = nullptr;
|
||||
QDomElement m_xml;
|
||||
QUuid m_uuid;
|
||||
QIcon m_icon;
|
||||
|
||||
public:
|
||||
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
||||
static int MetaTypeId; ///< Id of the corresponding Qt meta type
|
||||
};
|
||||
Q_DECLARE_METATYPE(ElementsLocation)
|
||||
uint qHash(const ElementsLocation &);
|
||||
|
||||
@@ -59,31 +59,3 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph
|
||||
//default if nothing match for link_type
|
||||
return (new SimpleElement(location, qgi, state));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementFactory::createElement
|
||||
* @param location : The location of the element
|
||||
* @param parent : parent item for the new element
|
||||
* @param state : state of the creation
|
||||
* @return : the element or nullptr if the creation failed
|
||||
*/
|
||||
Element *ElementFactory::createElement(ElementLocation &location, QGraphicsItem *parent, int *state)
|
||||
{
|
||||
if (!location.isElement() || location.isNull())
|
||||
{
|
||||
if (state) *state = 1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (location.xml().hasAttribute("link_type"))
|
||||
{
|
||||
QString link_type = location.xml().attribute("link_type");
|
||||
if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, parent, state));
|
||||
if (link_type == "master") return (new MasterElement (location, parent, state));
|
||||
if (link_type == "slave") return (new SlaveElement (location, parent, state));
|
||||
if (link_type == "terminal") return (new TerminalElement (location, parent, state));
|
||||
}
|
||||
|
||||
//default if nothing match for link_type
|
||||
return (new SimpleElement(location, parent, state));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define ELEMENTFACTORY_H
|
||||
|
||||
#include <QMutex>
|
||||
#include "elementlocation.h"
|
||||
|
||||
class Element;
|
||||
class ElementsLocation;
|
||||
class QGraphicsItem;
|
||||
@@ -71,7 +71,6 @@ class ElementFactory
|
||||
|
||||
public:
|
||||
Element *createElement (const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
Element *createElement(ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
};
|
||||
//ElementFactory ElementFactory::factory_ = 0;
|
||||
#endif // ELEMENTFACTORY_H
|
||||
|
||||
@@ -90,50 +90,6 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg
|
||||
elmt_state = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CustomElement::CustomElement
|
||||
* Constructor build an element from the location @location
|
||||
* @param location : location of the element
|
||||
* @param parent : parent of element
|
||||
* @param state : pointeur used to know the encountered error at creation...
|
||||
- 0 : No error
|
||||
- 1 : The location don't represent an element
|
||||
- 2 : The location can't be readable
|
||||
- 3 : The location isn't valid / exploitable / usable
|
||||
- 4 : The xml document wasn't an element "definition"
|
||||
- 5 : The attributes of the defintion aren't present and/or valid
|
||||
- 6 : The defintion is empty
|
||||
- 7 : The analyze of an xml element that describe a part of the drawing was failed
|
||||
- 8 : No part of the drawing can be loaded
|
||||
*/
|
||||
CustomElement::CustomElement(ElementLocation &location, QGraphicsItem *parent, int *state) :
|
||||
FixedElement(parent),
|
||||
elmt_state(-1),
|
||||
m_location(location),
|
||||
forbid_antialiasing(false)
|
||||
|
||||
{
|
||||
if (!location.isElement())
|
||||
{
|
||||
if (state) *state = 1;
|
||||
elmt_state = 1;
|
||||
}
|
||||
|
||||
//Start from empty lists.
|
||||
list_lines_.clear();
|
||||
list_rectangles_.clear();
|
||||
list_circles_.clear();
|
||||
list_polygons_.clear();
|
||||
list_arcs_.clear();
|
||||
|
||||
buildFromXml(location.xml(), &elmt_state);
|
||||
if (state) *state = elmt_state;
|
||||
if (elmt_state) return;
|
||||
|
||||
if (state) *state = 0;
|
||||
elmt_state = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Construit l'element personnalise a partir d'un element XML representant sa
|
||||
definition.
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "fixedelement.h"
|
||||
#include "nameslist.h"
|
||||
#include "elementslocation.h"
|
||||
#include "elementlocation.h"
|
||||
#include <QPicture>
|
||||
|
||||
class ElementTextItem;
|
||||
@@ -38,7 +37,6 @@ class CustomElement : public FixedElement
|
||||
// constructors, destructor
|
||||
public:
|
||||
CustomElement (const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
CustomElement (ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
|
||||
virtual ~CustomElement();
|
||||
|
||||
@@ -50,7 +48,6 @@ class CustomElement : public FixedElement
|
||||
int elmt_state; // hold the error code in case the instanciation fails, or 0 if everything went well
|
||||
NamesList names;
|
||||
ElementsLocation location_;
|
||||
ElementLocation m_location;
|
||||
QPicture drawing;
|
||||
QPicture low_zoom_drawing;
|
||||
QList<Terminal *> list_terminals;
|
||||
|
||||
@@ -35,14 +35,6 @@ MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qg
|
||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||
}
|
||||
|
||||
MasterElement::MasterElement(ElementLocation &location, QGraphicsItem *parent, int *state) :
|
||||
CustomElement(location, parent, state),
|
||||
cri_ (nullptr)
|
||||
{
|
||||
link_type_ = Master;
|
||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MasterElement::~MasterElement
|
||||
* default destructor
|
||||
|
||||
@@ -34,7 +34,6 @@ class MasterElement : public CustomElement
|
||||
|
||||
public:
|
||||
explicit MasterElement(const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
explicit MasterElement(ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
~MasterElement();
|
||||
|
||||
virtual void linkToElement (Element *elmt);
|
||||
|
||||
@@ -51,34 +51,6 @@ ReportElement::ReportElement(const ElementsLocation &location, QString link_type
|
||||
}
|
||||
}
|
||||
|
||||
ReportElement::ReportElement(ElementLocation &location, QString link_type, QGraphicsItem *parent, int *state) :
|
||||
CustomElement(location, parent, state),
|
||||
m_text_field (nullptr),
|
||||
m_watched_conductor (nullptr)
|
||||
{
|
||||
/*
|
||||
* Get text tagged label. This is work for report
|
||||
* create after the revision 3559.
|
||||
* for report create before, we take the first text field
|
||||
* because report haven't got a text field tagged label
|
||||
*/
|
||||
m_text_field = taggedText("label");
|
||||
if (!m_text_field && !texts().isEmpty())
|
||||
m_text_field = texts().first();
|
||||
if (m_text_field)
|
||||
m_text_field -> setNoEditable();
|
||||
|
||||
link_type == "next_report"? link_type_=NextReport : link_type_=PreviousReport;
|
||||
link_type == "next_report"? inverse_report=PreviousReport : inverse_report=NextReport;
|
||||
|
||||
//We make these connections, to be always aware about the conductor properties
|
||||
if (terminals().size())
|
||||
{
|
||||
connect (terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
|
||||
connect (terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ReportElement::~ReportElement
|
||||
* Destructor
|
||||
|
||||
@@ -33,7 +33,6 @@ class ReportElement : public CustomElement
|
||||
|
||||
public :
|
||||
explicit ReportElement(const ElementsLocation &,QString link_type, QGraphicsItem * = 0, int * = 0);
|
||||
explicit ReportElement(ElementLocation &location, QString link_type, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
~ReportElement();
|
||||
virtual void linkToElement(Element *);
|
||||
virtual void unlinkAllElements();
|
||||
|
||||
@@ -33,14 +33,6 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg
|
||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||
}
|
||||
|
||||
SimpleElement::SimpleElement(ElementLocation &location, QGraphicsItem *parent, int *state) :
|
||||
CustomElement(location, parent, state),
|
||||
m_comment_item (nullptr)
|
||||
{
|
||||
link_type_ = Simple;
|
||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SimpleElement::~SimpleElement
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,6 @@ class SimpleElement : public CustomElement {
|
||||
|
||||
public :
|
||||
explicit SimpleElement(const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
explicit SimpleElement(ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
~SimpleElement();
|
||||
|
||||
virtual void initLink(QETProject *project);
|
||||
|
||||
@@ -36,13 +36,6 @@ SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi,
|
||||
link_type_ = Slave;
|
||||
}
|
||||
|
||||
SlaveElement::SlaveElement(ElementLocation &location, QGraphicsItem *parent, int *state) :
|
||||
CustomElement(location, parent, state)
|
||||
{
|
||||
Xref_item = nullptr;
|
||||
link_type_ = Slave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::~SlaveElement
|
||||
* default destructor
|
||||
|
||||
@@ -25,7 +25,6 @@ class SlaveElement : public CustomElement
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
explicit SlaveElement(ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
~SlaveElement();
|
||||
virtual void linkToElement(Element *elmt);
|
||||
virtual void unlinkAllElements();
|
||||
|
||||
@@ -31,10 +31,4 @@ TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem
|
||||
link_type_ = Terminale;
|
||||
}
|
||||
|
||||
TerminalElement::TerminalElement(ElementLocation &location, QGraphicsItem *parent, int *state) :
|
||||
CustomElement(location, parent, state)
|
||||
{
|
||||
link_type_ = Terminale;
|
||||
}
|
||||
|
||||
TerminalElement::~TerminalElement() {}
|
||||
|
||||
@@ -25,7 +25,6 @@ class TerminalElement : public CustomElement
|
||||
Q_OBJECT
|
||||
public:
|
||||
TerminalElement(const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
|
||||
TerminalElement (ElementLocation &location, QGraphicsItem *parent = nullptr, int *state = nullptr);
|
||||
~TerminalElement();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user