Improve the way how an element is updated in the new element panel.

Now Qet only use the new embbeded collection (XmlElementCollection).
No need to reload the old element panel for add a new element created by the new element panel
Elements are always imported to the embbeded collection of a project


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4468 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-05-05 13:31:04 +00:00
parent dd1bfabe2d
commit 168467abb0
18 changed files with 522 additions and 271 deletions

View File

@@ -142,6 +142,30 @@ ElementCollectionItem *ElementCollectionItem::lastItemForPath(const QString &pat
return nullptr;
}
/**
* @brief ElementCollectionItem::itemAtPath
* @param path
* @return the item at path or nullptr if doesn't exist
*/
ElementCollectionItem *ElementCollectionItem::itemAtPath(const QString &path)
{
QStringList str_list = path.split("/");
if (str_list.isEmpty()) return nullptr;
ElementCollectionItem *match_eci = this;
foreach (QString str, str_list) {
ElementCollectionItem *eci = match_eci->childWithCollectionName(str);
if (!eci) {
return nullptr;
}
else {
match_eci = eci;
}
}
return match_eci;
}
/**
* @brief ElementCollectionItem::rowForInsertItem
* Return the row for insert a new child item to this item with name @collection_name.
@@ -396,22 +420,3 @@ void ElementCollectionItem::setBackgroundColor(Qt::GlobalColor color, bool show)
m_bg_color = color;
m_show_bg_color = show;
}
/**
* @brief ElementCollectionItem::canRemoveContent
* @return true if this item can remove the content that he represent
* By default return false.
*/
bool ElementCollectionItem::canRemoveContent() {
return false;
}
/**
* @brief ElementCollectionItem::removeContent
* Remove the content that he represent this item (a directory or an element).
* This method do nothing and return false. Inherit it, to handle removing
* @return true if the content was successfully removed
*/
bool ElementCollectionItem::removeContent() {
return false;
}

View File

@@ -47,6 +47,7 @@ class ElementCollectionItem : public QObject
ElementCollectionItem *child(int row) const;
ElementCollectionItem *childWithCollectionName(QString name) const;
ElementCollectionItem *lastItemForPath(const QString &path, QString &newt_item);
ElementCollectionItem *itemAtPath(const QString &path);
int rowForInsertItem(const QString &collection_name);
virtual void insertNewItem(const QString &collection_name);
int childCount() const;
@@ -72,10 +73,6 @@ class ElementCollectionItem : public QObject
int indexOfChild(ElementCollectionItem *child) const;
void setBackgroundColor(Qt::GlobalColor color, bool show);
virtual bool canRemoveContent();
virtual bool removeContent();
signals:
void beginInsertRows(ElementCollectionItem *parent, int first, int last);
void endInsertRows();

View File

