[qet] [4555] Element panel widget : improve how an item is updated or added after editing an element with the Qet Element Editor. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] [4555] Element panel widget : improve how an item is updated or added after editing an element with the Qet Element Editor.
- From: subversion@xxxxxxxxxxxxx
- Date: Fri, 17 Jun 2016 10:41:11 +0200
Revision: 4555
Author: blacksun
Date: 2016-06-17 10:41:09 +0200 (Fri, 17 Jun 2016)
Log Message:
-----------
Element panel widget : improve how an item is updated or added after editing an element with the Qet Element Editor.
Modified Paths:
--------------
trunk/sources/ElementsCollection/elementscollectionmodel.cpp
trunk/sources/ElementsCollection/elementscollectionmodel.h
trunk/sources/ElementsCollection/elementscollectionwidget.cpp
trunk/sources/ElementsCollection/elementscollectionwidget.h
trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
trunk/sources/ElementsCollection/fileelementcollectionitem.h
trunk/sources/editor/qetelementeditor.cpp
trunk/sources/editor/qetelementeditor.h
Modified: trunk/sources/ElementsCollection/elementscollectionmodel.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.cpp 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.cpp 2016-06-17 08:41:09 UTC (rev 4555)
@@ -242,6 +242,54 @@
}
/**
+ * @brief ElementsCollectionModel::addLocation
+ * Add the element or directory to this model.
+ * If the location is already managed by this model, do nothing.
+ * @param location
+ */
+void ElementsCollectionModel::addLocation(ElementsLocation location)
+{
+ QModelIndex index = indexFromLocation(location);
+ if (index.isValid())
+ return;
+
+ ElementCollectionItem *last_item = nullptr;
+ QString collection_name;
+
+ if (location.isProject()) {
+ QETProject *project = location.project();
+
+ if (project) {
+ XmlProjectElementCollectionItem *xpeci = m_project_hash.value(project);
+
+ last_item = xpeci->lastItemForPath(location.collectionPath(false), collection_name);
+ }
+ }
+ else if (location.isCustomCollection()) {
+ QList <ElementCollectionItem *> child_list;
+
+ for (int i=0 ; i<rowCount() ; i++)
+ child_list.append(static_cast<ElementCollectionItem *>(item(i)));
+
+ foreach(ElementCollectionItem *eci, child_list) {
+
+ if (eci->type() == FileElementCollectionItem::Type) {
+ FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci);
+
+ if (feci->isCustomCollection()) {
+ last_item = feci->lastItemForPath(location.collectionPath(false), collection_name);
+ if(last_item)
+ break;
+ }
+ }
+ }
+ }
+
+ if (last_item)
+ last_item->addChildAtPath(collection_name);
+}
+
+/**
* @brief ElementsCollectionModel::addProject
* Add project to this model
* @param project : project to add.
Modified: trunk/sources/ElementsCollection/elementscollectionmodel.h
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.h 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.h 2016-06-17 08:41:09 UTC (rev 4555)
@@ -42,6 +42,7 @@
void addCommonCollection(bool set_data = true);
void addCustomCollection(bool set_data = true);
+ void addLocation(ElementsLocation location);
void addProject(QETProject *project, bool set_data = true);
void removeProject(QETProject *project);
Modified: trunk/sources/ElementsCollection/elementscollectionwidget.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-06-17 08:41:09 UTC (rev 4555)
@@ -263,10 +263,7 @@
app->openElementLocations(QList<ElementsLocation>() << location);
foreach (QETElementEditor *element_editor, app->elementEditors())
- {
- if (element_editor->isEditing(location))
- connect(element_editor, &QETElementEditor::destroyed, [eci](){ eci->clearData(); eci->setUpData();});
- }
+ connect(element_editor, &QETElementEditor::saveToLocation, this, &ElementsCollectionWidget::locationWasSaved);
}
/**
@@ -482,6 +479,33 @@
}
/**
+ * @brief ElementsCollectionWidget::locationWasSaved
+ * This method is connected with the signal savedToLocation of Element editor (see ElementsCollectionWidget::editElement())
+ * Update or add the item represented by location to m_model
+ * @param location
+ */
+void ElementsCollectionWidget::locationWasSaved(ElementsLocation location)
+{
+ //Because this method update an item in the model, location must
+ //represente an existing element (in file system of project)
+ if (!location.exist())
+ return;
+
+ QModelIndex index = m_model->indexFromLocation(location);
+
+ if (index.isValid()) {
+ QStandardItem *item = m_model->itemFromIndex(index);
+ if (item) {
+ static_cast<ElementCollectionItem *>(item)->clearData();
+ static_cast<ElementCollectionItem *>(item)->setUpData();
+ }
+ }
+ else {
+ m_model->addLocation(location);
+ }
+}
+
+/**
* @brief ElementsCollectionWidget::search
* Search every item (directory or element) that match the text of m_search_field
* and display it, other item who does not match @text is hidden
Modified: trunk/sources/ElementsCollection/elementscollectionwidget.h
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.h 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.h 2016-06-17 08:41:09 UTC (rev 4555)
@@ -18,6 +18,8 @@
#ifndef ELEMENTSCOLLECTIONWIDGET_H
#define ELEMENTSCOLLECTIONWIDGET_H
+#include "elementslocation.h"
+
#include <QWidget>
#include <QModelIndex>
#include <QTimer>
@@ -75,7 +77,10 @@
private slots:
void reload();
+ private:
+ void locationWasSaved(ElementsLocation location);
+
private:
ElementsCollectionModel *m_model;
QLineEdit *m_search_field;
Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-06-17 08:41:09 UTC (rev 4555)
@@ -204,6 +204,15 @@
}
/**
+ * @brief FileElementCollectionItem::isCustomCollection
+ * @return True if this item represent the custom collection
+ */
+bool FileElementCollectionItem::isCustomCollection() const
+{
+ return fileSystemPath().startsWith(QETApp::customElementsDirN());
+}
+
+/**
* @brief FileElementCollectionItem::addChildAtPath
* Ask to this item item to add a child with collection name @collection_name
* @param collection_name
Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.h 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.h 2016-06-17 08:41:09 UTC (rev 4555)
@@ -44,6 +44,7 @@
virtual QString collectionPath() const;
virtual bool isCollectionRoot() const;
bool isCommonCollection() const;
+ bool isCustomCollection() const;
virtual void addChildAtPath(const QString &collection_name);
void setUpData();
Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/editor/qetelementeditor.cpp 2016-06-17 08:41:09 UTC (rev 4555)
@@ -1131,7 +1131,10 @@
//Else save to the known location
bool result_save = toLocation(location_);
- if (result_save) ce_scene -> undoStack().setClean();
+ if (result_save) {
+ ce_scene -> undoStack().setClean();
+ emit saveToLocation(location_);
+ }
return(result_save);
}
}
@@ -1147,20 +1150,19 @@
* @return true if save with success
*/
bool QETElementEditor::slot_saveAs() {
- // Check element befor writing
+ // Check element befor writing
if (checkElement()) {
- // demande une localisation a l'utilisateur
+ //Ask a location to user
ElementsLocation location = ElementDialog::getSaveElementLocation(this);
if (location.isNull()) return(false);
-
- // tente l'enregistrement
+
bool result_save = toLocation(location);
if (result_save) {
setLocation(location);
ce_scene -> undoStack().setClean();
+ emit saveToLocation(location);
}
-
- // retourne un booleen representatif de la reussite de l'enregistrement
+
return(result_save);
}
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
@@ -1173,9 +1175,9 @@
* @return true if save with success
*/
bool QETElementEditor::slot_saveAsFile() {
- // Check element befor writing
+ // Check element befor writing
if (checkElement()) {
- // demande un nom de fichier a l'utilisateur pour enregistrer l'element
+ //Ask a filename to user, for save the element
QString fn = QFileDialog::getSaveFileName(
this,
tr("Enregistrer sous", "dialog title"),
@@ -1185,19 +1187,22 @@
"filetypes allowed when saving an element file"
)
);
- // si aucun nom n'est entre, renvoie faux.
- if (fn.isEmpty()) return(false);
- // si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee
- if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt";
- // tente d'enregistrer le fichier
+
+ if (fn.isEmpty())
+ return(false);
+
+ //If the name doesn't end by .elmt, we add it
+ if (!fn.endsWith(".elmt", Qt::CaseInsensitive))
+ fn += ".elmt";
+
bool result_save = toFile(fn);
- // si l'enregistrement reussit, le nom du fichier est conserve
+ //If the save success, the filename is keep
if (result_save) {
setFileName(fn);
QETApp::elementsRecentFiles() -> fileWasOpened(fn);
ce_scene -> undoStack().setClean();
}
- // retourne un booleen representatif de la reussite de l'enregistrement
+
return(result_save);
}
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
Modified: trunk/sources/editor/qetelementeditor.h
===================================================================
--- trunk/sources/editor/qetelementeditor.h 2016-06-15 08:21:40 UTC (rev 4554)
+++ trunk/sources/editor/qetelementeditor.h 2016-06-17 08:41:09 UTC (rev 4555)
@@ -114,6 +114,9 @@
static QString getOpenElementFileName(QWidget * = 0, const QString & = QString());
void contextMenu(QPoint p);
+ signals:
+ void saveToLocation(ElementsLocation loc);
+
protected:
void closeEvent(QCloseEvent *);
virtual void firstActivation(QEvent *);