mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Remove old classes used to manage the xml elements collection
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4524 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 "elementscategorieswidget.h"
|
|
||||||
#include "elementscategorieslist.h"
|
|
||||||
#include "elementscategoryeditor.h"
|
|
||||||
#include "elementscategorydeleter.h"
|
|
||||||
#include "elementscategory.h"
|
|
||||||
#include "qeticons.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param parent Le QWidget parent
|
|
||||||
*/
|
|
||||||
ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget *parent) : QWidget(parent) {
|
|
||||||
// initialise la liste des categories
|
|
||||||
elementscategorieslist = new ElementsCategoriesList(false, QET::All, this);
|
|
||||||
|
|
||||||
// actions
|
|
||||||
action_reload = new QAction(QET::Icons::ViewRefresh, tr("Recharger les catégories"), this);
|
|
||||||
action_new = new QAction(QET::Icons::FolderNew, tr("Nouvelle catégorie"), this);
|
|
||||||
action_open = new QAction(QET::Icons::FolderEdit, tr("Éditer la catégorie"), this);
|
|
||||||
action_delete = new QAction(QET::Icons::FolderDelete, tr("Supprimer la catégorie"), this);
|
|
||||||
|
|
||||||
// initialise la barre d'outils
|
|
||||||
toolbar = new QToolBar(this);
|
|
||||||
toolbar -> setMovable(false);
|
|
||||||
toolbar -> addAction(action_reload);
|
|
||||||
toolbar -> addAction(action_new);
|
|
||||||
toolbar -> addAction(action_open);
|
|
||||||
toolbar -> addAction(action_delete);
|
|
||||||
|
|
||||||
connect(action_reload, SIGNAL(triggered()), elementscategorieslist, SLOT(reload()) );
|
|
||||||
connect(action_new, SIGNAL(triggered()), this, SLOT(newCategory()) );
|
|
||||||
connect(action_open, SIGNAL(triggered()), this, SLOT(editCategory()) );
|
|
||||||
connect(action_delete, SIGNAL(triggered()), this, SLOT(removeCategory()));
|
|
||||||
connect(elementscategorieslist, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()) );
|
|
||||||
|
|
||||||
updateButtons();
|
|
||||||
|
|
||||||
// disposition verticale
|
|
||||||
QVBoxLayout *vlayout = new QVBoxLayout(this);
|
|
||||||
vlayout -> setMargin(0);
|
|
||||||
vlayout -> setSpacing(0);
|
|
||||||
vlayout -> addWidget(toolbar);
|
|
||||||
vlayout -> addWidget(elementscategorieslist);
|
|
||||||
vlayout -> setStretchFactor(elementscategorieslist, 75000);
|
|
||||||
setLayout(vlayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Destructeur
|
|
||||||
*/
|
|
||||||
ElementsCategoriesWidget::~ElementsCategoriesWidget() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Lance un editeur de categorie en mode "creation de categorie"
|
|
||||||
*/
|
|
||||||
void ElementsCategoriesWidget::newCategory() {
|
|
||||||
// recupere le chemin virtuel de la categorie selectionnee
|
|
||||||
ElementsLocation s_c_path = elementscategorieslist -> selectedLocation();
|
|
||||||
if (s_c_path.isNull()) return;
|
|
||||||
|
|
||||||
// lance un editeur de categorie
|
|
||||||
ElementsCategoryEditor *editor = new ElementsCategoryEditor(s_c_path, false, this);
|
|
||||||
int result = editor -> exec();
|
|
||||||
|
|
||||||
// recharge la collection si besoin
|
|
||||||
if (result == QDialog::Accepted) {
|
|
||||||
elementscategorieslist -> reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Lance un editeur de categorie en mode "edition de categorie"
|
|
||||||
*/
|
|
||||||
void ElementsCategoriesWidget::editCategory() {
|
|
||||||
ElementsLocation s_c_path = elementscategorieslist -> selectedLocation();
|
|
||||||
if (s_c_path.isNull()) return;
|
|
||||||
(new ElementsCategoryEditor(s_c_path, true, this)) -> exec();
|
|
||||||
elementscategorieslist -> reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime la categorie selectionnee
|
|
||||||
*/
|
|
||||||
void ElementsCategoriesWidget::removeCategory() {
|
|
||||||
// recupere le chemin de la categorie
|
|
||||||
ElementsLocation s_c_path = elementscategorieslist -> selectedLocation();
|
|
||||||
if (s_c_path.isNull()) return;
|
|
||||||
|
|
||||||
// supprime la categorie
|
|
||||||
ElementsCategoryDeleter cat_deleter(s_c_path, this);
|
|
||||||
cat_deleter.exec();
|
|
||||||
|
|
||||||
// recharge la liste des categories
|
|
||||||
elementscategorieslist -> reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Met a jour l'etat (active / desactive) des boutons en fonction de ce qui
|
|
||||||
est selectionne.
|
|
||||||
*/
|
|
||||||
void ElementsCategoriesWidget::updateButtons() {
|
|
||||||
QList<QTreeWidgetItem *> sel_items = elementscategorieslist -> selectedItems();
|
|
||||||
bool sel_items_empty = !sel_items.isEmpty();
|
|
||||||
bool is_top_lvl_item = sel_items_empty && (elementscategorieslist -> indexOfTopLevelItem(sel_items.at(0)) != -1);
|
|
||||||
action_new -> setEnabled(sel_items_empty);
|
|
||||||
action_open -> setEnabled(sel_items_empty && !is_top_lvl_item);
|
|
||||||
action_delete -> setEnabled(sel_items_empty && !is_top_lvl_item);
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 ELEMENTS_CATEGORIES_WIDGET_H
|
|
||||||
#define ELEMENTS_CATEGORIES_WIDGET_H
|
|
||||||
#include <QtWidgets>
|
|
||||||
class ElementsCategoriesList;
|
|
||||||
/**
|
|
||||||
This class provides a widget listing available elements categories along
|
|
||||||
with buttons to add, change or create categories.
|
|
||||||
*/
|
|
||||||
class ElementsCategoriesWidget : public QWidget {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// Constructors, destructor
|
|
||||||
public:
|
|
||||||
ElementsCategoriesWidget(QWidget * = 0);
|
|
||||||
virtual ~ElementsCategoriesWidget();
|
|
||||||
|
|
||||||
private:
|
|
||||||
ElementsCategoriesWidget(const ElementsCategoriesWidget &);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
private:
|
|
||||||
ElementsCategoriesList *elementscategorieslist;
|
|
||||||
QToolBar *toolbar;
|
|
||||||
QAction *action_reload;
|
|
||||||
QAction *action_new;
|
|
||||||
QAction *action_open;
|
|
||||||
QAction *action_delete;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
ElementsCategoriesList &elementsCategoriesList() const;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void newCategory();
|
|
||||||
void editCategory();
|
|
||||||
void removeCategory();
|
|
||||||
void updateButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return The ElementsCategoriesList embedded within this widget.
|
|
||||||
*/
|
|
||||||
inline ElementsCategoriesList &ElementsCategoriesWidget::elementsCategoriesList() const {
|
|
||||||
return(*elementscategorieslist);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "elementspanelwidget.h"
|
#include "elementspanelwidget.h"
|
||||||
#include "newelementwizard.h"
|
#include "newelementwizard.h"
|
||||||
#include "elementscategorieswidget.h"
|
|
||||||
#include "elementscollectionitem.h"
|
#include "elementscollectionitem.h"
|
||||||
#include "qetelementeditor.h"
|
#include "qetelementeditor.h"
|
||||||
#include "elementdeleter.h"
|
#include "elementdeleter.h"
|
||||||
@@ -395,9 +394,6 @@ void ElementsPanelWidget::newCategory() {
|
|||||||
if (new_category_dialog.exec() == QDialog::Accepted) {
|
if (new_category_dialog.exec() == QDialog::Accepted) {
|
||||||
elements_panel -> reload();
|
elements_panel -> reload();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
launchCategoriesManager();
|
|
||||||
elements_panel -> reload();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,31 +468,6 @@ void ElementsPanelWidget::setElementsActionEnabled(bool enable) {
|
|||||||
delete_element -> setEnabled(enable);
|
delete_element -> setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Lance le gestionnaire de categories. Il s'agit d'un petit dialogue listant
|
|
||||||
les categories accessibles en ecriture et permettant de les editer, de les
|
|
||||||
supprimer et d'en creer de nouvelles.
|
|
||||||
*/
|
|
||||||
int ElementsPanelWidget::launchCategoriesManager() {
|
|
||||||
QDialog new_category_dialog(this);
|
|
||||||
new_category_dialog.setMinimumSize(480, 280);
|
|
||||||
new_category_dialog.setWindowTitle(tr("Gestionnaire de catégories", "window title"));
|
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(&new_category_dialog);
|
|
||||||
QLabel *explication = new QLabel(tr("Vous pouvez utiliser ce gestionnaire pour ajouter, supprimer ou modifier les catégories."));
|
|
||||||
explication -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
|
||||||
explication -> setWordWrap(true);
|
|
||||||
layout -> addWidget(explication);
|
|
||||||
|
|
||||||
layout -> addWidget(new ElementsCategoriesWidget());
|
|
||||||
|
|
||||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close);
|
|
||||||
connect(buttons, SIGNAL(rejected()), &new_category_dialog, SLOT(accept()));
|
|
||||||
layout -> addWidget(buttons);
|
|
||||||
|
|
||||||
return(new_category_dialog.exec());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere le menu contextuel du panel d'elements
|
Gere le menu contextuel du panel d'elements
|
||||||
@param pos Position ou le menu contextuel a ete demande
|
@param pos Position ou le menu contextuel a ete demande
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ class ElementsPanelWidget : public QWidget {
|
|||||||
void deleteElement();
|
void deleteElement();
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
void setElementsActionEnabled(bool);
|
void setElementsActionEnabled(bool);
|
||||||
int launchCategoriesManager();
|
|
||||||
void handleContextMenu(const QPoint &);
|
void handleContextMenu(const QPoint &);
|
||||||
void handleCollectionRequest(const ElementsLocation &);
|
void handleCollectionRequest(const ElementsLocation &);
|
||||||
void collectionsRead();
|
void collectionsRead();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class Diagram;
|
|||||||
class ElementsLocation;
|
class ElementsLocation;
|
||||||
class QETResult;
|
class QETResult;
|
||||||
class TitleBlockTemplate;
|
class TitleBlockTemplate;
|
||||||
class XmlElementsCollection;
|
|
||||||
class MoveTitleBlockTemplatesHandler;
|
class MoveTitleBlockTemplatesHandler;
|
||||||
class NumerotationContext;
|
class NumerotationContext;
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 "xmlelementdefinition.h"
|
|
||||||
#include "xmlelementscategory.h"
|
|
||||||
#include "xmlelementscollection.h"
|
|
||||||
#include "qet.h"
|
|
||||||
#include "qetproject.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Construit une definition d'element vide
|
|
||||||
*/
|
|
||||||
XmlElementDefinition::XmlElementDefinition(const QString &name, XmlElementsCategory *category, XmlElementsCollection *collection) :
|
|
||||||
ElementDefinition(category, collection),
|
|
||||||
parent_category_(category)
|
|
||||||
{
|
|
||||||
name_ = name;
|
|
||||||
QDomElement new_elmt = xml_element_.createElement("element");
|
|
||||||
new_elmt.setAttribute("name", name_);
|
|
||||||
xml_element_.appendChild(new_elmt);
|
|
||||||
element_definition_ = xml_element_.createElement("definition");
|
|
||||||
new_elmt.appendChild(element_definition_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Construit une definition d'element a partir de sa representation XML
|
|
||||||
*/
|
|
||||||
XmlElementDefinition::XmlElementDefinition(const QDomElement &xml_element, XmlElementsCategory *category, XmlElementsCollection *collection) :
|
|
||||||
ElementDefinition(category, collection),
|
|
||||||
parent_category_(category)
|
|
||||||
{
|
|
||||||
xml_element_.appendChild(xml_element_.importNode(xml_element, true));
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Destructeur
|
|
||||||
*/
|
|
||||||
XmlElementDefinition::~XmlElementDefinition() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la definition XML de l'element
|
|
||||||
*/
|
|
||||||
QDomElement XmlElementDefinition::xml() {
|
|
||||||
return(element_definition_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Change la definition XML de l'element
|
|
||||||
@param xml_element Nouvelle definition XML de l'element
|
|
||||||
@return true si l'operation s'est bien passee, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::setXml(const QDomElement &xml_element) {
|
|
||||||
// oublie toute la structure XML
|
|
||||||
xml_element_.clear();
|
|
||||||
|
|
||||||
// cree la structure XML contenant le nom de l'element
|
|
||||||
QDomElement new_elmt = xml_element_.createElement("element");
|
|
||||||
new_elmt.setAttribute("name", name_);
|
|
||||||
xml_element_.appendChild(new_elmt);
|
|
||||||
|
|
||||||
// importe la nouvelle definition XML de l'element
|
|
||||||
element_definition_ = xml_element_.importNode(xml_element, true).toElement();
|
|
||||||
new_elmt.appendChild(element_definition_);
|
|
||||||
is_null_ = false;
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XmlElementDefinition::write() {
|
|
||||||
/*
|
|
||||||
Contrairement a un schema, cet objet ne contient pas deux versions de
|
|
||||||
l'element (element avant edition et element edite) Cette methode ne
|
|
||||||
fait donc rien d'autre qu'emettre le signal written(), le travail ayant
|
|
||||||
deja ete fait par la methode setXml().
|
|
||||||
*/
|
|
||||||
emit(written());
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si l'element n'est pas exploitable (definition ou nom non
|
|
||||||
trouve)
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::isNull() const {
|
|
||||||
return(name_.isEmpty() || is_null_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return Le nom de cet element dans l'arborescence
|
|
||||||
*/
|
|
||||||
QString XmlElementDefinition::pathName() const {
|
|
||||||
return(name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return le chemin virtuel de cet element
|
|
||||||
*/
|
|
||||||
QString XmlElementDefinition::virtualPath() {
|
|
||||||
// il n'est pas possible d'avoir un chemin virtuel sans appartenir a une collection
|
|
||||||
if (!hasParentCollection() || name_.isEmpty()) return(QString());
|
|
||||||
|
|
||||||
if (parent_category_) {
|
|
||||||
QString tmp(parent_category_ -> virtualPath());
|
|
||||||
if (!tmp.isEmpty()) tmp += "/";
|
|
||||||
return(tmp + name_);
|
|
||||||
} else {
|
|
||||||
return(name_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Recharge le contenu de l'element
|
|
||||||
*/
|
|
||||||
void XmlElementDefinition::reload() {
|
|
||||||
is_null_ = true;
|
|
||||||
|
|
||||||
// on recupere le nom de l'element
|
|
||||||
QDomElement doc_elmt = xml_element_.documentElement();
|
|
||||||
name_ = doc_elmt.attribute("name");
|
|
||||||
if (name_.isEmpty()) return;
|
|
||||||
|
|
||||||
// on recupere la definition de l'element
|
|
||||||
for (QDomNode node = doc_elmt.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
|
||||||
if (!node.isElement()) continue;
|
|
||||||
QDomElement current_element = node.toElement();
|
|
||||||
if (current_element.tagName() == "definition" && current_element.attribute("type") == "element") {
|
|
||||||
element_definition_ = current_element;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// l'element est nul si aucune definition n'a ete trouvee
|
|
||||||
is_null_ = (element_definition_.isNull());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si l'element existe, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::exists() {
|
|
||||||
// la seule raison qu'un element aurait de ne pas exister est l'absence
|
|
||||||
// de nom
|
|
||||||
return(!name_.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la categorie est accessible en lecture, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::isReadable() {
|
|
||||||
// une categorie XML n'a aucune raison de ne pas etre accessible en lecture
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la categorie est accessible en ecriture, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::isWritable() {
|
|
||||||
// une categorie XML peut etre en lecture seule si le projet auquel elle
|
|
||||||
// appartient l'est
|
|
||||||
if (QETProject *parent_project = project()) {
|
|
||||||
return(!parent_project -> isReadOnly());
|
|
||||||
} else {
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime l'element
|
|
||||||
@return true si l'operation s'est bien passee, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::remove() {
|
|
||||||
removeContent();
|
|
||||||
emit(removed(name_));
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return toujours false, car un element XML n'a pas de chemin de type
|
|
||||||
fichier
|
|
||||||
*/
|
|
||||||
bool XmlElementDefinition::hasFilePath() {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return une chaine vide, car un element XML n'a pas de chemin de type
|
|
||||||
fichier
|
|
||||||
*/
|
|
||||||
QString XmlElementDefinition::filePath() {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
return(QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ne fait rien, car un element XML n'a pas de chemin de type fichier
|
|
||||||
*/
|
|
||||||
void XmlElementDefinition::setFilePath(const QString &) {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return a null QDateTime object since an XML element does not have a
|
|
||||||
modification time.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
@return the time of the last modification (mtime) for this element file
|
|
||||||
*/
|
|
||||||
QDateTime XmlElementDefinition::modificationTime() const {
|
|
||||||
return QDateTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement XmlElementDefinition::writeXml(QDomDocument &xml_doc) const {
|
|
||||||
QDomElement element_elmt = xml_element_.documentElement();
|
|
||||||
QDomNode new_node = xml_doc.importNode(element_elmt, true);
|
|
||||||
return(new_node.toElement());
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 XML_ELEMENT_DEFINITION
|
|
||||||
#define XML_ELEMENT_DEFINITION
|
|
||||||
#include <QtXml>
|
|
||||||
#include "elementdefinition.h"
|
|
||||||
class XmlElementsCategory;
|
|
||||||
class XmlElementsCollection;
|
|
||||||
/**
|
|
||||||
This class represents an element definition stored within an XML document
|
|
||||||
(e.g. the embedded collection of a QET project).
|
|
||||||
*/
|
|
||||||
class XmlElementDefinition : public ElementDefinition {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
XmlElementDefinition(const QString &, XmlElementsCategory * = 0, XmlElementsCollection * = 0);
|
|
||||||
XmlElementDefinition(const QDomElement &, XmlElementsCategory * = 0, XmlElementsCollection * = 0);
|
|
||||||
virtual ~XmlElementDefinition();
|
|
||||||
|
|
||||||
private:
|
|
||||||
XmlElementDefinition(const XmlElementDefinition &);
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
virtual QDomElement xml();
|
|
||||||
virtual bool setXml(const QDomElement &);
|
|
||||||
virtual bool write();
|
|
||||||
virtual bool isNull() const;
|
|
||||||
virtual QString pathName() const;
|
|
||||||
virtual QString virtualPath();
|
|
||||||
virtual void reload();
|
|
||||||
virtual bool exists();
|
|
||||||
virtual bool isReadable();
|
|
||||||
virtual bool isWritable();
|
|
||||||
virtual bool remove();
|
|
||||||
virtual bool hasFilePath();
|
|
||||||
virtual QString filePath();
|
|
||||||
virtual void setFilePath(const QString &);
|
|
||||||
virtual QDateTime modificationTime() const;
|
|
||||||
virtual QDomElement writeXml(QDomDocument &) const;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void written();
|
|
||||||
void removed(const QString &);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
private:
|
|
||||||
bool is_null_;
|
|
||||||
QString name_;
|
|
||||||
XmlElementsCategory *parent_category_;
|
|
||||||
QDomDocument xml_element_;
|
|
||||||
QDomElement element_definition_;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,487 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 "xmlelementscategory.h"
|
|
||||||
#include "xmlelementscollection.h"
|
|
||||||
#include "xmlelementdefinition.h"
|
|
||||||
#include "qetproject.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cree une categorie XML vide
|
|
||||||
@param parent Categorie parente
|
|
||||||
@param collection Collection a laquelle cette categorie appartient
|
|
||||||
*/
|
|
||||||
XmlElementsCategory::XmlElementsCategory(XmlElementsCategory *parent, XmlElementsCollection *collection) :
|
|
||||||
ElementsCategory(parent, collection),
|
|
||||||
xml_parent_collection_(collection),
|
|
||||||
xml_parent_category_(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cree une categorie XML a partir d'un element XML
|
|
||||||
@param xml_element Element XML a analyser
|
|
||||||
@param parent Categorie parente
|
|
||||||
@param collection Collection a laquelle cette categorie appartient
|
|
||||||
*/
|
|
||||||
XmlElementsCategory::XmlElementsCategory(const QDomElement &xml_element, XmlElementsCategory *parent, XmlElementsCollection *collection) :
|
|
||||||
ElementsCategory(parent, collection),
|
|
||||||
xml_parent_collection_(collection),
|
|
||||||
xml_parent_category_(parent)
|
|
||||||
{
|
|
||||||
loadContent(xml_element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Destructeur
|
|
||||||
*/
|
|
||||||
XmlElementsCategory::~XmlElementsCategory() {
|
|
||||||
deleteContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return le nom de la categorie utilisable dans un chemin (virtuel ou reel)
|
|
||||||
*/
|
|
||||||
QString XmlElementsCategory::pathName() const {
|
|
||||||
return(name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return le chemin virtuel de la categorie, sans le protocole
|
|
||||||
*/
|
|
||||||
QString XmlElementsCategory::virtualPath() {
|
|
||||||
// il n'est pas possible d'avoir un chemin virtuel sans appartenir a une collection
|
|
||||||
if (!hasParentCollection() || name_.isEmpty()) return(QString());
|
|
||||||
|
|
||||||
if (parent_category_) {
|
|
||||||
QString tmp(parent_category_ -> virtualPath());
|
|
||||||
if (!tmp.isEmpty()) tmp += "/";
|
|
||||||
return(tmp + name_);
|
|
||||||
} else {
|
|
||||||
return(name_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return toujours false, car une categorie XML n'a pas de chemin de type
|
|
||||||
fichier
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::hasFilePath() {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return une chaine vide, car une categorie XML n'a pas de chemin de type
|
|
||||||
fichier
|
|
||||||
*/
|
|
||||||
QString XmlElementsCategory::filePath() {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
return(QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ne fait rien, car une categorie XML n'a pas de chemin de type fichier
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::setFilePath(const QString &) {
|
|
||||||
// une categorie XML n'a pas de chemin de type fichier
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la liste des sous-categories de la categorie
|
|
||||||
*/
|
|
||||||
QList<ElementsCategory *> XmlElementsCategory::categories() {
|
|
||||||
QList<ElementsCategory *> cat_list;
|
|
||||||
|
|
||||||
QList<QString> keys(categories_.keys());
|
|
||||||
qSort(keys.begin(), keys.end());
|
|
||||||
foreach(QString key, keys) cat_list << categories_[key];
|
|
||||||
return(cat_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la categorie correspondant au chemin virtuel cat_path, ou 0 en cas d'echec
|
|
||||||
@param cat_path Chemin virtuel de la categorie voulue
|
|
||||||
*/
|
|
||||||
ElementsCategory *XmlElementsCategory::category(const QString &cat_path) {
|
|
||||||
// recupere les differentes parties du chemin
|
|
||||||
QString cat_path_(cat_path);
|
|
||||||
QStringList path_parts = cat_path_.split(QChar('/'), QString::SkipEmptyParts, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
if (!path_parts.count()) {
|
|
||||||
return(this);
|
|
||||||
} else {
|
|
||||||
// a-t-on la premiere sous-categorie ?
|
|
||||||
if (!categories_.contains(path_parts.first())) {
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// on a la premiere sous-categorie
|
|
||||||
ElementsCategory *first_sub_cat = categories_.value(path_parts.first());
|
|
||||||
|
|
||||||
if (path_parts.count() == 1) return(first_sub_cat);
|
|
||||||
|
|
||||||
// on demande a la premiere sous-categorie de fournir la categorie finale
|
|
||||||
path_parts.removeFirst();
|
|
||||||
return(first_sub_cat -> category(path_parts.join("/")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cree une categorie. La categorie parente doit exister.
|
|
||||||
@param path chemin d'une categorie a creer sous la forme d'une adresse
|
|
||||||
virtuelle comme common://cat1/cat2/cat3
|
|
||||||
@return la nouvelle categorie demandee, ou 0 en cas d'echec
|
|
||||||
*/
|
|
||||||
ElementsCategory *XmlElementsCategory::createCategory(const QString &path) {
|
|
||||||
// on ne doit pas etre en lecture seule
|
|
||||||
if (!isWritable()) return(0);
|
|
||||||
|
|
||||||
// recupere les differentes parties du chemin
|
|
||||||
QString cat_path_(path);
|
|
||||||
QStringList path_parts = cat_path_.split(QChar('/'), QString::SkipEmptyParts, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
if (!path_parts.count()) {
|
|
||||||
// le chemin est vide, on renvoie 0
|
|
||||||
return(0);
|
|
||||||
} else if (path_parts.count() == 1) {
|
|
||||||
// il n'y a plus qu'une categorie dans le chemin : il faut la creer ici
|
|
||||||
|
|
||||||
// on verifie si la categorie n'existe pas deja
|
|
||||||
if (categories_.contains(path_parts[0])) {
|
|
||||||
return(categories_.value(path_parts[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// on cree un objet
|
|
||||||
XmlElementsCategory *new_category = new XmlElementsCategory(
|
|
||||||
this,
|
|
||||||
xml_parent_collection_
|
|
||||||
);
|
|
||||||
new_category -> name_ = path_parts[0];
|
|
||||||
|
|
||||||
// on l'integre dans la liste des sous-categories connues
|
|
||||||
categories_.insert(path_parts[0], new_category);
|
|
||||||
connect(new_category, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
connect(new_category, SIGNAL(removed(const QString &)), this, SLOT(componentRemoved(const QString &)));
|
|
||||||
|
|
||||||
// on le renvoie
|
|
||||||
return(new_category);
|
|
||||||
} else {
|
|
||||||
// il y a plusieurs categories dans le chemin :
|
|
||||||
// on delegue le travail a la premiere sous-categorie
|
|
||||||
|
|
||||||
// a-t-on la premiere sous-categorie ?
|
|
||||||
if (!categories_.contains(path_parts.first())) {
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// on a la premiere sous-categorie
|
|
||||||
ElementsCategory *first_sub_cat = categories_.value(path_parts.first());
|
|
||||||
|
|
||||||
// on demande a la premiere sous-categorie de fournir la categorie finale
|
|
||||||
path_parts.removeFirst();
|
|
||||||
return(first_sub_cat -> category(path_parts.join("/")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la liste des elements de la categorie
|
|
||||||
*/
|
|
||||||
QList<ElementDefinition *> XmlElementsCategory::elements() {
|
|
||||||
QList<ElementDefinition *> elmt_list;
|
|
||||||
|
|
||||||
QList<QString> keys(elements_.keys());
|
|
||||||
qSort(keys.begin(), keys.end());
|
|
||||||
foreach(QString key, keys) elmt_list << elements_[key];
|
|
||||||
return(elmt_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return l'element correspondant au chemin virtuel elmt_path, ou 0 en cas d'echec
|
|
||||||
@param elmt_path Chemin virtuel de l'element voulu
|
|
||||||
*/
|
|
||||||
ElementDefinition *XmlElementsCategory::element(const QString &elmt_path) {
|
|
||||||
// recupere les differentes parties du chemin
|
|
||||||
QString elmt_path_(elmt_path);
|
|
||||||
QStringList path_parts = elmt_path_.split(QChar('/'), QString::SkipEmptyParts, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
if (!path_parts.count()) {
|
|
||||||
// chemin vide
|
|
||||||
return(0);
|
|
||||||
} else if (path_parts.count() == 1) {
|
|
||||||
// seulement le nom de fichier
|
|
||||||
QString element_filename = path_parts.takeLast();
|
|
||||||
if (!elements_.contains(element_filename)) {
|
|
||||||
return(0);
|
|
||||||
} else {
|
|
||||||
return(elements_.value(element_filename));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// separe le nom de fichier du chemin de la categorie et recupere celle-ci
|
|
||||||
QString element_filename = path_parts.takeLast();
|
|
||||||
ElementsCategory *elmt_cat = category(path_parts.join("/"));
|
|
||||||
if (!elmt_cat) {
|
|
||||||
return(0);
|
|
||||||
} else {
|
|
||||||
return(elmt_cat -> element(element_filename));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cree un element. La categorie parente doit exister.
|
|
||||||
@param path chemin d'un element a creer sous la forme d'une adresse
|
|
||||||
virtuelle comme common://cat1/cat2/cat3/dog.elmt
|
|
||||||
@return le nouvel element demande, ou 0 en cas d'echec
|
|
||||||
*/
|
|
||||||
ElementDefinition *XmlElementsCategory::createElement(const QString &path) {
|
|
||||||
// on ne doit pas etre en lecture seule
|
|
||||||
if (!isWritable()) return(0);
|
|
||||||
|
|
||||||
// recupere les differentes parties du chemin
|
|
||||||
QString cat_path_(path);
|
|
||||||
QStringList path_parts = cat_path_.split(QChar('/'), QString::SkipEmptyParts, Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
if (!path_parts.count()) {
|
|
||||||
// le chemin est vide, on renvoie 0
|
|
||||||
return(0);
|
|
||||||
} else if (path_parts.count() == 1) {
|
|
||||||
// il n'y a plus que l'element dans le chemin : il faut le creer ici
|
|
||||||
|
|
||||||
// on verifie si l'element n'existe pas deja
|
|
||||||
if (elements_.contains(path_parts[0])) {
|
|
||||||
return(elements_.value(path_parts[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// on cree un objet
|
|
||||||
XmlElementDefinition *new_element = new XmlElementDefinition(
|
|
||||||
path_parts[0],
|
|
||||||
this,
|
|
||||||
xml_parent_collection_
|
|
||||||
);
|
|
||||||
|
|
||||||
// on l'integre dans la liste des elements connus
|
|
||||||
elements_.insert(path_parts[0], new_element);
|
|
||||||
connect(new_element, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
connect(new_element, SIGNAL(removed(const QString &)), this, SLOT(componentRemoved(const QString &)));
|
|
||||||
|
|
||||||
// on le renvoie
|
|
||||||
return(new_element);
|
|
||||||
} else {
|
|
||||||
// il y a plusieurs categories dans le chemin :
|
|
||||||
// on delegue le travail a la premiere sous-categorie
|
|
||||||
|
|
||||||
// a-t-on la premiere sous-categorie ?
|
|
||||||
if (!categories_.contains(path_parts.first())) {
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// on a la premiere sous-categorie
|
|
||||||
ElementsCategory *first_sub_cat = categories_.value(path_parts.first());
|
|
||||||
|
|
||||||
// on demande a la premiere sous-categorie de fournir la categorie finale
|
|
||||||
path_parts.removeFirst();
|
|
||||||
return(first_sub_cat -> createElement(path_parts.join("/")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la categorie existe, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::exists() {
|
|
||||||
// la seule raison qu'une categorie aurait de ne pas exister est l'absence
|
|
||||||
// de nom
|
|
||||||
return(!name_.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la categorie est accessible en lecture, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::isReadable() {
|
|
||||||
// une categorie XML n'a aucune raison de ne pas etre accessible en lecture
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la categorie est accessible en ecriture, false sinon
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::isWritable() {
|
|
||||||
// une categorie XML peut etre en lecture seule si le projet auquel elle
|
|
||||||
// appartient l'est
|
|
||||||
if (QETProject *parent_project = project()) {
|
|
||||||
return(!parent_project -> isReadOnly());
|
|
||||||
} else {
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cette methode ne fait rien. Recharger une categorie XML n'a pas vraiment de
|
|
||||||
sens.
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::reload() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime la categorie et son contenu
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::remove() {
|
|
||||||
removeContent();
|
|
||||||
emit(removed(name_));
|
|
||||||
write();
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime le contenu de la categorie sans supprimer la categorie elle-meme.
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::removeContent() {
|
|
||||||
// suppression des sous-categories
|
|
||||||
foreach(QString cat_name, categories_.keys()) {
|
|
||||||
ElementsCategory *cat = categories_.value(cat_name);
|
|
||||||
if (cat -> remove()) {
|
|
||||||
categories_.take(cat_name);
|
|
||||||
delete cat;
|
|
||||||
} else {
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// suppression des elements
|
|
||||||
foreach(QString elmt_name, elements_.keys()) {
|
|
||||||
ElementDefinition *elmt = elements_.value(elmt_name);
|
|
||||||
if (elmt -> remove()) {
|
|
||||||
elements_.take(elmt_name);
|
|
||||||
delete elmt;
|
|
||||||
} else {
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write();
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ecrit la categorie.
|
|
||||||
Comme il s'agit d'une categorie embarquee, cette methode emet simplement le
|
|
||||||
signal written pour indiquer qu'il faut enregistrer la collection / le
|
|
||||||
projet.
|
|
||||||
*/
|
|
||||||
bool XmlElementsCategory::write() {
|
|
||||||
// indique que la categorie a ete changee
|
|
||||||
emit(written());
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return un Element XML decrivant la categorie et son contenu
|
|
||||||
@param xml_doc Document XML a utiliser pour creer l'element XML
|
|
||||||
*/
|
|
||||||
QDomElement XmlElementsCategory::writeXml(QDomDocument &xml_doc) const {
|
|
||||||
QDomElement category_elmt = xml_doc.createElement("category");
|
|
||||||
if (!isRootCategory()) {
|
|
||||||
category_elmt.setAttribute("name", name_);
|
|
||||||
category_elmt.appendChild(category_names.toXml(xml_doc));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(XmlElementsCategory *subcat, categories_) {
|
|
||||||
category_elmt.appendChild(subcat -> writeXml(xml_doc));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(XmlElementDefinition *elmt, elements_) {
|
|
||||||
category_elmt.appendChild(elmt -> writeXml(xml_doc));
|
|
||||||
}
|
|
||||||
|
|
||||||
return(category_elmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait qu'une sous-categorie ou un element ait ete enregistre
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::componentWritten() {
|
|
||||||
write();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait qu'une sous-categorie ou un element ait ete supprime
|
|
||||||
@param path Chemin de l'element ou de la categorie supprime(e)
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::componentRemoved(const QString &path) {
|
|
||||||
if (elements_.contains(path)) {
|
|
||||||
elements_.remove(path);
|
|
||||||
write();
|
|
||||||
} else if (categories_.contains(path)) {
|
|
||||||
categories_.remove(path);
|
|
||||||
write();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime le contenu de la categorie en memoire
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::deleteContent() {
|
|
||||||
// suppression des elements
|
|
||||||
foreach(QString elmt_name, elements_.keys()) {
|
|
||||||
XmlElementDefinition *elmt = elements_.take(elmt_name);
|
|
||||||
delete elmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// suppression des categories
|
|
||||||
foreach(QString cat_name, categories_.keys()) {
|
|
||||||
XmlElementsCategory *cat = categories_.take(cat_name);
|
|
||||||
delete cat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Charge dans cet objet le contenu de la categorie a partir d'un element XML.
|
|
||||||
@param xml_element element XML a analyser
|
|
||||||
*/
|
|
||||||
void XmlElementsCategory::loadContent(const QDomElement &xml_element) {
|
|
||||||
deleteContent();
|
|
||||||
name_.clear();
|
|
||||||
category_names.clearNames();
|
|
||||||
|
|
||||||
// charge le nom de la categorie pour son chemin virtuel
|
|
||||||
name_ = xml_element.attribute("name");
|
|
||||||
|
|
||||||
// charge les noms affiches de la categorie
|
|
||||||
category_names.fromXml(xml_element);
|
|
||||||
|
|
||||||
// charge les categories et elements
|
|
||||||
QDomElement current_element;
|
|
||||||
for (QDomNode node = xml_element.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
|
||||||
if (!node.isElement()) continue;
|
|
||||||
current_element = node.toElement();
|
|
||||||
|
|
||||||
// les sous-categories et elements sans nom sont ignores
|
|
||||||
if (!current_element.hasAttribute("name")) continue;
|
|
||||||
|
|
||||||
if (current_element.tagName() == "category") {
|
|
||||||
XmlElementsCategory *new_category = new XmlElementsCategory(current_element, this, xml_parent_collection_);
|
|
||||||
categories_.insert(current_element.attribute("name"), new_category);
|
|
||||||
connect(new_category, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
connect(new_category, SIGNAL(removed(const QString &)), this, SLOT(componentRemoved(const QString &)));
|
|
||||||
} else if (current_element.tagName() == "element") {
|
|
||||||
|
|
||||||
XmlElementDefinition *new_element = new XmlElementDefinition(current_element, this, xml_parent_collection_);
|
|
||||||
elements_.insert(current_element.attribute("name"), new_element);
|
|
||||||
connect(new_element, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
connect(new_element, SIGNAL(removed(const QString &)), this, SLOT(componentRemoved(const QString &)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 XML_ELEMENTS_CATEGORY
|
|
||||||
#define XML_ELEMENTS_CATEGORY
|
|
||||||
#include <QtXml>
|
|
||||||
#include "elementscategory.h"
|
|
||||||
class XmlElementsCollection;
|
|
||||||
class XmlElementDefinition;
|
|
||||||
/**
|
|
||||||
This class represents an elements category stored within an XML document
|
|
||||||
(e.g. the embedded collection of a QET project).
|
|
||||||
*/
|
|
||||||
class XmlElementsCategory : public ElementsCategory {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// constructors, destructor
|
|
||||||
public:
|
|
||||||
XmlElementsCategory(XmlElementsCategory * = 0, XmlElementsCollection * = 0);
|
|
||||||
XmlElementsCategory(const QDomElement &, XmlElementsCategory * = 0, XmlElementsCollection * = 0);
|
|
||||||
virtual ~XmlElementsCategory();
|
|
||||||
|
|
||||||
private:
|
|
||||||
XmlElementsCategory(const XmlElementsCategory &);
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
virtual QString pathName() const;
|
|
||||||
virtual QString virtualPath();
|
|
||||||
|
|
||||||
virtual QString filePath();
|
|
||||||
virtual bool hasFilePath();
|
|
||||||
virtual void setFilePath(const QString &);
|
|
||||||
|
|
||||||
virtual QList<ElementsCategory *> categories();
|
|
||||||
virtual ElementsCategory *category(const QString &);
|
|
||||||
virtual ElementsCategory *createCategory(const QString &);
|
|
||||||
|
|
||||||
virtual QList<ElementDefinition *> elements();
|
|
||||||
virtual ElementDefinition *element(const QString &);
|
|
||||||
virtual ElementDefinition *createElement(const QString &);
|
|
||||||
|
|
||||||
virtual bool exists();
|
|
||||||
virtual bool isReadable();
|
|
||||||
virtual bool isWritable();
|
|
||||||
|
|
||||||
virtual void reload();
|
|
||||||
virtual bool remove();
|
|
||||||
virtual bool removeContent();
|
|
||||||
virtual bool write();
|
|
||||||
|
|
||||||
virtual QDomElement writeXml(QDomDocument &) const;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void componentWritten();
|
|
||||||
void componentRemoved(const QString &path);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void written();
|
|
||||||
void removed(const QString &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void deleteContent();
|
|
||||||
void loadContent(const QDomElement &);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
protected:
|
|
||||||
/// Parent collection
|
|
||||||
XmlElementsCollection *xml_parent_collection_;
|
|
||||||
/// Parent category
|
|
||||||
XmlElementsCategory *xml_parent_category_;
|
|
||||||
/// Child categories
|
|
||||||
QHash<QString, XmlElementsCategory *> categories_;
|
|
||||||
/// Child elements
|
|
||||||
QHash<QString, XmlElementDefinition *> elements_;
|
|
||||||
/// Nae of this category within the tree
|
|
||||||
QString name_;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 "xmlelementscollection.h"
|
|
||||||
#include "xmlelementscategory.h"
|
|
||||||
#include "qetproject.h"
|
|
||||||
#include "qetapp.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Construit une collection vide
|
|
||||||
@param parent Item parent
|
|
||||||
*/
|
|
||||||
XmlElementsCollection::XmlElementsCollection(ElementsCollectionItem *parent) :
|
|
||||||
ElementsCollection(parent)
|
|
||||||
{
|
|
||||||
protocol_ = "unknown";
|
|
||||||
project_ = 0;
|
|
||||||
// cree une categorie racine vide
|
|
||||||
root = new XmlElementsCategory(0, this);
|
|
||||||
connect(root, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Construit une collection a partir d'un element XML suppose la decrire
|
|
||||||
@param xml_element Element XML decrivant la collection
|
|
||||||
@param parent Item parent
|
|
||||||
*/
|
|
||||||
XmlElementsCollection::XmlElementsCollection(const QDomElement &xml_element, ElementsCollectionItem *parent) :
|
|
||||||
ElementsCollection(parent)
|
|
||||||
{
|
|
||||||
protocol_ = "unknown";
|
|
||||||
project_ = 0;
|
|
||||||
// cree sa categorie racine a partir de l'element XML
|
|
||||||
root = new XmlElementsCategory(xml_element, 0, this);
|
|
||||||
connect(root, SIGNAL(written()), this, SLOT(componentWritten()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Destructeur
|
|
||||||
*/
|
|
||||||
XmlElementsCollection::~XmlElementsCollection() {
|
|
||||||
deleteContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString XmlElementsCollection::title() const {
|
|
||||||
if (!title_.isEmpty()) return(title_);
|
|
||||||
|
|
||||||
// if the title attribute is empty, we generate a suitable one using the
|
|
||||||
// parent project
|
|
||||||
QString final_title;
|
|
||||||
if (project_) {
|
|
||||||
QString project_title = project_ -> title();
|
|
||||||
if (project_title.isEmpty()) {
|
|
||||||
final_title = QString(
|
|
||||||
tr(
|
|
||||||
"Collection du projet sans titre (id %1)",
|
|
||||||
"Elements collection title when the parent project has an empty title -- %1 is the project internal id"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final_title = final_title.arg(QETApp::projectId(project_));
|
|
||||||
} else {
|
|
||||||
final_title = QString(
|
|
||||||
tr(
|
|
||||||
"Collection du projet \"%1\"",
|
|
||||||
"Elements collection title when the project has a suitable title -- %1 is the project title"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
final_title = final_title.arg(project_title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(final_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementsCategory *XmlElementsCollection::rootCategory() {
|
|
||||||
return(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return toujours false ; une collection XML n'est representee nul part sur
|
|
||||||
le systeme de fichiers.
|
|
||||||
*/
|
|
||||||
bool XmlElementsCollection::hasFilePath() {
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return le chemin du repertoire representant cette collection
|
|
||||||
*/
|
|
||||||
QString XmlElementsCollection::filePath() {
|
|
||||||
return(QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ne fait rien - une collection XML n'est representee nul part sur le systeme
|
|
||||||
de fichiers.
|
|
||||||
*/
|
|
||||||
void XmlElementsCollection::setFilePath(const QString &) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlElementsCollection::reload() {
|
|
||||||
if (root) root -> reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return toujours true
|
|
||||||
*/
|
|
||||||
bool XmlElementsCollection::exists() {
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la collection est accessible en lecture
|
|
||||||
*/
|
|
||||||
bool XmlElementsCollection::isReadable() {
|
|
||||||
// une collection XML n'a aucune raison de ne pas etre accessible en lecture
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XmlElementsCollection::isWritable() {
|
|
||||||
// une collection XML peut etre en lecture seule si le projet auquel elle
|
|
||||||
// appartient l'est
|
|
||||||
if (QETProject *parent_project = project()) {
|
|
||||||
return(!parent_project -> isReadOnly());
|
|
||||||
} else {
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XmlElementsCollection::write() {
|
|
||||||
emit(written());
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return always false, since an XMl-based elements collection should never
|
|
||||||
be cached.
|
|
||||||
*/
|
|
||||||
bool XmlElementsCollection::isCacheable() const {
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement XmlElementsCollection::writeXml(QDomDocument &xml_doc) const {
|
|
||||||
QDomElement collection_elmt = root -> writeXml(xml_doc);
|
|
||||||
collection_elmt.setTagName("collection");
|
|
||||||
xml_doc.appendChild(collection_elmt);
|
|
||||||
return(collection_elmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlElementsCollection::componentWritten() {
|
|
||||||
write();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Supprime le contenu en memoire de cette collection
|
|
||||||
*/
|
|
||||||
void XmlElementsCollection::deleteContent() {
|
|
||||||
delete root;
|
|
||||||
root = 0;
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2016 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 XML_ELEMENTS_COLLECTION
|
|
||||||
#define XML_ELEMENTS_COLLECTION
|
|
||||||
#include <QtXml>
|
|
||||||
#include "elementscollection.h"
|
|
||||||
class XmlElementsCategory;
|
|
||||||
/**
|
|
||||||
This class represents an elements collection stored within an XML document
|
|
||||||
(e.g. the embedded collection of a QET project).
|
|
||||||
*/
|
|
||||||
class XmlElementsCollection : public ElementsCollection {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
// constructors, destructor
|
|
||||||
XmlElementsCollection(ElementsCollectionItem * = 0);
|
|
||||||
XmlElementsCollection(const QDomElement &, ElementsCollectionItem * = 0);
|
|
||||||
virtual ~XmlElementsCollection();
|
|
||||||
|
|
||||||
private:
|
|
||||||
XmlElementsCollection(const XmlElementsCollection &);
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
virtual QString title() const;
|
|
||||||
virtual ElementsCategory *rootCategory();
|
|
||||||
virtual bool hasFilePath();
|
|
||||||
virtual QString filePath();
|
|
||||||
virtual void setFilePath(const QString &);
|
|
||||||
virtual void reload();
|
|
||||||
virtual bool exists();
|
|
||||||
virtual bool isReadable();
|
|
||||||
virtual bool isWritable();
|
|
||||||
virtual bool write();
|
|
||||||
virtual bool isCacheable() const;
|
|
||||||
|
|
||||||
virtual QDomElement writeXml(QDomDocument &) const;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void componentWritten();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void written();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void deleteContent();
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
private:
|
|
||||||
XmlElementsCategory *root;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user