@@ -21,6 +21,7 @@
#include "fileelementcollectionitem.h"
#include "xmlprojectelementcollectionitem.h"
#include "qetproject.h"
#include "xmlelementcollection.h"
/**
* @brief ElementsCollectionModel::ElementsCollectionModel
@@ -273,7 +274,7 @@ void ElementsCollectionModel::addCustomCollection()
/**
* @brief ElementsCollectionModel::addProject
* Add @project to the disalyed collection
* Add @project to the displayed collection
* @param project
* @return true if project was successfully added. If project is already
* handled, return false.
@@ -288,21 +289,27 @@ bool ElementsCollectionModel::addProject(QETProject *project)
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem(project, m_root_item);
bool r = m_root_item->insertChild(row, xpeci);
endInsertRows();
connect(project, &QETProject::elementIntegratedToCollection, this, &ElementsCollectionModel::elementIntegratedToCollection);
connect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
return r;
}
/**
* @brief ElementsCollectionModel::removeProject
* Remove @project from this model
* @param project
* @return true if the project was successfully removed, false if not (or project doesn't managed)
*/
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()))
{
if (removeRows(row, 1, QModelIndex())) {
m_project_list.removeOne(project);
disconnect(project, &QETProject::elementIntegratedToCollection, this, &ElementsCollectionModel::elementIntegratedToCollection);
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
return true;
}
else
@@ -339,24 +346,73 @@ XmlProjectElementCollectionItem *ElementsCollectionModel::itemForProject(QETProj
* @brief ElementsCollectionModel::elementAddedToEmbeddedCollection
* When an element is added to embedded collection of a project,
* this method create and display the new element
* @param project -The project where new element was added.
* @param path -The path of the new element in the embedded collection of project
* @param path -The path of the new element in the embedded collection of a project
*/
void ElementsCollectionModel::elementIntegratedToCollection(QETProject *project, QString path)
void ElementsCollectionModel::elementIntegratedToCollection (QString path)
{
XmlProjectElementCollectionItem *xpeci = itemForProject(project);
if (!xpeci) return;
QObject *object = sender();
XmlElementCollection *collection = static_cast<XmlElementCollection *> (object);
if (!collection) return;
QString collection_name;
ElementCollectionItem *eci = xpeci->lastItemForPath(path, collection_name);
if (!eci) return;
QETProject *project = nullptr;
int new_row = eci->rowForInsertItem(collection_name);
if (new_row <= -1) return;
QModelIndex parent_index = createIndex(eci->row(), 0, eci);
beginInsertRows(parent_index, new_row, new_row);
eci->insertNewItem(collection_name);
endInsertRows();
//Get the owner project of the collection
foreach (QETProject *prj, m_project_list) {
if (prj->embeddedElementCollection() == collection) {
project = prj;
}
}
if (project) {
XmlProjectElementCollectionItem *xpeci = itemForProject(project);
if (!xpeci) return;
QString collection_name;
ElementCollectionItem *eci = xpeci->lastItemForPath(path, collection_name);
if (!eci) return;
int new_row = eci->rowForInsertItem(collection_name);
if (new_row <= -1) return;
QModelIndex parent_index = createIndex(eci->row(), 0, eci);
beginInsertRows(parent_index, new_row, new_row);
eci->insertNewItem(collection_name);
endInsertRows();
}
}
/**
* @brief ElementsCollectionModel::updateItem
* Update the item at path
* @param path
*/
void ElementsCollectionModel::updateItem(QString path)
{
QObject *object = sender();
XmlElementCollection *collection = static_cast<XmlElementCollection *> (object);
if (!collection) return;
QETProject *project = nullptr;
//Get the owner project of the collection
foreach (QETProject *prj, m_project_list) {
if (prj->embeddedElementCollection() == collection) {
project = prj;
}
}
if (project) {
XmlProjectElementCollectionItem *xpeci = itemForProject(project);
if (!xpeci) {
return;
}
ElementCollectionItem *eci = xpeci->itemAtPath(path);
if (!eci) {
return;
}
eci->clearData();
}
}
void ElementsCollectionModel::bir(ElementCollectionItem *eci, int first, int last)

View File

@@ -61,7 +61,8 @@ class ElementsCollectionModel : public QAbstractItemModel
private:
XmlProjectElementCollectionItem *itemForProject(QETProject *project);
void elementIntegratedToCollection (QETProject *project, QString path);
void elementIntegratedToCollection (QString path);
void updateItem (QString path);
//Use as slot in method drop mime data
void bir(ElementCollectionItem *eci, int first, int last);
void brr(ElementCollectionItem *eci, int first, int last);

View File

@@ -263,21 +263,26 @@ void ElementsCollectionWidget::deleteElement()
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
if (!eci) return;
if (!(eci->isElement() && eci->canRemoveContent())) return;
ElementsLocation loc(eci->collectionPath());
if (! (loc.isElement() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
if (QET::QetMessageBox::question(this,
tr("Supprimer l'élément ?", "message box title"),
tr("Êtes-vous sûr de vouloir supprimer cet élément ?\n", "message box content"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
if (!eci->removeContent())
QFile file(loc.fileSystemPath());
if (file.remove())
{
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
else
{
QET::QetMessageBox::warning(this,
tr("Suppression de l'élément", "message box title"),
tr("La suppression de l'élément a échoué.", "message box content"));
}
else
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
}
@@ -290,7 +295,9 @@ void ElementsCollectionWidget::deleteDirectory()
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
if (!eci) return;
if (!(eci->isDir() && eci->canRemoveContent())) return;
ElementsLocation loc (eci->collectionPath());
if (! (loc.isDirectory() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
if (QET::QetMessageBox::question(this,
tr("Supprimer le dossier?", "message box title"),
@@ -299,14 +306,17 @@ void ElementsCollectionWidget::deleteDirectory()
"message box content"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
if (!eci->removeContent())
QDir dir (loc.fileSystemPath());
if (dir.removeRecursively())
{
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
else
{
QET::QetMessageBox::warning(this,
tr("Suppression du dossier", "message box title"),
tr("La suppression du dossier a échoué.", "message box content"));
}
else
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
}
@@ -344,8 +354,9 @@ void ElementsCollectionWidget::newDirectory()
ElementsLocation location(feci->collectionPath());
ElementsCategoryEditor new_dir_editor(location, false, this);
if (new_dir_editor.exec() == QDialog::Accepted)
reload();;
if (new_dir_editor.exec() == QDialog::Accepted) {
reload();
}
}
/**

View File

@@ -677,3 +677,19 @@ QString ElementsLocation::fileName() const
uint qHash(const ElementsLocation &location) {
return(qHash(location.toString()));
}
QDebug operator<< (QDebug debug, const ElementsLocation &location)
{
QDebugStateSaver saver(debug);
debug.noquote();
QString msg;
msg += "ElementsLocation(";
msg += (location.isProject()? location.projectCollectionPath() : location.collectionPath(true));
msg += location.exist()? ", true" : ", false";
msg +=")";
debug << msg;
return debug;
}

View File

@@ -83,6 +83,9 @@ class ElementsLocation
public:
static int MetaTypeId; ///< Id of the corresponding Qt meta type
};
QDebug operator<<(QDebug debug, const ElementsLocation &location);
Q_DECLARE_METATYPE(ElementsLocation)
uint qHash(const ElementsLocation &);
#endif

View File

@@ -391,40 +391,6 @@ QString FileElementCollectionItem::name()
return m_name;
}
/**
* @brief FileElementCollectionItem::canRemoveContent
* Reimplemented from ElementCollectionItem
* @return
*/
bool FileElementCollectionItem::canRemoveContent()
{
if (isCommonCollection()) return false;
else if (isDir() && isCollectionRoot()) return false;
else return true;
}
/**
* @brief FileElementCollectionItem::removeContent
* Reimplemented from ElementCollectionItem
* @return
*/
bool FileElementCollectionItem::removeContent()
{
if (!canRemoveContent()) return false;
if (isElement())
{
QFile file(fileSystemPath());
return file.remove();
}
else if (isDir() && !isCollectionRoot())
{
QDir dir (fileSystemPath());
return dir.removeRecursively();
}
return false;
}
void FileElementCollectionItem::insertNewItem(const QString &collection_name)
{
if (collection_name.isEmpty()) return;

View File

@@ -60,8 +60,6 @@ class FileElementCollectionItem : public ElementCollectionItem
virtual bool isValid() const;
virtual QString name();
virtual bool canRemoveContent();
virtual bool removeContent();
virtual void insertNewItem(const QString &collection_name);
private:

View File

@@ -433,6 +433,7 @@ bool XmlElementCollection::addElementDefinition(const QString &dir_path, const Q
* @brief XmlElementCollection::copy
* Copy the content represented by source (an element or a directory) to destination.
* Destination must be a directory of this collection.
* If the destination already have an item at the same path of source, he will be replaced by source.
* @param source : content to copy
* @param destination : destination of the copy, must be a directory of this collection
* @param rename : rename the copy with @rename else use the name of source
@@ -545,10 +546,12 @@ ElementsLocation XmlElementCollection::copyDirectory(ElementsLocation &source, E
/**
* @brief XmlElementCollection::copyElement
* Copy the element represented by source to destination (must be a directory)
* If element already exist in destination he will be replaced by the new.
* @param source : element to copy
* @param destination : destination of the copy
* @param rename : rename the copy with @rename else use the name of source
* @return
* @return The ElementsLocation of the copy
*/
ElementsLocation XmlElementCollection::copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename)
{
@@ -575,13 +578,25 @@ ElementsLocation XmlElementCollection::copyElement(ElementsLocation &source, Ele
//Remove the previous element with the same path
QDomElement element = child(destination.collectionPath(false) + "/" + new_elmt_name);
if (!element.isNull())
bool removed = false;
if (!element.isNull()) {
element.parentNode().removeChild(element);
removed = true;
}
//Get the xml directory where the new element must be added
QDomElement dir_dom = directory(destination.collectionPath(false));
if (dir_dom.isNull()) return ElementsLocation();
dir_dom.appendChild(elmt_dom);
return ElementsLocation(destination.projectCollectionPath() + "/" + new_elmt_name);
ElementsLocation copy_loc(destination.projectCollectionPath() + "/" + new_elmt_name);
if (removed) {
emit elementChanged(copy_loc.collectionPath(false));
}
else {
emit elementAdded(copy_loc.collectionPath(false));
}
return copy_loc;
}

View File

@@ -62,6 +62,12 @@ class XmlElementCollection : public QObject
* @param collection_path, the path of element in this collection
*/
void elementAdded(QString collection_path);
/**
* @brief elementChanged
* This signal is emited when the defintion of the element at path was changed
* @param collection_path, the path of this element in this collection
*/
void elementChanged (QString collection_path);
public slots:

View File

@@ -172,22 +172,22 @@ bool DiagramEventAddElement::buildElement()
{
if (QETProject::integrateElementToProject(m_location, m_diagram -> project()))
{
QString error_msg;
IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler();
m_integrate_path = m_diagram -> project() -> integrateElement(m_location.toString(), integ_handler, error_msg);
delete integ_handler;
if (m_integrate_path.isEmpty())
{
qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element. Motif : " << qPrintable(error_msg);
ElementsLocation loc = m_diagram->project()->importElement(m_location);
if (loc.exist()) {
m_integrate_path = loc.projectCollectionPath();
}
else {
qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element.";
return false;
}
}
int state;
m_element = ElementFactory::Instance() -> createElement(m_location, 0, &state);
ElementsLocation loc(m_integrate_path);
m_element = ElementFactory::Instance() -> createElement(loc, 0, &state);
//The creation of element failed, we delete it
if (state)
{
if (state) {
delete m_element;
return(false);
}

View File

@@ -279,18 +279,18 @@ void DiagramView::dropEvent(QDropEvent *e) {
Handle the drop of an element.
@param e the QDropEvent describing the current drag'n drop
*/
void DiagramView::handleElementDrop(QDropEvent *e)
void DiagramView::handleElementDrop(QDropEvent *event)
{
//fetch the element location from the drop event
QString elmt_path = e -> mimeData() -> text();
//Build an element from the text of the mime data
ElementsLocation location(event->mimeData()->text());
ElementsLocation location(elmt_path);
if ( !(location.isElement() && location.exist()) )
{
qDebug() << "DiagramView::handleElementDrop, location can't be use : " << location;
return;
}
// verifie qu'il existe un element correspondant a cet emplacement
ElementsCollectionItem *dropped_item = QETApp::collectionItem(location);
if (!dropped_item) return;
diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(e->pos())));
diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(event->pos())));
//Set focus to the view to get event
this->setFocus();
}

View File

@@ -33,6 +33,7 @@
#include "reportproperties.h"
#include "integrationmovetemplateshandler.h"
#include "xmlelementcollection.h"
#include "importelementdialog.h"
#include <QStandardPaths>
@@ -69,8 +70,6 @@ QETProject::QETProject(int diagrams, QObject *parent) :
m_elements_collection = new XmlElementCollection(this);
// une categorie dediee aux elements integres automatiquement
ensureIntegrationCategoryExists();
setupTitleBlockTemplatesCollection();
undo_stack_ = new QUndoStack();
@@ -146,17 +145,10 @@ QETProject::~QETProject()
*/
bool QETProject::integrateElementToProject(const ElementsLocation &location, const QETProject *project)
{
//Integration element must be enable
QSettings settings;
bool auto_integration_enabled = settings.value("diagrameditor/integrate-elements", true).toBool();
if (location.isFileSystem()) {return true;}
if (location.isProject() && (location.project() != project)) {return true;}
//the element belongs there a project and if so, is this another project of the project given by parameter?
bool elmt_from_project = location.project();
bool elmt_from_another_project = elmt_from_project && location.project() != project;
bool must_integrate_element = (elmt_from_another_project || (auto_integration_enabled && !elmt_from_project));
return(must_integrate_element);
return false;
}
/**
@@ -638,24 +630,6 @@ bool QETProject::isEmpty() const {
return(pertinent_diagrams > 0);
}
/**
Cree une categorie dediee aux elements integres automatiquement dans le
projet si celle-ci n'existe pas deja.
@return true si tout s'est bien passe, false sinon
*/
bool QETProject::ensureIntegrationCategoryExists() {
ElementsCategory *root_cat = rootCategory();
if (!root_cat) return(false);
if (root_cat -> category(integration_category_name)) return(true);
ElementsCategory *integration_category = root_cat -> createCategory(integration_category_name);
if (!integration_category) return(false);
integration_category -> setNames(namesListForIntegrationCategory());
return(true);
}
/**
@return la categorie dediee aux elements integres automatiquement dans le
projet ou 0 si celle-ci n'a pu etre creee.
@@ -669,134 +643,94 @@ ElementsCategory *QETProject::integrationCategory() const {
}
/**
Integre un element dans le projet.
Cette methode delegue son travail a la methode
integrateElement(const QString &, MoveElementsHandler *, QString &)
en lui passant un MoveElementsHandler approprie.
@param elmt_location Emplacement de l'element a integrer
@param error_msg Reference vers une chaine de caractere qui contiendra
eventuellement un message d'erreur
@return L'emplacement de l'element apres integration, ou une chaine vide si
l'integration a echoue.
*/
QString QETProject::integrateElement(const QString &elmt_location, QString &error_msg) {
// handler dedie a l'integration d'element
IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler(0);
QString integ_path = integrateElement(elmt_location, integ_handler, error_msg);
delete integ_handler;
return(integ_path);
}
/**
Integre un element dans le projet.
Cette methode prend en parametre l'emplacement d'un element a integrer.
Chaque categorie mentionnee dans le chemin de cet element sera copiee de
maniere non recursive sous la categorie dediee a l'integration si elle
n'existe pas deja.
L'element sera ensuite copiee dans cette copie de la hierarchie d'origine.
En cas de probleme, error_message sera modifiee de facon a contenir un
message decrivant l'erreur rencontree.
@param elmt_path Emplacement de l'element a integrer
@param handler Gestionnaire a utiliser pour gerer les copies d'elements et categories
@param error_message Reference vers une chaine de caractere qui contiendra
eventuellement un message d'erreur
@return L'emplacement de l'element apres integration, ou une chaine vide si
l'integration a echoue.
*/
QString QETProject::integrateElement(const QString &elmt_path, MoveElementsHandler *handler, QString &error_message) {
// on s'assure que le projet a une categorie dediee aux elements importes automatiquement
if (!ensureIntegrationCategoryExists())
{
error_message = tr("Impossible de créer la catégorie pour l'intégration des éléments");
return(QString());
* @brief QETProject::importElement
* Import the element represented by @location to the embbeded collection of this project
* @param location
* @return the location of the imported element, location can be null.
*/
ElementsLocation QETProject::importElement(ElementsLocation &location)
{
//Location isn't an element or doesn't exist
if (! (location.isElement() && location.exist()) ) {
return ElementsLocation();
}
// accede a la categorie d'integration
ElementsCategory *integ_cat = integrationCategory();
// accede a l'element a integrer
ElementsCollectionItem *integ_item = QETApp::collectionItem(ElementsLocation(elmt_path));
ElementDefinition *integ_elmt = integ_item ? integ_item -> toElement() : 0;
if (!integ_item || !integ_elmt)
{
error_message = tr("Impossible d'accéder à l'élément à intégrer");
return(QString());
//Get the path where the element must be imported
QString import_path;
if (location.isFileSystem()) {
import_path = "import/" + location.collectionPath(false);
}
// recopie l'arborescence de l'element de facon non recursive
QList<ElementsCategory *> integ_par_cat = integ_elmt -> parentCategories();
ElementsCategory *target_cat = integ_cat;
foreach(ElementsCategory *par_cat, integ_par_cat)
{
if (par_cat -> isRootCategory()) continue;
if (ElementsCategory *existing_cat = target_cat -> category(par_cat -> pathName()))
{
// la categorie cible existe deja : on continue la progression
target_cat = existing_cat;
if (location.isProject()) {
if (location.project() == this) {
return location;
}
else
{
// la categorie cible n'existe pas : on la cree par recopie
ElementsCollectionItem *result_cat = par_cat -> copy(target_cat, handler, false);
if (!result_cat || !result_cat -> isCategory())
{
error_message = QString(tr("Un problème s'est produit pendant la copie de la catégorie %1")).arg(par_cat -> location().toString());
return(QString());
import_path = location.collectionPath(false);
}
//Element already exist in the embedded collection, we ask what to do to user
if (m_elements_collection->exist(import_path)) {
ElementsLocation existing_location(import_path, this);
//@existing_location and @location have the same uuid, so it is the same element
if (existing_location.uuid() == location.uuid()) {
return existing_location;
}
ImportElementDialog ied;
if (ied.exec() == QDialog::Accepted) {
QET::Action action = ied.action();
//Use the exisitng element
if (action == QET::Ignore) {
return existing_location;
}
target_cat = result_cat -> toCategory();
//Erase the existing element, and use the newer instead
else if (action == QET::Erase) {
ElementsLocation parent_loc = existing_location.parent();
return m_elements_collection->copy(location, parent_loc);
}
//Add the new element with an other name.
else if (action == QET::Rename) {
int a = 0;
QString parent_path = existing_location.parent().projectCollectionPath();
QString name_ = existing_location.fileName();
name_.remove(".elmt");
ElementsLocation loc;
do
{
a++;
QString new_path = parent_path + "/" + name_ + QString::number(a) + ".elmt";
loc = ElementsLocation (new_path);
} while (loc.exist());
ElementsLocation parent_loc = existing_location.parent();
return m_elements_collection->copy(location, parent_loc, loc.fileName());
}
else {
return ElementsLocation();
}
}
else {
return ElementsLocation();
}
}
//Element doesn't exist in the collection, we just import it
else {
ElementsLocation loc(m_elements_collection->addElement(location), this);
if (!loc.exist()) {
qDebug() << "QETProject::importElement : failed to import location. " << location;
return ElementsLocation();
}
else {
return loc;
}
}
// recopie l'element
ElementsLocation result;
if (ElementDefinition *existing_elmt = target_cat -> element(integ_item -> pathName()))
{
// l'element existe deja - on demande au handler ce que l'on doit faire
QET::Action action = handler -> elementAlreadyExists(integ_elmt, existing_elmt);
if (action == QET::Ignore)
{
// il faut conserver et utiliser l'element deja integre
result = existing_elmt -> location();
}
else if (action == QET::Erase)
{
// il faut ecraser l'element deja integre
BasicMoveElementsHandler *erase_handler = new BasicMoveElementsHandler();
result = copyElementWithHandler(integ_elmt, target_cat, erase_handler, error_message);
delete erase_handler;
}
else if (action == QET::Rename)
{
// il faut faire cohabiter les deux elements en renommant le nouveau
QString integ_element_name = handler -> nameForRenamingOperation();
BasicMoveElementsHandler *rename_handler = new BasicMoveElementsHandler();
rename_handler -> setActionIfItemAlreadyExists(QET::Rename);
rename_handler -> setNameForRenamingOperation(integ_element_name);
result = copyElementWithHandler(integ_elmt, target_cat, rename_handler, error_message);
delete rename_handler;
}
else
{
// il faut annuler la pose de l'element
result = ElementsLocation();
}
}
else
{
// integre l'element normalement
result = copyElementWithHandler(integ_elmt, target_cat, handler, error_message);
ElementsLocation location(elmt_path);
QString xml_path = m_elements_collection->addElement(location);
if (!xml_path.isNull()) emit elementIntegratedToCollection(this, xml_path);
}
if (!result.isNull()) emit(elementIntegrated(this, result));
return(result.toString());
return ElementsLocation();
}
/**

View File

@@ -127,10 +127,8 @@ class QETProject : public QObject
bool isReadOnly() const;
void setReadOnly(bool);
bool isEmpty() const;
bool ensureIntegrationCategoryExists();
ElementsCategory *integrationCategory() const;
QString integrateElement(const QString &, QString &);
QString integrateElement(const QString &, MoveElementsHandler *, QString &);
ElementsLocation importElement(ElementsLocation &location);
QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler);
bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &);
@@ -164,7 +162,6 @@ class QETProject : public QObject
void readOnlyChanged(QETProject *, bool);
void reportPropertiesChanged(QString);
void XRefPropertiesChanged ();
void elementIntegratedToCollection(QETProject *project, QString path);
private slots:
void updateDiagramsFolioData();

View File

@@ -0,0 +1,53 @@
/*
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 "importelementdialog.h"
#include "ui_importelementdialog.h"
ImportElementDialog::ImportElementDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportElementDialog)
{
ui->setupUi(this);
setUpWidget();
}
ImportElementDialog::~ImportElementDialog()
{
delete ui;
}
QET::Action ImportElementDialog::action() const
{
if (ui->m_use_actual_rd->isChecked()) { return QET::Ignore; }
else if (ui->m_erase_actual_rb->isChecked()) { return QET::Erase; }
else if (ui->m_use_both_rb->isChecked()) { return QET::Rename; }
else return QET::Abort;
}
void ImportElementDialog::setUpWidget()
{
QButtonGroup *button_group = new QButtonGroup(this);
button_group->addButton(ui->m_use_actual_rd);
button_group->addButton(ui->m_use_drop_rb);
QButtonGroup *button_group_drop = new QButtonGroup(this);
button_group_drop->addButton(ui->m_erase_actual_rb);
button_group_drop->addButton(ui->m_use_both_rb);
ui->m_use_drop_rb->setChecked(true);
ui->m_use_both_rb->setChecked(true);
}

View File

@@ -0,0 +1,46 @@
/*
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 IMPORTELEMENTDIALOG_H
#define IMPORTELEMENTDIALOG_H
#include <QDialog>
#include "qet.h"
namespace Ui {
class ImportElementDialog;
}
class ImportElementDialog : public QDialog
{
Q_OBJECT
public:
explicit ImportElementDialog(QWidget *parent = 0);
~ImportElementDialog();
QET::Action action() const;
private:
void setUpWidget();
void setUpConnection();
private:
Ui::ImportElementDialog *ui;
};
#endif // IMPORTELEMENTDIALOG_H

View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportElementDialog</class>
<widget class="QDialog" name="ImportElementDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>754</width>
<height>176</height>
</rect>
</property>
<property name="windowTitle">
<string>Intégration d'un élément</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>L'élément a déjà été intégré dans le projet. Toutefois, la version que vous tentez de poser semble différente. Que souhaitez-vous faire ?</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_use_actual_rd">
<property name="text">
<string>Utiliser l'élément déjà integré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_use_drop_rb">
<property name="text">
<string>Intégrer l'élément déposé</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>15</number>
</property>
<item>
<widget class="QRadioButton" name="m_erase_actual_rb">
<property name="text">
<string>Écraser l'élément déjà intégé</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_use_both_rb">
<property name="text">
<string>Faire cohabiter les deux éléments</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportElementDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportElementDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_use_drop_rb</sender>
<signal>toggled(bool)</signal>
<receiver>m_erase_actual_rb</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>375</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
<x>375</x>
<y>188</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_use_drop_rb</sender>
<signal>toggled(bool)</signal>
<receiver>m_use_both_rb</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>375</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
<x>375</x>
<y>214</y>
</hint>
</hints>
</connection>
</connections>
</ui>