mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +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:
@@ -163,3 +163,17 @@ bool ElementCollectionItem::isElement() const {
|
|||||||
bool ElementCollectionItem::isValid() const {
|
bool ElementCollectionItem::isValid() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementCollectionItem::items
|
||||||
|
* @return all child and subchild subsubchild... contained by this item
|
||||||
|
* This item isn't stored in the list
|
||||||
|
*/
|
||||||
|
QList<ElementCollectionItem *> ElementCollectionItem::items() const
|
||||||
|
{
|
||||||
|
QList<ElementCollectionItem *> list;
|
||||||
|
list.append(m_child_items);
|
||||||
|
foreach(ElementCollectionItem *eci, m_child_items)
|
||||||
|
list.append(eci->items());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class ElementCollectionItem
|
|||||||
virtual bool isDir() const;
|
virtual bool isDir() const;
|
||||||
virtual bool isElement() const;
|
virtual bool isElement() const;
|
||||||
virtual bool isValid() const;
|
virtual bool isValid() const;
|
||||||
|
virtual QList <ElementCollectionItem *> items() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ElementCollectionItem *m_parent_item;
|
ElementCollectionItem *m_parent_item;
|
||||||
|
|||||||
@@ -56,34 +56,29 @@ ElementLocation::~ElementLocation()
|
|||||||
*/
|
*/
|
||||||
bool ElementLocation::setPath(QString path)
|
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
|
//The path is in file system
|
||||||
if (!m_project)
|
if (!m_project)
|
||||||
{
|
{
|
||||||
//Common collection
|
//The given path is relative to common or custom collection
|
||||||
|
if (path.startsWith("common://") || path.startsWith("custom://"))
|
||||||
|
{
|
||||||
|
QString p;
|
||||||
if (path.startsWith("common://"))
|
if (path.startsWith("common://"))
|
||||||
{
|
{
|
||||||
tmp_path.remove("common://");
|
tmp_path.remove("common://");
|
||||||
QString p = QETApp::commonElementsDir() + tmp_path;
|
p = QETApp::commonElementsDir() + tmp_path;
|
||||||
QFile file(p);
|
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
m_file_system_path = p;
|
|
||||||
m_collection_path = path;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Custom collection
|
|
||||||
if (path.startsWith("custom://"))
|
|
||||||
{
|
{
|
||||||
tmp_path.remove("custom://");
|
tmp_path.remove("custom://");
|
||||||
QString p = QETApp::customElementsDir() + tmp_path;
|
p = QETApp::customElementsDir() + tmp_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is an element
|
||||||
|
if (path.endsWith(".elmt"))
|
||||||
|
{
|
||||||
QFile file(p);
|
QFile file(p);
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
{
|
{
|
||||||
@@ -91,11 +86,25 @@ bool ElementLocation::setPath(QString path)
|
|||||||
m_collection_path = path;
|
m_collection_path = path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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.
|
//In this case, the path is supposed to be relative to the file system.
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(path.endsWith(".elmt"))
|
||||||
{
|
{
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
@@ -110,13 +119,36 @@ bool ElementLocation::setPath(QString path)
|
|||||||
else if (path.startsWith(QETApp::customElementsDir()))
|
else if (path.startsWith(QETApp::customElementsDir()))
|
||||||
{
|
{
|
||||||
path.remove(QETApp::customElementsDir());
|
path.remove(QETApp::customElementsDir());
|
||||||
path.prepend("common://");
|
path.prepend("custom://");
|
||||||
m_collection_path = path;
|
m_collection_path = path;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
return false;
|
||||||
@@ -139,24 +171,39 @@ 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
|
* @brief ElementLocation::collectionPath
|
||||||
* @return the colletion relative to the collection
|
* @return the colletion relative to the collection
|
||||||
*/
|
*/
|
||||||
QString ElementLocation::collectionPath() const
|
QString ElementLocation::collectionPath() const {
|
||||||
{
|
|
||||||
return m_collection_path;
|
return m_collection_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementLocation::fileSystemPath
|
* @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;
|
* If this element is embedded in a project return an empty string;
|
||||||
*/
|
*/
|
||||||
QString ElementLocation::fileSystemPath() const
|
QString ElementLocation::fileSystemPath() const
|
||||||
{
|
{
|
||||||
if (!m_project)
|
if (!m_project)
|
||||||
return QDir::fromNativeSeparators(m_file_system_path);
|
return m_file_system_path;
|
||||||
else
|
else
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -165,8 +212,7 @@ QString ElementLocation::fileSystemPath() const
|
|||||||
* @brief ElementLocation::project
|
* @brief ElementLocation::project
|
||||||
* @return the project of this location if he was set.
|
* @return the project of this location if he was set.
|
||||||
*/
|
*/
|
||||||
QETProject *ElementLocation::project() const
|
QETProject *ElementLocation::project() const {
|
||||||
{
|
|
||||||
return m_project;
|
return m_project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,8 +250,6 @@ QUuid ElementLocation::uuid()
|
|||||||
|
|
||||||
if (!list_.isEmpty())
|
if (!list_.isEmpty())
|
||||||
m_uuid = QUuid(list_.first().attribute("uuid"));
|
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";
|
|
||||||
|
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class QETProject;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ElementLocation class
|
* @brief The ElementLocation class
|
||||||
* This class represent the location of an element in the file system
|
* This class represent the location of an element or a directory in the file system
|
||||||
* or an embedded collection of a project.
|
* or an embedded collection of a project.
|
||||||
* They also provide common things about an element, like the icon, uuid etc...
|
* They also provide common things about an element, like the icon, uuid etc...
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +41,8 @@ class ElementLocation
|
|||||||
bool setPath(QString path);
|
bool setPath(QString path);
|
||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
void setProject(QETProject *project);
|
void setProject(QETProject *project);
|
||||||
|
bool isElement() const;
|
||||||
|
bool isDirectory() const;
|
||||||
|
|
||||||
QString collectionPath() const;
|
QString collectionPath() const;
|
||||||
QString fileSystemPath() const;
|
QString fileSystemPath() const;
|
||||||
|
|||||||
@@ -197,10 +197,21 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction
|
|||||||
QStringList ElementsCollectionModel::mimeTypes() const
|
QStringList ElementsCollectionModel::mimeTypes() const
|
||||||
{
|
{
|
||||||
QStringList mime_list = QAbstractItemModel::mimeTypes();
|
QStringList mime_list = QAbstractItemModel::mimeTypes();
|
||||||
mime_list << "application/x-qet-element-uri";
|
mime_list << "application/x-qet-element-uri" << "application/x-qet-category-uri";
|
||||||
return mime_list;
|
return mime_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementsCollectionModel::items
|
||||||
|
* @return All items handled by this model. The root item isn't stored in the list
|
||||||
|
*/
|
||||||
|
QList<ElementCollectionItem *> ElementsCollectionModel::items() const
|
||||||
|
{
|
||||||
|
QList <ElementCollectionItem *> list;
|
||||||
|
list.append(m_root_item->items());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementsCollectionModel::addCommonCollection
|
* @brief ElementsCollectionModel::addCommonCollection
|
||||||
* Add the common elements collection to this model
|
* Add the common elements collection to this model
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class ElementsCollectionModel : public QAbstractItemModel
|
|||||||
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const;
|
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const;
|
||||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
|
QList <ElementCollectionItem *> items() const;
|
||||||
|
|
||||||
void addCommonCollection();
|
void addCommonCollection();
|
||||||
void addCustomCollection();
|
void addCustomCollection();
|
||||||
|
|||||||
@@ -40,11 +40,14 @@
|
|||||||
*/
|
*/
|
||||||
ElementsCollectionWidget::ElementsCollectionWidget(QWidget *parent):
|
ElementsCollectionWidget::ElementsCollectionWidget(QWidget *parent):
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
|
m_model(nullptr),
|
||||||
m_item_at_context_menu(nullptr)
|
m_item_at_context_menu(nullptr)
|
||||||
{
|
{
|
||||||
setUpWidget();
|
setUpWidget();
|
||||||
setUpAction();
|
setUpAction();
|
||||||
setUpConnection();
|
setUpConnection();
|
||||||
|
|
||||||
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,11 +103,11 @@ void ElementsCollectionWidget::setUpWidget()
|
|||||||
m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
m_main_vlayout->addWidget(m_tree_view);
|
m_main_vlayout->addWidget(m_tree_view);
|
||||||
|
|
||||||
//Setup the element collection model
|
//Setup the progress bar
|
||||||
m_model = new ElementsCollectionModel(m_tree_view);
|
m_progress_bar = new QProgressBar(this);
|
||||||
m_model->addCommonCollection();
|
m_progress_bar->setFormat(tr("Chargement") + " %p%");
|
||||||
m_model->addCustomCollection();
|
m_main_vlayout->addWidget(m_progress_bar);
|
||||||
m_tree_view->setModel(m_model);
|
m_progress_bar->hide();
|
||||||
|
|
||||||
m_context_menu = new QMenu(this);
|
m_context_menu = new QMenu(this);
|
||||||
}
|
}
|
||||||
@@ -345,13 +348,25 @@ void ElementsCollectionWidget::newElement()
|
|||||||
*/
|
*/
|
||||||
void ElementsCollectionWidget::reload()
|
void ElementsCollectionWidget::reload()
|
||||||
{
|
{
|
||||||
|
m_progress_bar->show();
|
||||||
ElementsCollectionModel *new_model = new ElementsCollectionModel(m_tree_view);
|
ElementsCollectionModel *new_model = new ElementsCollectionModel(m_tree_view);
|
||||||
new_model->addCommonCollection();
|
new_model->addCommonCollection();
|
||||||
new_model->addCustomCollection();
|
new_model->addCustomCollection();
|
||||||
|
|
||||||
|
QList <ElementCollectionItem *> list = new_model->items();
|
||||||
|
m_progress_bar->setMaximum(list.size());
|
||||||
|
m_progress_bar->setValue(0);
|
||||||
|
foreach (ElementCollectionItem *item, new_model->items())
|
||||||
|
{
|
||||||
|
item->name();
|
||||||
|
m_progress_bar->setValue(m_progress_bar->value() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
m_tree_view->setModel(new_model);
|
m_tree_view->setModel(new_model);
|
||||||
delete m_model;
|
if (m_model) delete m_model;
|
||||||
m_model = new_model;
|
m_model = new_model;
|
||||||
expandFirstItems();
|
expandFirstItems();
|
||||||
|
m_progress_bar->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class QVBoxLayout;
|
|||||||
class QMenu;
|
class QMenu;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class ElementCollectionItem;
|
class ElementCollectionItem;
|
||||||
|
class QProgressBar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ElementsCollectionWidget class
|
* @brief The ElementsCollectionWidget class
|
||||||
@@ -69,6 +70,7 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
QVBoxLayout *m_main_vlayout;
|
QVBoxLayout *m_main_vlayout;
|
||||||
QMenu *m_context_menu;
|
QMenu *m_context_menu;
|
||||||
ElementCollectionItem *m_item_at_context_menu;
|
ElementCollectionItem *m_item_at_context_menu;
|
||||||
|
QProgressBar *m_progress_bar;
|
||||||
|
|
||||||
QAction *m_open_dir,
|
QAction *m_open_dir,
|
||||||
*m_edit_element,
|
*m_edit_element,
|
||||||
|
|||||||
@@ -53,10 +53,8 @@ bool FileElementCollectionItem::setRootPath(QString path)
|
|||||||
{
|
{
|
||||||
m_path = path;
|
m_path = path;
|
||||||
populate();
|
populate();
|
||||||
name();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,8 +71,10 @@ QString FileElementCollectionItem::fileSystemPath() const
|
|||||||
FileElementCollectionItem *parent = static_cast<FileElementCollectionItem*>(m_parent_item);
|
FileElementCollectionItem *parent = static_cast<FileElementCollectionItem*>(m_parent_item);
|
||||||
|
|
||||||
//Get the path of the parent.
|
//Get the path of the parent.
|
||||||
QString path = parent->fileSystemPath();
|
if (parent->isCollectionRoot())
|
||||||
return path + "/" + m_path;
|
return parent->fileSystemPath() + m_path;
|
||||||
|
else
|
||||||
|
return parent->fileSystemPath() + "/" + m_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,19 +135,7 @@ QVariant FileElementCollectionItem::data(int column, int role)
|
|||||||
|
|
||||||
switch (role)
|
switch (role)
|
||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole: {
|
||||||
{
|
|
||||||
//This item have no parent or parent isn't a file element, so it is the root of a collection
|
|
||||||
if (!m_parent_item || m_parent_item->type() != FileElementCollectionItem::Type)
|
|
||||||
{
|
|
||||||
if (m_path == QETApp::commonElementsDir())
|
|
||||||
return QObject::tr("Collection QET");
|
|
||||||
else if (m_path == QETApp::customElementsDir())
|
|
||||||
return QObject::tr("Collection utilisateur");
|
|
||||||
else
|
|
||||||
return QObject::tr("Collection inconnue");
|
|
||||||
}
|
|
||||||
|
|
||||||
return name();
|
return name();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -193,7 +181,12 @@ QMimeData *FileElementCollectionItem::mimeData()
|
|||||||
{
|
{
|
||||||
QMimeData *mime_data = new QMimeData();
|
QMimeData *mime_data = new QMimeData();
|
||||||
mime_data->setText(collectionPath());
|
mime_data->setText(collectionPath());
|
||||||
|
|
||||||
|
if (isElement())
|
||||||
mime_data->setData("application/x-qet-element-uri", collectionPath().toLatin1());
|
mime_data->setData("application/x-qet-element-uri", collectionPath().toLatin1());
|
||||||
|
else
|
||||||
|
mime_data->setData("application/x-qet-category-uri", collectionPath().toLatin1());
|
||||||
|
|
||||||
return mime_data;
|
return mime_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +200,9 @@ QMimeData *FileElementCollectionItem::mimeData()
|
|||||||
bool FileElementCollectionItem::canDropMimeData(const QMimeData *data, Qt::DropAction action, int column) const
|
bool FileElementCollectionItem::canDropMimeData(const QMimeData *data, Qt::DropAction action, int column) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(action); Q_UNUSED(column);
|
Q_UNUSED(action); Q_UNUSED(column);
|
||||||
|
if (isCommonCollection()) return false;
|
||||||
|
|
||||||
if (data->hasFormat("application/x-qet-element-uri") &&
|
if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri"))
|
||||||
fileSystemPath().startsWith(QETApp::customElementsDir()))
|
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@@ -224,7 +217,18 @@ bool FileElementCollectionItem::canDropMimeData(const QMimeData *data, Qt::DropA
|
|||||||
*/
|
*/
|
||||||
bool FileElementCollectionItem::dropMimeData(const QMimeData *data, Qt::DropAction action, int column)
|
bool FileElementCollectionItem::dropMimeData(const QMimeData *data, Qt::DropAction action, int column)
|
||||||
{
|
{
|
||||||
Q_UNUSED(data); Q_UNUSED(action); Q_UNUSED(column);
|
Q_UNUSED(action); Q_UNUSED(column);
|
||||||
|
if (isCommonCollection()) return false;
|
||||||
|
|
||||||
|
FileElementCollectionItem *feci = this;
|
||||||
|
if (isElement() && parent() && parent()->type() == FileElementCollectionItem::Type)
|
||||||
|
feci = static_cast<FileElementCollectionItem *>(parent());
|
||||||
|
|
||||||
|
if (data->hasFormat("application/x-qet-element-uri"))
|
||||||
|
return feci->handleElementDrop(data);
|
||||||
|
else if (data->hasFormat("application/x-qet-category-uri"))
|
||||||
|
return feci->handleDirectoryDrop(data);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,6 +306,17 @@ QString FileElementCollectionItem::name()
|
|||||||
if (!m_name.isNull()) return m_name;
|
if (!m_name.isNull()) return m_name;
|
||||||
|
|
||||||
else if (isDir())
|
else if (isDir())
|
||||||
|
{
|
||||||
|
if (isCollectionRoot())
|
||||||
|
{
|
||||||
|
if (m_path == QETApp::commonElementsDir())
|
||||||
|
m_name = QObject::tr("Collection QET");
|
||||||
|
else if (m_path == QETApp::customElementsDir())
|
||||||
|
m_name = QObject::tr("Collection utilisateur");
|
||||||
|
else
|
||||||
|
m_name = QObject::tr("Collection inconnue");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
//Open the qet_directory file, to get the traductions name of this dir
|
//Open the qet_directory file, to get the traductions name of this dir
|
||||||
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
||||||
@@ -325,6 +340,7 @@ QString FileElementCollectionItem::name()
|
|||||||
nl.fromXml(root);
|
nl.fromXml(root);
|
||||||
m_name = nl.name();
|
m_name = nl.name();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (isElement())
|
else if (isElement())
|
||||||
{
|
{
|
||||||
ElementLocation loc(collectionPath());
|
ElementLocation loc(collectionPath());
|
||||||
@@ -345,7 +361,6 @@ void FileElementCollectionItem::setPathName(QString path_name)
|
|||||||
if (!m_parent_item) return;
|
if (!m_parent_item) return;
|
||||||
|
|
||||||
m_path = path_name;
|
m_path = path_name;
|
||||||
name();
|
|
||||||
|
|
||||||
//This isn't an element, we create the childs
|
//This isn't an element, we create the childs
|
||||||
if (!path_name.endsWith(".elmt"))
|
if (!path_name.endsWith(".elmt"))
|
||||||
@@ -377,3 +392,64 @@ void FileElementCollectionItem::populate()
|
|||||||
appendChild(feci);
|
appendChild(feci);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FileElementCollectionItem::handleElementDrop
|
||||||
|
* Handle a drop data that represente an element.
|
||||||
|
* @param data
|
||||||
|
* @return true if the data is successfully dropped
|
||||||
|
*/
|
||||||
|
bool FileElementCollectionItem::handleElementDrop(const QMimeData *data)
|
||||||
|
{
|
||||||
|
ElementLocation location(data->text());
|
||||||
|
return QFile::copy(location.fileSystemPath(), fileSystemPath() + "/" + location.fileSystemPath().split("/").last());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FileElementCollectionItem::handleDirectoryDrop
|
||||||
|
* Handle a drop data that represent a directory
|
||||||
|
* @param data
|
||||||
|
* @return true if the data is successfully dropped
|
||||||
|
*/
|
||||||
|
bool FileElementCollectionItem::handleDirectoryDrop(const QMimeData *data)
|
||||||
|
{
|
||||||
|
ElementLocation location(data->text());
|
||||||
|
QDir origin_dir(location.fileSystemPath());
|
||||||
|
|
||||||
|
if (origin_dir.exists())
|
||||||
|
return createSubDir(origin_dir, QDir(fileSystemPath()));
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FileElementCollectionItem::createSubDir
|
||||||
|
* Copy the directory @ dir_to_copy and the qet_directory file to destination.
|
||||||
|
* Also copy all directorys and elements find in @dir_to_copy recursively
|
||||||
|
* @param dir_to_copy
|
||||||
|
* @param destination
|
||||||
|
* @return true if the copy of @dir_to_copy to destination is successfull.
|
||||||
|
*/
|
||||||
|
bool FileElementCollectionItem::createSubDir(QDir dir_to_copy, QDir destination)
|
||||||
|
{
|
||||||
|
if (destination.mkdir(dir_to_copy.dirName()))
|
||||||
|
{
|
||||||
|
QDir created_dir(destination.canonicalPath() + "/" + dir_to_copy.dirName());
|
||||||
|
|
||||||
|
//Copy the qet_directory file
|
||||||
|
QFile::copy(dir_to_copy.canonicalPath() + "/qet_directory", created_dir.canonicalPath() +"/qet_directory");
|
||||||
|
|
||||||
|
//Copy all dirs found in dir_to_copy to destination
|
||||||
|
foreach(QString str, dir_to_copy.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
|
||||||
|
createSubDir(QDir(dir_to_copy.canonicalPath() + "/" + str), created_dir);
|
||||||
|
|
||||||
|
//Copy all elements found in dir_to_copy to destination
|
||||||
|
dir_to_copy.setNameFilters(QStringList() << "*.elmt");
|
||||||
|
foreach(QString str, dir_to_copy.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
|
||||||
|
QFile::copy(dir_to_copy.canonicalPath() + "/" + str, created_dir.canonicalPath() + "/" + str);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "elementcollectionitem.h"
|
#include "elementcollectionitem.h"
|
||||||
#include "elementlocation.h"
|
#include "elementlocation.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The FileElementCollectionItem class
|
* @brief The FileElementCollectionItem class
|
||||||
@@ -58,6 +59,9 @@ class FileElementCollectionItem : public ElementCollectionItem
|
|||||||
private:
|
private:
|
||||||
void setPathName(QString path_name);
|
void setPathName(QString path_name);
|
||||||
void populate();
|
void populate();
|
||||||
|
bool handleElementDrop (const QMimeData *data);
|
||||||
|
bool handleDirectoryDrop (const QMimeData *data);
|
||||||
|
bool createSubDir (QDir dir_to_copy, QDir destination);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_path;
|
QString m_path;
|
||||||
|
|||||||
Reference in New Issue
Block a user