mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Enable the drag and drop inside the new element panel
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4284 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2015 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
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 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.
|
||||
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/>.
|
||||
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"
|
||||
@@ -25,10 +25,10 @@
|
||||
* @param path : path of item in file system
|
||||
*/
|
||||
ElementLocation::ElementLocation(QString path):
|
||||
m_project(nullptr)
|
||||
m_project(nullptr)
|
||||
{
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,10 +37,10 @@ ElementLocation::ElementLocation(QString path):
|
||||
* @param project : project
|
||||
*/
|
||||
ElementLocation::ElementLocation(QString path, QETProject *project) :
|
||||
m_project(project)
|
||||
m_project(project)
|
||||
{
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
if (!path.isEmpty())
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
ElementLocation::~ElementLocation()
|
||||
@@ -56,68 +56,100 @@ ElementLocation::~ElementLocation()
|
||||
*/
|
||||
bool ElementLocation::setPath(QString path)
|
||||
{
|
||||
if (!path.endsWith(".elmt")) return false;
|
||||
QString tmp_path = path;
|
||||
|
||||
QString tmp_path = path;
|
||||
//The path is in file system
|
||||
if (!m_project)
|
||||
{
|
||||
//The given path is relative to common or custom collection
|
||||
if (path.startsWith("common://") || path.startsWith("custom://"))
|
||||
{
|
||||
QString p;
|
||||
if (path.startsWith("common://"))
|
||||
{
|
||||
tmp_path.remove("common://");
|
||||
p = QETApp::commonElementsDir() + tmp_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_path.remove("custom://");
|
||||
p = QETApp::customElementsDir() + tmp_path;
|
||||
}
|
||||
|
||||
//The path is in file system
|
||||
if (!m_project)
|
||||
{
|
||||
//Common collection
|
||||
if (path.startsWith("common://"))
|
||||
{
|
||||
tmp_path.remove("common://");
|
||||
QString p = QETApp::commonElementsDir() + tmp_path;
|
||||
QFile file(p);
|
||||
if (file.exists())
|
||||
{
|
||||
m_file_system_path = p;
|
||||
m_collection_path = path;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Custom collection
|
||||
if (path.startsWith("custom://"))
|
||||
{
|
||||
tmp_path.remove("custom://");
|
||||
QString p = QETApp::customElementsDir() + tmp_path;
|
||||
QFile file(p);
|
||||
if (file.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
|
||||
{
|
||||
QFile file(path);
|
||||
if (file.exists())
|
||||
{
|
||||
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("common://");
|
||||
m_collection_path = path;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//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"))
|
||||
{
|
||||
QFile file(path);
|
||||
if (file.exists())
|
||||
{
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QDir dir(path);
|
||||
if (dir.exists())
|
||||
{
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -136,38 +168,52 @@ bool ElementLocation::isNull() const
|
||||
*/
|
||||
void ElementLocation::setProject(QETProject *project)
|
||||
{
|
||||
m_project = 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::collectionPath
|
||||
* @return the colletion relative to the collection
|
||||
*/
|
||||
QString ElementLocation::collectionPath() const
|
||||
{
|
||||
return m_collection_path;
|
||||
QString ElementLocation::collectionPath() const {
|
||||
return m_collection_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementLocation::fileSystemPath
|
||||
* @return The file system path of this element,
|
||||
* @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 QDir::fromNativeSeparators(m_file_system_path);
|
||||
else
|
||||
return QString();
|
||||
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;
|
||||
QETProject *ElementLocation::project() const {
|
||||
return m_project;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,18 +223,18 @@ QETProject *ElementLocation::project() const
|
||||
*/
|
||||
QDomElement ElementLocation::xml()
|
||||
{
|
||||
if (!m_xml.isNull())
|
||||
return m_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();
|
||||
}
|
||||
if (!m_project)
|
||||
{
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
m_xml = docu.documentElement().cloneNode().toElement();
|
||||
}
|
||||
|
||||
return m_xml;
|
||||
return m_xml;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,15 +243,13 @@ QDomElement ElementLocation::xml()
|
||||
*/
|
||||
QUuid ElementLocation::uuid()
|
||||
{
|
||||
if (!m_uuid.isNull()) return m_uuid;
|
||||
if (!m_uuid.isNull()) return m_uuid;
|
||||
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
|
||||
if (!list_.isEmpty())
|
||||
m_uuid = QUuid(list_.first().attribute("uuid"));
|
||||
// else
|
||||
// qDebug() << "The element : " << m_file_system_path << "haven't got an uuid, please edit and save this element with element editor to create an uuid";
|
||||
if (!list_.isEmpty())
|
||||
m_uuid = QUuid(list_.first().attribute("uuid"));
|
||||
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user