mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element panel widget : improve how an item is updated or added after editing an element with the Qet Element Editor.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4555 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -241,6 +241,54 @@ void ElementsCollectionModel::addCustomCollection(bool set_data)
|
|||||||
delete feci;
|
delete feci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
* @brief ElementsCollectionModel::addProject
|
||||||
* Add project to this model
|
* Add project to this model
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class ElementsCollectionModel : public QStandardItemModel
|
|||||||
|
|
||||||
void addCommonCollection(bool set_data = true);
|
void addCommonCollection(bool set_data = true);
|
||||||
void addCustomCollection(bool set_data = true);
|
void addCustomCollection(bool set_data = true);
|
||||||
|
void addLocation(ElementsLocation location);
|
||||||
|
|
||||||
void addProject(QETProject *project, bool set_data = true);
|
void addProject(QETProject *project, bool set_data = true);
|
||||||
void removeProject(QETProject *project);
|
void removeProject(QETProject *project);
|
||||||
|
|||||||
@@ -263,10 +263,7 @@ void ElementsCollectionWidget::editElement()
|
|||||||
app->openElementLocations(QList<ElementsLocation>() << location);
|
app->openElementLocations(QList<ElementsLocation>() << location);
|
||||||
|
|
||||||
foreach (QETElementEditor *element_editor, app->elementEditors())
|
foreach (QETElementEditor *element_editor, app->elementEditors())
|
||||||
{
|
connect(element_editor, &QETElementEditor::saveToLocation, this, &ElementsCollectionWidget::locationWasSaved);
|
||||||
if (element_editor->isEditing(location))
|
|
||||||
connect(element_editor, &QETElementEditor::destroyed, [eci](){ eci->clearData(); eci->setUpData();});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -481,6 +478,33 @@ void ElementsCollectionWidget::reload()
|
|||||||
m_progress_bar->hide();
|
m_progress_bar->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
* @brief ElementsCollectionWidget::search
|
||||||
* Search every item (directory or element) that match the text of m_search_field
|
* Search every item (directory or element) that match the text of m_search_field
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#ifndef ELEMENTSCOLLECTIONWIDGET_H
|
#ifndef ELEMENTSCOLLECTIONWIDGET_H
|
||||||
#define ELEMENTSCOLLECTIONWIDGET_H
|
#define ELEMENTSCOLLECTIONWIDGET_H
|
||||||
|
|
||||||
|
#include "elementslocation.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -75,6 +77,9 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
private slots:
|
private slots:
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void locationWasSaved(ElementsLocation location);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ElementsCollectionModel *m_model;
|
ElementsCollectionModel *m_model;
|
||||||
|
|||||||
@@ -203,6 +203,15 @@ bool FileElementCollectionItem::isCommonCollection() const
|
|||||||
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
|
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief FileElementCollectionItem::isCustomCollection
|
||||||
|
* @return True if this item represent the custom collection
|
||||||
|
*/
|
||||||
|
bool FileElementCollectionItem::isCustomCollection() const
|
||||||
|
{
|
||||||
|
return fileSystemPath().startsWith(QETApp::customElementsDirN());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief FileElementCollectionItem::addChildAtPath
|
* @brief FileElementCollectionItem::addChildAtPath
|
||||||
* Ask to this item item to add a child with collection name @collection_name
|
* Ask to this item item to add a child with collection name @collection_name
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class FileElementCollectionItem : public ElementCollectionItem
|
|||||||
virtual QString collectionPath() const;
|
virtual QString collectionPath() const;
|
||||||
virtual bool isCollectionRoot() const;
|
virtual bool isCollectionRoot() const;
|
||||||
bool isCommonCollection() const;
|
bool isCommonCollection() const;
|
||||||
|
bool isCustomCollection() const;
|
||||||
virtual void addChildAtPath(const QString &collection_name);
|
virtual void addChildAtPath(const QString &collection_name);
|
||||||
|
|
||||||
void setUpData();
|
void setUpData();
|
||||||
|
|||||||
@@ -1131,7 +1131,10 @@ bool QETElementEditor::slot_save()
|
|||||||
|
|
||||||
//Else save to the known location
|
//Else save to the known location
|
||||||
bool result_save = toLocation(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);
|
return(result_save);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1149,18 +1152,17 @@ bool QETElementEditor::slot_save()
|
|||||||
bool QETElementEditor::slot_saveAs() {
|
bool QETElementEditor::slot_saveAs() {
|
||||||
// Check element befor writing
|
// Check element befor writing
|
||||||
if (checkElement()) {
|
if (checkElement()) {
|
||||||
// demande une localisation a l'utilisateur
|
//Ask a location to user
|
||||||
ElementsLocation location = ElementDialog::getSaveElementLocation(this);
|
ElementsLocation location = ElementDialog::getSaveElementLocation(this);
|
||||||
if (location.isNull()) return(false);
|
if (location.isNull()) return(false);
|
||||||
|
|
||||||
// tente l'enregistrement
|
|
||||||
bool result_save = toLocation(location);
|
bool result_save = toLocation(location);
|
||||||
if (result_save) {
|
if (result_save) {
|
||||||
setLocation(location);
|
setLocation(location);
|
||||||
ce_scene -> undoStack().setClean();
|
ce_scene -> undoStack().setClean();
|
||||||
|
emit saveToLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// retourne un booleen representatif de la reussite de l'enregistrement
|
|
||||||
return(result_save);
|
return(result_save);
|
||||||
}
|
}
|
||||||
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
|
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
|
||||||
@@ -1175,7 +1177,7 @@ bool QETElementEditor::slot_saveAs() {
|
|||||||
bool QETElementEditor::slot_saveAsFile() {
|
bool QETElementEditor::slot_saveAsFile() {
|
||||||
// Check element befor writing
|
// Check element befor writing
|
||||||
if (checkElement()) {
|
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(
|
QString fn = QFileDialog::getSaveFileName(
|
||||||
this,
|
this,
|
||||||
tr("Enregistrer sous", "dialog title"),
|
tr("Enregistrer sous", "dialog title"),
|
||||||
@@ -1185,19 +1187,22 @@ bool QETElementEditor::slot_saveAsFile() {
|
|||||||
"filetypes allowed when saving an element file"
|
"filetypes allowed when saving an element file"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// si aucun nom n'est entre, renvoie faux.
|
|
||||||
if (fn.isEmpty()) return(false);
|
if (fn.isEmpty())
|
||||||
// si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee
|
return(false);
|
||||||
if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt";
|
|
||||||
// tente d'enregistrer le fichier
|
//If the name doesn't end by .elmt, we add it
|
||||||
|
if (!fn.endsWith(".elmt", Qt::CaseInsensitive))
|
||||||
|
fn += ".elmt";
|
||||||
|
|
||||||
bool result_save = toFile(fn);
|
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) {
|
if (result_save) {
|
||||||
setFileName(fn);
|
setFileName(fn);
|
||||||
QETApp::elementsRecentFiles() -> fileWasOpened(fn);
|
QETApp::elementsRecentFiles() -> fileWasOpened(fn);
|
||||||
ce_scene -> undoStack().setClean();
|
ce_scene -> undoStack().setClean();
|
||||||
}
|
}
|
||||||
// retourne un booleen representatif de la reussite de l'enregistrement
|
|
||||||
return(result_save);
|
return(result_save);
|
||||||
}
|
}
|
||||||
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
|
QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement à échoué,\nles conditions requises ne sont pas valides"));
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ class QETElementEditor : public QETMainWindow {
|
|||||||
static QString getOpenElementFileName(QWidget * = 0, const QString & = QString());
|
static QString getOpenElementFileName(QWidget * = 0, const QString & = QString());
|
||||||
void contextMenu(QPoint p);
|
void contextMenu(QPoint p);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void saveToLocation(ElementsLocation loc);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
virtual void firstActivation(QEvent *);
|
virtual void firstActivation(QEvent *);
|
||||||
|
|||||||
Reference in New Issue
Block a user