mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
New element panel can read the embedded collection of project (only at opening, other fonctionnality isn't created yet)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4287 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
593f8eb4f1
commit
4f222d2843
@ -63,6 +63,14 @@ bool ElementCollectionItem::removeChild(int row, int count)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ElementCollectionItem::insertChild(int row, ElementCollectionItem *item)
|
||||
{
|
||||
if (m_child_items.contains(item)) return false;
|
||||
|
||||
m_child_items.insert(row, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementCollectionItem::child
|
||||
* @param row
|
||||
|
@ -41,6 +41,7 @@ class ElementCollectionItem
|
||||
|
||||
void appendChild (ElementCollectionItem *item);
|
||||
bool removeChild (int row, int count);
|
||||
bool insertChild (int row, ElementCollectionItem *item);
|
||||
ElementCollectionItem *child(int row);
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "elementcollectionitem.h"
|
||||
#include "qetapp.h"
|
||||
#include "fileelementcollectionitem.h"
|
||||
#include "xmlprojectelementcollectionitem.h"
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::ElementsCollectionModel
|
||||
@ -262,3 +263,46 @@ void ElementsCollectionModel::addCustomCollection()
|
||||
else
|
||||
delete feci;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::addProject
|
||||
* Add @project to the disalyed collection
|
||||
* @param project
|
||||
* @return true if project was successfully added. If project is already
|
||||
* handled, return false.
|
||||
*/
|
||||
bool ElementsCollectionModel::addProject(QETProject *project)
|
||||
{
|
||||
if (m_project_list.contains(project)) return false;
|
||||
|
||||
m_project_list.append(project);
|
||||
int row = m_project_list.indexOf(project);
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem(project, m_root_item);
|
||||
bool r = m_root_item->insertChild(row, xpeci);
|
||||
endInsertRows();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool ElementsCollectionModel::removeProject(QETProject *project)
|
||||
{
|
||||
if (!m_project_list.contains(project)) return false;
|
||||
|
||||
int row = m_project_list.indexOf(project);
|
||||
if (removeRows(row, 1, QModelIndex()))
|
||||
{
|
||||
m_project_list.removeOne(project);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::project
|
||||
* @return A list of project handled by this model
|
||||
*/
|
||||
QList<QETProject *> ElementsCollectionModel::project() const {
|
||||
return m_project_list;
|
||||
}
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class ElementCollectionItem;
|
||||
class QETProject;
|
||||
class QList<QETProject>;
|
||||
|
||||
/**
|
||||
* @brief The ElementsCollectionModel class
|
||||
* Provide a data model for collection of elements.
|
||||
* Provide a data model for co;llection of elements.
|
||||
*/
|
||||
class ElementsCollectionModel : public QAbstractItemModel
|
||||
{
|
||||
@ -52,9 +54,13 @@ class ElementsCollectionModel : public QAbstractItemModel
|
||||
|
||||
void addCommonCollection();
|
||||
void addCustomCollection();
|
||||
bool addProject(QETProject *project);
|
||||
bool removeProject(QETProject *project);
|
||||
QList<QETProject *> project() const;
|
||||
|
||||
private:
|
||||
ElementCollectionItem *m_root_item;
|
||||
QList <QETProject *> m_project_list;
|
||||
};
|
||||
|
||||
#endif // ELEMENTSCOLLECTIONMODEL_H
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "elementscategoryeditor.h"
|
||||
#include "newelementwizard.h"
|
||||
#include "elementscategory.h"
|
||||
#include "xmlprojectelementcollectionitem.h"
|
||||
#include "qetproject.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QTreeView>
|
||||
@ -40,8 +42,7 @@
|
||||
*/
|
||||
ElementsCollectionWidget::ElementsCollectionWidget(QWidget *parent):
|
||||
QWidget(parent),
|
||||
m_model(nullptr),
|
||||
m_item_at_context_menu(nullptr)
|
||||
m_model(nullptr)
|
||||
{
|
||||
setUpWidget();
|
||||
setUpAction();
|
||||
@ -68,6 +69,19 @@ ElementsCollectionModel *ElementsCollectionWidget::model() const {
|
||||
return m_model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionWidget::addProject
|
||||
* Add @project to be displayed
|
||||
* @param project
|
||||
*/
|
||||
void ElementsCollectionWidget::addProject(QETProject *project) {
|
||||
m_model->addProject(project);
|
||||
}
|
||||
|
||||
void ElementsCollectionWidget::removeProject(QETProject *project) {
|
||||
m_model->removeProject(project);
|
||||
}
|
||||
|
||||
void ElementsCollectionWidget::setUpAction()
|
||||
{
|
||||
m_open_dir = new QAction(QET::Icons::DocumentOpen, tr("Ouvrir le dossier correspondant"), this);
|
||||
@ -130,7 +144,7 @@ void ElementsCollectionWidget::setUpConnection()
|
||||
connect(m_new_element, &QAction::triggered, this, &ElementsCollectionWidget::newElement);
|
||||
|
||||
connect(m_tree_view, &QTreeView::doubleClicked, [this](const QModelIndex &index) {
|
||||
this->m_item_at_context_menu = static_cast<ElementCollectionItem*>(index.internalPointer());
|
||||
this->m_index_at_context_menu = index ;
|
||||
this->editElement();});
|
||||
}
|
||||
|
||||
@ -145,14 +159,16 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
||||
if (!m_index_at_context_menu.isValid()) return;
|
||||
|
||||
m_context_menu->clear();
|
||||
ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(m_index_at_context_menu.internalPointer());
|
||||
m_item_at_context_menu = eci;
|
||||
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
bool add_open_dir = false;
|
||||
|
||||
if (eci->isElement())
|
||||
m_context_menu->addAction(m_edit_element);
|
||||
|
||||
if (eci->type() == FileElementCollectionItem::Type)
|
||||
{
|
||||
add_open_dir = true;
|
||||
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
|
||||
if (!feci->isCommonCollection())
|
||||
{
|
||||
@ -170,9 +186,16 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
||||
m_context_menu->addAction(m_delete_element);
|
||||
}
|
||||
}
|
||||
if (eci->type() == XmlProjectElementCollectionItem::Type)
|
||||
{
|
||||
XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem *>(eci);
|
||||
if (xpeci->isCollectionRoot())
|
||||
add_open_dir = true;
|
||||
}
|
||||
|
||||
m_context_menu->addSeparator();
|
||||
m_context_menu->addAction(m_open_dir);
|
||||
if (add_open_dir)
|
||||
m_context_menu->addAction(m_open_dir);
|
||||
m_context_menu->addAction(m_reload);
|
||||
|
||||
m_context_menu->popup(mapToGlobal(m_tree_view->mapToParent(point)));
|
||||
@ -184,12 +207,13 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
||||
*/
|
||||
void ElementsCollectionWidget::openDir()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
if (!eci) return;
|
||||
|
||||
if (!eci || (eci->type() != FileElementCollectionItem::Type)) return;
|
||||
|
||||
QDesktopServices::openUrl(static_cast<FileElementCollectionItem*>(eci)->dirPath());
|
||||
if (eci->type() == FileElementCollectionItem::Type)
|
||||
QDesktopServices::openUrl(static_cast<FileElementCollectionItem*>(eci)->dirPath());
|
||||
else if (eci->type() == XmlProjectElementCollectionItem::Type)
|
||||
QDesktopServices::openUrl(static_cast<XmlProjectElementCollectionItem*>(eci)->project()->currentDir());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,8 +222,7 @@ void ElementsCollectionWidget::openDir()
|
||||
*/
|
||||
void ElementsCollectionWidget::editElement()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (!eci ||
|
||||
!eci->isElement() ||
|
||||
@ -215,8 +238,7 @@ void ElementsCollectionWidget::editElement()
|
||||
*/
|
||||
void ElementsCollectionWidget::deleteElement()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (!eci) return;
|
||||
if (!(eci->isElement() && eci->canRemoveContent())) return;
|
||||
@ -243,8 +265,7 @@ void ElementsCollectionWidget::deleteElement()
|
||||
*/
|
||||
void ElementsCollectionWidget::deleteDirectory()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (!eci) return;
|
||||
if (!(eci->isDir() && eci->canRemoveContent())) return;
|
||||
@ -273,8 +294,7 @@ void ElementsCollectionWidget::deleteDirectory()
|
||||
*/
|
||||
void ElementsCollectionWidget::editDirectory()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (eci->type() != FileElementCollectionItem::Type) return;
|
||||
|
||||
@ -293,8 +313,7 @@ void ElementsCollectionWidget::editDirectory()
|
||||
*/
|
||||
void ElementsCollectionWidget::newDirectory()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (eci->type() != FileElementCollectionItem::Type) return;
|
||||
|
||||
@ -313,8 +332,7 @@ void ElementsCollectionWidget::newDirectory()
|
||||
*/
|
||||
void ElementsCollectionWidget::newElement()
|
||||
{
|
||||
ElementCollectionItem *eci = m_item_at_context_menu;
|
||||
m_item_at_context_menu = nullptr;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (eci->type() != FileElementCollectionItem::Type) return;
|
||||
|
||||
@ -340,6 +358,10 @@ void ElementsCollectionWidget::reload()
|
||||
new_model->addCommonCollection();
|
||||
new_model->addCustomCollection();
|
||||
|
||||
if (m_model)
|
||||
foreach (QETProject *project, m_model->project())
|
||||
new_model->addProject(project);
|
||||
|
||||
QList <ElementCollectionItem *> list = new_model->items();
|
||||
m_progress_bar->setMaximum(list.size());
|
||||
m_progress_bar->setValue(0);
|
||||
@ -429,3 +451,12 @@ void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index, bool
|
||||
m_tree_view->setRowHidden(index.row(), index.parent(), false);
|
||||
m_tree_view->expand(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionWidget::elementCollectionItemForIndex
|
||||
* @param index
|
||||
* @return The internal pointer of index casted to ElementCollectionItem;
|
||||
*/
|
||||
ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex(const QModelIndex &index) {
|
||||
return static_cast<ElementCollectionItem*>(index.internalPointer());
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class QMenu;
|
||||
class QLineEdit;
|
||||
class ElementCollectionItem;
|
||||
class QProgressBar;
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The ElementsCollectionWidget class
|
||||
@ -45,6 +46,9 @@ class ElementsCollectionWidget : public QWidget
|
||||
void expandFirstItems();
|
||||
ElementsCollectionModel *model() const;
|
||||
|
||||
void addProject (QETProject *project);
|
||||
void removeProject (QETProject *project);
|
||||
|
||||
private:
|
||||
void setUpAction();
|
||||
void setUpWidget();
|
||||
@ -62,6 +66,7 @@ class ElementsCollectionWidget : public QWidget
|
||||
void hideCollection(bool hide = true);
|
||||
void hideItem(bool hide, const QModelIndex &index = QModelIndex(), bool recursive = true);
|
||||
void showAndExpandItem (const QModelIndex &index, bool recursive = true);
|
||||
ElementCollectionItem *elementCollectionItemForIndex (const QModelIndex &index);
|
||||
|
||||
private:
|
||||
ElementsCollectionModel *m_model;
|
||||
@ -69,7 +74,6 @@ class ElementsCollectionWidget : public QWidget
|
||||
QTreeView *m_tree_view;
|
||||
QVBoxLayout *m_main_vlayout;
|
||||
QMenu *m_context_menu;
|
||||
ElementCollectionItem *m_item_at_context_menu;
|
||||
QModelIndex m_index_at_context_menu;
|
||||
QProgressBar *m_progress_bar;
|
||||
|
||||
|
@ -130,7 +130,7 @@ QString FileElementCollectionItem::collectionPath() const
|
||||
QVariant FileElementCollectionItem::data(int column, int role)
|
||||
{
|
||||
//element collection have only one column
|
||||
if (column > 1)
|
||||
if (column > 0)
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
@ -169,8 +169,6 @@ QVariant FileElementCollectionItem::data(int column, int role)
|
||||
return QVariant();
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
|
132
sources/ElementsCollection/xmlelementcollection.cpp
Normal file
132
sources/ElementsCollection/xmlelementcollection.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
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 "xmlelementcollection.h"
|
||||
#include "qdebug.h"
|
||||
#include "nameslist.h"
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::XmlElementCollection
|
||||
* Build an empty collection
|
||||
* @param parent
|
||||
*/
|
||||
XmlElementCollection::XmlElementCollection(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
QDomElement collection = m_dom_document.createElement("collection");
|
||||
m_dom_document.appendChild(collection);
|
||||
QDomElement import = m_dom_document.createElement("category");
|
||||
import.setAttribute("name", "import");
|
||||
collection.appendChild(import);
|
||||
|
||||
NamesList names;
|
||||
|
||||
const QChar russian_data[24] = { 0x0418, 0x043C, 0x043F, 0x043E, 0x0440, 0x0442, 0x0438, 0x0440, 0x043E, 0x0432, 0x0430, 0x043D, 0x043D, 0x044B, 0x0435, 0x0020, 0x044D, 0x043B, 0x0435, 0x043C, 0x0435, 0x043D, 0x0442, 0x044B };
|
||||
const QChar greek_data[18] = { 0x0395, 0x03b9, 0x03c3, 0x03b7, 0x03b3, 0x03bc, 0x03ad, 0x03bd, 0x03b1, 0x0020, 0x03c3, 0x03c4, 0x03bf, 0x03b9, 0x03c7, 0x03b5, 0x03af, 0x03b1 };
|
||||
|
||||
names.addName("fr", "Éléments importés");
|
||||
names.addName("en", "Imported elements");
|
||||
names.addName("de", "Importierte elemente");
|
||||
names.addName("es", "Elementos importados");
|
||||
names.addName("ru", QString(russian_data, 24));
|
||||
names.addName("cs", "Zavedené prvky");
|
||||
names.addName("pl", "Elementy importowane");
|
||||
names.addName("pt", "elementos importados");
|
||||
names.addName("it", "Elementi importati");
|
||||
names.addName("el", QString(greek_data, 18));
|
||||
names.addName("nl", "Elementen geïmporteerd");
|
||||
names.addName("hr", "Uvezeni elementi");
|
||||
names.addName("ca", "Elements importats");
|
||||
names.addName("ro", "Elemente importate");
|
||||
|
||||
import.appendChild(names.toXml(m_dom_document));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::XmlElementCollection
|
||||
* Constructor with an collection. The tagName of @dom_element must be "collection"
|
||||
* @param dom_element -the collection in a dom_element (the dom element in cloned)
|
||||
* @param parent -parent QObject
|
||||
*/
|
||||
XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
QDomElement collection = m_dom_document.createElement("collection");
|
||||
m_dom_document.appendChild(collection);
|
||||
collection.appendChild(dom_element.firstChildElement("category").cloneNode(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::root
|
||||
* @return The root QDomElement of the collection
|
||||
*/
|
||||
QDomElement XmlElementCollection::root() const {
|
||||
return m_dom_document.documentElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::childs
|
||||
* @param parent_element
|
||||
* @return All childs element in the @parent_element tree
|
||||
*/
|
||||
QDomNodeList XmlElementCollection::childs(const QDomElement &parent_element)
|
||||
{
|
||||
if (parent_element.ownerDocument() != m_dom_document) return QDomNodeList();
|
||||
return parent_element.childNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::directory
|
||||
* @param parent_element
|
||||
* @return A list of directory stored in @parent_element
|
||||
*/
|
||||
QList<QDomElement> XmlElementCollection::directory(const QDomElement &parent_element)
|
||||
{
|
||||
QList <QDomElement> directory_list;
|
||||
QDomNodeList node_list = childs(parent_element);
|
||||
if (node_list.isEmpty()) return directory_list;
|
||||
|
||||
for (int i=0 ; i < node_list.count() ; i++)
|
||||
{
|
||||
QDomNode node = node_list.at(i);
|
||||
if (node.isElement() && node.toElement().tagName() == "category")
|
||||
directory_list << node.toElement();
|
||||
}
|
||||
|
||||
return directory_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::elements
|
||||
* @param parent_element
|
||||
* @return A list of element stored in @parent_element
|
||||
*/
|
||||
QList<QDomElement> XmlElementCollection::elements(const QDomElement &parent_element)
|
||||
{
|
||||
QList <QDomElement> element_list;
|
||||
QDomNodeList node_list = childs(parent_element);
|
||||
if (node_list.isEmpty()) return element_list;
|
||||
|
||||
for (int i=0 ; i < node_list.count() ; i++)
|
||||
{
|
||||
QDomNode node = node_list.at(i);
|
||||
if (node.isElement() && node.toElement().tagName() == "element")
|
||||
element_list << node.toElement();
|
||||
}
|
||||
|
||||
return element_list;
|
||||
}
|
46
sources/ElementsCollection/xmlelementcollection.h
Normal file
46
sources/ElementsCollection/xmlelementcollection.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 XMLELEMENTCOLLECTION_H
|
||||
#define XMLELEMENTCOLLECTION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDomElement>
|
||||
|
||||
class QDomElement;
|
||||
|
||||
class XmlElementCollection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
XmlElementCollection (QObject *parent = nullptr);
|
||||
XmlElementCollection (const QDomElement &dom_element, QObject *parent = nullptr);
|
||||
QDomElement root() const;
|
||||
QDomNodeList childs(const QDomElement &parent_element);
|
||||
QList<QDomElement> directory(const QDomElement &parent_element);
|
||||
QList<QDomElement> elements(const QDomElement &parent_element);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QDomDocument m_dom_document;
|
||||
|
||||
};
|
||||
|
||||
#endif // XMLELEMENTCOLLECTION_H
|
256
sources/ElementsCollection/xmlprojectelementcollectionitem.cpp
Normal file
256
sources/ElementsCollection/xmlprojectelementcollectionitem.cpp
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
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 "xmlprojectelementcollectionitem.h"
|
||||
#include "qetproject.h"
|
||||
#include "qeticons.h"
|
||||
#include "xmlelementcollection.h"
|
||||
#include "nameslist.h"
|
||||
#include "qetapp.h"
|
||||
#include <algorithm>
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::XmlProjectElementCollectionItem
|
||||
* Default constructor.
|
||||
* @param project -project for this item
|
||||
* @param parent -paretn item
|
||||
*/
|
||||
XmlProjectElementCollectionItem::XmlProjectElementCollectionItem(QETProject *project, ElementCollectionItem *parent) :
|
||||
ElementCollectionItem(parent),
|
||||
m_project(project)
|
||||
{
|
||||
m_dom_element = project->embeddedElementCollection()->root();
|
||||
populate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::XmlProjectElementCollectionItem
|
||||
* Private constructor
|
||||
* @param project -project for this item
|
||||
* @param dom_element: the dom_element must represent this item
|
||||
* @param parent
|
||||
*/
|
||||
XmlProjectElementCollectionItem::XmlProjectElementCollectionItem(QETProject *project, const QDomElement &dom_element, ElementCollectionItem *parent) :
|
||||
ElementCollectionItem(parent),
|
||||
m_project(project),
|
||||
m_dom_element(dom_element)
|
||||
{
|
||||
populate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::~XmlProjectElementCollectionItem
|
||||
*/
|
||||
XmlProjectElementCollectionItem::~XmlProjectElementCollectionItem()
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::data
|
||||
* The data used by the view who display this item through the model
|
||||
* @param column
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant XmlProjectElementCollectionItem::data(int column, int role)
|
||||
{
|
||||
if (column > 0)
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return name();
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (isCollectionRoot())
|
||||
return QIcon(QET::Icons::ProjectFileGP);
|
||||
else if (isDir())
|
||||
return QET::Icons::Folder;
|
||||
else
|
||||
return QET::Icons::Element;
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
if (isCollectionRoot())
|
||||
return m_project->filePath();
|
||||
else
|
||||
return collectionPath();
|
||||
break;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::mimeData
|
||||
* @return The mimedata of this item
|
||||
*/
|
||||
QMimeData *XmlProjectElementCollectionItem::mimeData()
|
||||
{
|
||||
QMimeData *mime_data = new QMimeData();
|
||||
mime_data->setText(collectionPath());
|
||||
|
||||
if (isElement())
|
||||
mime_data->setData("application/x-qet-element-uri", collectionPath().toLatin1());
|
||||
else
|
||||
mime_data->setData("application/x-qet-category-uri", collectionPath().toLatin1());
|
||||
|
||||
return mime_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::flags
|
||||
* @return The flags of this item
|
||||
*/
|
||||
Qt::ItemFlags XmlProjectElementCollectionItem::flags()
|
||||
{
|
||||
if (isDir())
|
||||
return (Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
|
||||
else
|
||||
return (Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::isCollectionRoot
|
||||
* @return True if this item represent the root collection of a project
|
||||
*/
|
||||
bool XmlProjectElementCollectionItem::isCollectionRoot() const
|
||||
{
|
||||
if (!m_parent_item) return true;
|
||||
else if (m_parent_item->type() != XmlProjectElementCollectionItem::Type) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::name
|
||||
* @return The name of this item, name is notably use for Qt::DisplayRole data
|
||||
*/
|
||||
QString XmlProjectElementCollectionItem::name()
|
||||
{
|
||||
if (!m_name.isNull()) return m_name;
|
||||
|
||||
if (isCollectionRoot())
|
||||
{
|
||||
if (m_project->title().isEmpty())
|
||||
return QString("Projet sans titre");
|
||||
else
|
||||
return m_project->title();
|
||||
}
|
||||
else
|
||||
{
|
||||
NamesList nl;
|
||||
if (isDir())
|
||||
{
|
||||
nl.fromXml(m_dom_element);
|
||||
if (nl.name().isEmpty())
|
||||
m_name = m_dom_element.attribute("name");
|
||||
else
|
||||
m_name = nl.name();
|
||||
}
|
||||
else
|
||||
{
|
||||
nl.fromXml(m_dom_element.firstChildElement("definition"));
|
||||
if (nl.name().isEmpty())
|
||||
m_name = m_dom_element.attribute("name");
|
||||
else
|
||||
m_name = nl.name();
|
||||
}
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::isValid
|
||||
* @return Always true
|
||||
*/
|
||||
bool XmlProjectElementCollectionItem::isValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::project
|
||||
* @return The project for this collection item
|
||||
*/
|
||||
QETProject *XmlProjectElementCollectionItem::project() const {
|
||||
return m_project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::isDir
|
||||
* @return true if this item represent a directory
|
||||
*/
|
||||
bool XmlProjectElementCollectionItem::isDir() const
|
||||
{
|
||||
if (m_dom_element.tagName() == "category") return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::isElement
|
||||
* @return true if this item represent an element
|
||||
*/
|
||||
bool XmlProjectElementCollectionItem::isElement() const
|
||||
{
|
||||
if (m_dom_element.tagName() == "element") return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::collectionPath
|
||||
* @return The collection path of this item
|
||||
*/
|
||||
QString XmlProjectElementCollectionItem::collectionPath() const
|
||||
{
|
||||
if (isCollectionRoot())
|
||||
{
|
||||
QString path;
|
||||
return path + "project" + QString::number(QETApp::projectId(m_project)) + "+embed://";
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlProjectElementCollectionItem *parent = static_cast<XmlProjectElementCollectionItem *>(m_parent_item);
|
||||
|
||||
if (parent->isCollectionRoot())
|
||||
return parent->collectionPath() + m_dom_element.attribute("name");
|
||||
else
|
||||
return parent->collectionPath() + "/" + m_dom_element.attribute("name");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::populate
|
||||
* Populate this item
|
||||
*/
|
||||
void XmlProjectElementCollectionItem::populate()
|
||||
{
|
||||
QList <QDomElement> dom_category = m_project->embeddedElementCollection()->directory(m_dom_element);
|
||||
std::sort(dom_category.begin(), dom_category.end(), [](QDomElement a, QDomElement b){return (a.attribute("name") < b.attribute("name"));});
|
||||
|
||||
foreach (QDomElement element, dom_category)
|
||||
{
|
||||
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem(m_project, element, this);
|
||||
this->appendChild(xpeci);
|
||||
}
|
||||
|
||||
QList <QDomElement> dom_elements = m_project->embeddedElementCollection()->elements(m_dom_element);
|
||||
std::sort(dom_elements.begin(), dom_elements.end(), [](QDomElement a, QDomElement b){return (a.attribute("name") < b.attribute("name"));});
|
||||
|
||||
foreach (QDomElement element, dom_elements)
|
||||
{
|
||||
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem(m_project, element, this);
|
||||
this->appendChild(xpeci);
|
||||
}
|
||||
}
|
63
sources/ElementsCollection/xmlprojectelementcollectionitem.h
Normal file
63
sources/ElementsCollection/xmlprojectelementcollectionitem.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
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 XMLPROJECTELEMENTCOLLECTIONITEM_H
|
||||
#define XMLPROJECTELEMENTCOLLECTIONITEM_H
|
||||
|
||||
#include "elementcollectionitem.h"
|
||||
|
||||
#include <QDomElement>
|
||||
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The XmlProjectElementCollectionItem class
|
||||
* This class specialise ElementCollectionItem for manage an xml collection embedded in a project.
|
||||
*/
|
||||
class XmlProjectElementCollectionItem : public ElementCollectionItem
|
||||
{
|
||||
public:
|
||||
XmlProjectElementCollectionItem(QETProject *project, ElementCollectionItem *parent = nullptr);
|
||||
private:
|
||||
XmlProjectElementCollectionItem (QETProject *project, const QDomElement &dom_element, ElementCollectionItem *parent = nullptr);
|
||||
public:
|
||||
~XmlProjectElementCollectionItem();
|
||||
|
||||
enum {Type = UserType + 2};
|
||||
virtual int type() const {return Type;}
|
||||
|
||||
virtual QVariant data(int column, int role);
|
||||
virtual QMimeData *mimeData();
|
||||
virtual Qt::ItemFlags flags();
|
||||
|
||||
virtual bool isCollectionRoot() const;
|
||||
virtual QString name();
|
||||
virtual bool isValid() const;
|
||||
QETProject *project() const;
|
||||
virtual bool isDir() const;
|
||||
virtual bool isElement() const;
|
||||
QString collectionPath() const;
|
||||
|
||||
private:
|
||||
void populate();
|
||||
|
||||
private:
|
||||
QETProject *m_project;
|
||||
QDomElement m_dom_element;
|
||||
};
|
||||
|
||||
#endif // XMLPROJECTELEMENTCOLLECTIONITEM_H
|
@ -931,6 +931,8 @@ bool QETDiagramEditor::addProject(QETProject *project, bool update_panel) {
|
||||
addProjectView(project_view);
|
||||
|
||||
undo_group.addStack(project -> undoStack());
|
||||
|
||||
m_element_collection_widget->addProject(project);
|
||||
|
||||
// met a jour le panel d'elements
|
||||
if (update_panel) {
|
||||
@ -1720,6 +1722,7 @@ void QETDiagramEditor::projectWasClosed(ProjectView *project_view) {
|
||||
QETProject *project = project_view -> project();
|
||||
if (project) {
|
||||
pa -> elementsPanel().projectWasClosed(project);
|
||||
m_element_collection_widget->removeProject(project);
|
||||
undo_group.removeStack(project -> undoStack());
|
||||
QETApp::unregisterProject(project);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "numerotationcontext.h"
|
||||
#include "reportproperties.h"
|
||||
#include "integrationmovetemplateshandler.h"
|
||||
#include "xmlelementcollection.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
@ -51,7 +52,8 @@ QETProject::QETProject(int diagrams, QObject *parent) :
|
||||
read_only_ (false ),
|
||||
titleblocks_ (this ),
|
||||
folioSheetsQuantity (0 ),
|
||||
m_auto_conductor (true )
|
||||
m_auto_conductor (true ),
|
||||
m_elements_collection (nullptr)
|
||||
{
|
||||
// 0 a n schema(s) vide(s)
|
||||
int diagrams_count = qMax(0, diagrams);
|
||||
@ -64,6 +66,8 @@ QETProject::QETProject(int diagrams, QObject *parent) :
|
||||
collection_ -> setProtocol("embed");
|
||||
collection_ -> setProject(this);
|
||||
connect(collection_, SIGNAL(written()), this, SLOT(componentWritten()));
|
||||
|
||||
m_elements_collection = new XmlElementCollection(this);
|
||||
|
||||
// une categorie dediee aux elements integres automatiquement
|
||||
ensureIntegrationCategoryExists();
|
||||
@ -87,7 +91,8 @@ QETProject::QETProject(const QString &path, QObject *parent) :
|
||||
read_only_ (false ),
|
||||
titleblocks_ (this ),
|
||||
folioSheetsQuantity (0 ),
|
||||
m_auto_conductor (true )
|
||||
m_auto_conductor (true ),
|
||||
m_elements_collection (nullptr)
|
||||
{
|
||||
//Open the file
|
||||
QFile project_file(path);
|
||||
@ -204,6 +209,14 @@ ElementsCollection *QETProject::embeddedCollection() const {
|
||||
return(collection_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETProject::embeddedCollection
|
||||
* @return The embedded collection
|
||||
*/
|
||||
XmlElementCollection *QETProject::embeddedElementCollection() const {
|
||||
return m_elements_collection;
|
||||
}
|
||||
|
||||
/**
|
||||
@return the title block templates collection enbeedded within this project
|
||||
*/
|
||||
@ -1141,9 +1154,15 @@ void QETProject::readElementsCollectionXml(QDomDocument &xml_project)
|
||||
}
|
||||
|
||||
if (collection_root.isNull()) //Make an empty collection
|
||||
{
|
||||
collection_ = new XmlElementsCollection();
|
||||
m_elements_collection = new XmlElementCollection(this);
|
||||
}
|
||||
else //Read the collection
|
||||
{
|
||||
collection_ = new XmlElementsCollection(collection_root);
|
||||
m_elements_collection = new XmlElementCollection(collection_root, this);
|
||||
}
|
||||
|
||||
collection_ -> setProtocol("embed");
|
||||
collection_ -> setProject(this);
|
||||
|
@ -38,6 +38,7 @@ class MoveElementsHandler;
|
||||
class MoveTitleBlockTemplatesHandler;
|
||||
class NumerotationContext;
|
||||
class QUndoStack;
|
||||
class XmlElementCollection;
|
||||
|
||||
/**
|
||||
This class represents a QET project. Typically saved as a .qet file, it
|
||||
@ -85,6 +86,7 @@ class QETProject : public QObject
|
||||
void setFolioSheetsQuantity(int); /// set the folio sheets quantity for this project
|
||||
int folioIndex(const Diagram *) const;
|
||||
ElementsCollection *embeddedCollection() const;
|
||||
XmlElementCollection *embeddedElementCollection()const;
|
||||
TitleBlockTemplatesProjectCollection *embeddedTitleBlockTemplatesCollection();
|
||||
QString filePath();
|
||||
void setFilePath(const QString &);
|
||||
@ -119,7 +121,6 @@ class QETProject : public QObject
|
||||
|
||||
bool autoConductor () const;
|
||||
void setAutoConductor (bool ac);
|
||||
|
||||
QDomDocument toXml();
|
||||
bool close();
|
||||
QETResult write();
|
||||
@ -230,6 +231,7 @@ class QETProject : public QObject
|
||||
/// Folio List Sheets quantity for this project.
|
||||
int folioSheetsQuantity;
|
||||
bool m_auto_conductor;
|
||||
XmlElementCollection *m_elements_collection;
|
||||
};
|
||||
Q_DECLARE_METATYPE(QETProject *)
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user