diff --git a/sources/dataBase/projectdatabase.cpp b/sources/dataBase/projectdatabase.cpp index 771a4dc29..ed0e218e8 100644 --- a/sources/dataBase/projectdatabase.cpp +++ b/sources/dataBase/projectdatabase.cpp @@ -75,6 +75,20 @@ QVector projectDataBase::elementsInfoFromQuery(const QString &query return result_; } +/** + * @brief projectDataBase::updateDB + * Up to date the content of the data base. + * Except at the creation of this class, + * call this method each time you want to query the data base + * to be sure that the content reflect the current state of the project. + * Emit the singal dataBaseUpdated + */ +void projectDataBase::updateDB() +{ + populateElementsTable(); + emit dataBaseUpdated(); +} + /** * @brief projectDataBase::createDataBase * Create the data base @@ -114,8 +128,7 @@ bool projectDataBase::createDataBase() query_.exec(); } - populateElementsTable(); - + updateDB(); return true; } diff --git a/sources/dataBase/projectdatabase.h b/sources/dataBase/projectdatabase.h index 98ba65f18..0b89a202a 100644 --- a/sources/dataBase/projectdatabase.h +++ b/sources/dataBase/projectdatabase.h @@ -23,9 +23,8 @@ #include #include -#include "qetproject.h" - class Element; +class QETProject; /** * @brief The projectDataBase class @@ -43,6 +42,10 @@ class projectDataBase : public QObject virtual ~projectDataBase() override; QVector elementsInfoFromQuery(const QString &query); + void updateDB(); + + signals: + void dataBaseUpdated(); private: bool createDataBase(); diff --git a/sources/factory/propertieseditorfactory.cpp b/sources/factory/propertieseditorfactory.cpp new file mode 100644 index 000000000..c9e3801cf --- /dev/null +++ b/sources/factory/propertieseditorfactory.cpp @@ -0,0 +1,207 @@ +/* + Copyright 2006-2020 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 . +*/ +#include "propertieseditorfactory.h" +#include "QGraphicsItem" +#include "element.h" +#include "PropertiesEditor/propertieseditorwidget.h" +#include "elementpropertieswidget.h" +#include "element.h" +#include "independenttextitem.h" +#include "inditextpropertieswidget.h" +#include "diagramimageitem.h" +#include "imagepropertieswidget.h" +#include "qetshapeitem.h" +#include "shapegraphicsitempropertieswidget.h" +#include "dynamicelementtextitem.h" +#include "dynamicelementtextitemeditor.h" +#include "elementtextitemgroup.h" +#include "qetgraphicstableitem.h" +#include "graphicstablepropertieseditor.h" +#include "nomenclaturemodel.h" +#include "nomenclaturemodelpropertieswidget.h" + +/** + * @brief PropertiesEditorFactory::propertiesEditor + * @param model : the model to be edited + * @param editor : if the properties editor to be created is the same class as @editor, the this function set @item as edited item of @editor and return editor + * @param parent : parent widget of the returned editor + * @return an editor or nullptr + */ +PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor(QAbstractItemModel *model, PropertiesEditorWidget *editor, QWidget *parent) +{ + Q_UNUSED(model) + Q_UNUSED(editor) + Q_UNUSED(parent) + + if (auto m = static_cast(model)) + { + if (editor && + editor->metaObject()->className() == NomenclatureModelPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setModel(m); + return editor; + } + return new NomenclatureModelPropertiesWidget(m, parent); + } + return nullptr; +} + +/** +* @brief propertiesEditor +* @param items : The items to be edited +* @param editor : If the properties editor to be created is the same class as @editor, then this function set @item as edited item of @editor and return editor +* @param parent : parent widget of the returned editor +* @return : an editor or nullptr; +*/ +PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor(QList items, PropertiesEditorWidget *editor, QWidget *parent) +{ + int count_ = items.size(); + + //The editor widget can only edit one item + //or several items of the same type + if (count_ != 1) + { + if (count_ == 0) { + return nullptr; + } + + int type_ = items.first()->type(); + for (QGraphicsItem *qgi : items) { + if (qgi->type() != type_) { + return nullptr; + } + } + } + + QGraphicsItem *item = items.first(); + const int type_ = item->type(); + QString class_name; + if (editor) { + class_name = editor->metaObject()->className(); + } + + switch (type_) + { + case Element::Type: //1000 + { + if (count_ > 1) { + return nullptr; + } + auto elmt = static_cast(item); + //auto created_editor = new ElementPropertiesWidget(elmt, parent); + + //We already edit an element, just update the editor with a new element + if (class_name == ElementPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setElement(elmt); + return editor; + } + return new ElementPropertiesWidget(elmt, parent); + } + case IndependentTextItem::Type: //1005 + { + QList text_list; + for (QGraphicsItem *qgi : items) { + text_list.append(static_cast(qgi)); + } + + if (class_name == IndiTextPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setText(text_list); + return editor; + } + + return new IndiTextPropertiesWidget(text_list, parent); + } + case DiagramImageItem::Type: //1007 + { + if (count_ > 1) { + return nullptr; + } + return new ImagePropertiesWidget(static_cast(item), parent); + } + case QetShapeItem::Type: //1008 + { + QList shapes_list; + for (QGraphicsItem *qgi : items) { + shapes_list.append(static_cast(qgi)); + } + + if (class_name == ShapeGraphicsItemPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setItems(shapes_list); + return editor; + } + + return new ShapeGraphicsItemPropertiesWidget(shapes_list, parent); + } + case DynamicElementTextItem::Type: //1010 + { + if (count_ > 1) { + return nullptr; + } + + DynamicElementTextItem *deti = static_cast(item); + //For dynamic element text, we open the element editor to edit it + //If we already edit an element, just update the editor with a new element + if (class_name == ElementPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setDynamicText(deti); + return editor; + } + return new ElementPropertiesWidget(deti, parent); + } + case QGraphicsItemGroup::Type: + { + if (count_ > 1) { + return nullptr; + } + + if(ElementTextItemGroup *group = dynamic_cast(item)) + { + //For element text item group, we open the element editor to edit it + //If we already edit an element, just update the editor with a new element + if(class_name == ElementPropertiesWidget::staticMetaObject.className()) + { + static_cast(editor)->setTextsGroup(group); + return editor; + } + return new ElementPropertiesWidget(group, parent); + } + break; + } + case QetGraphicsTableItem::Type: + { + if (count_ > 1) { + return nullptr; + } + + auto table = static_cast(item); + if (class_name == GraphicsTablePropertiesEditor::staticMetaObject.className()) + { + static_cast(editor)->setTable(table); + return editor; + } + return new GraphicsTablePropertiesEditor(table, parent); + } + default: + return nullptr; + } + + return nullptr; +} diff --git a/sources/factory/propertieseditorfactory.h b/sources/factory/propertieseditorfactory.h new file mode 100644 index 000000000..986af0c55 --- /dev/null +++ b/sources/factory/propertieseditorfactory.h @@ -0,0 +1,34 @@ +/* + Copyright 2006-2020 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 . +*/ +#ifndef PROPERTIESEDITORFACTORY_H +#define PROPERTIESEDITORFACTORY_H + +#include + +class QAbstractItemModel; +class QGraphicsItem; +class PropertiesEditorWidget; +class QWidget; + +namespace PropertiesEditorFactory +{ + PropertiesEditorWidget *propertiesEditor(QAbstractItemModel *model, PropertiesEditorWidget *editor = nullptr, QWidget *parent=nullptr); + PropertiesEditorWidget *propertiesEditor(QList items, PropertiesEditorWidget *editor = nullptr, QWidget *parent = nullptr); +} + +#endif // PROPERTIESEDITORFACTORY_H diff --git a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp index 56810089a..b2a22927b 100644 --- a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp +++ b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp @@ -17,6 +17,7 @@ */ #include "nomenclaturemodel.h" #include "qetapp.h" +#include "qetproject.h" #include #include @@ -28,9 +29,10 @@ */ NomenclatureModel::NomenclatureModel(QETProject *project, QObject *parent) : QAbstractTableModel(parent), - m_project(project), - m_database(project) -{} + m_project(project) +{ + connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated); +} /** * @brief NomenclatureModel::rowCount @@ -159,6 +161,22 @@ QVariant NomenclatureModel::data(const QModelIndex &index, int role) const void NomenclatureModel::query(const QString &query) { m_query = query; - m_record.clear(); - m_record = m_database.elementsInfoFromQuery(query); + + if (m_project) { + m_project->dataBase()->updateDB(); + } +} + +/** + * @brief NomenclatureModel::dataBaseUpdated + * slot called when the project database is updated + */ +void NomenclatureModel::dataBaseUpdated() +{ + m_record.clear(); + m_record = m_project->dataBase()->elementsInfoFromQuery(m_query); + + auto row = m_record.size(); + auto col = row ? m_record.first().count() : 1; + emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); } diff --git a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h index 500958135..bdc45c196 100644 --- a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h +++ b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h @@ -20,8 +20,6 @@ #include #include -#include "projectdatabase.h" - class QETProject; @@ -45,10 +43,12 @@ class NomenclatureModel : public QAbstractTableModel QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void query(const QString &query); + private: + void dataBaseUpdated(); + private: QPointer m_project; QString m_query; - projectDataBase m_database; QVector m_record; QHash> m_header_data; QHash m_index_0_0_data; diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index 4d2be043e..899a33247 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -391,6 +391,7 @@ void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelI setUpColumnAndRowMinimumSize(); adjustSize(); setSize(size_); + qDebug() << "data changed"; } /** diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp index 06bf4db75..b1b3bbcf0 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp @@ -22,6 +22,7 @@ #include "diagram.h" #include "QPropertyUndoCommand/qpropertyundocommand.h" #include "itemmodelcommand.h" +#include "propertieseditorfactory.h" #include #include @@ -69,6 +70,11 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table) for (auto c : m_connect_list) { disconnect(c); } + if (m_current_model_editor) + { + ui->m_content_layout->removeWidget(m_current_model_editor); + m_current_model_editor->deleteLater(); + } } m_table_item = table; @@ -76,6 +82,12 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table) m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::xChanged, this, &GraphicsTablePropertiesEditor::updateUi); m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::yChanged, this, &GraphicsTablePropertiesEditor::updateUi); + + if (auto editor = PropertiesEditorFactory::propertiesEditor(table->model(), this)) + { + ui->m_content_layout->insertWidget(0, editor); + m_current_model_editor = editor; + } updateUi(); } diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h index f3b770eab..b69f6c4b6 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h @@ -62,6 +62,7 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget m_edit_connection; QButtonGroup *m_header_button_group = nullptr, *m_table_button_group = nullptr; + QWidget *m_current_model_editor = nullptr; }; Q_DECLARE_METATYPE(QMargins) diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui index e7f53285d..e13308c32 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui @@ -6,8 +6,8 @@ 0 0 - 331 - 484 + 353 + 534 @@ -15,237 +15,271 @@ - - - Position + + + 0 - - - - - X : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 10000 - - - - - - - Y : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 10000 - - - - + + + Affichage + + + + + + Position + + + + + + X : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 10000 + + + + + + + Y : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 10000 + + + + + + + + + + En tête + + + + + + + + + + + + + + + + + Marge + + + Qt::AlignCenter + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Aligement : + + + + + + + Gauche + + + + + + + Centré + + + + + + + Droite + + + + + + + + + + Police + + + + + + + + + + Tableau + + + + + + + + + + + + + + + + + + + + Marge + + + Qt::AlignCenter + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Alignement : + + + + + + + Gauche + + + + + + + Centré + + + + + + + Droite + + + + + + + + + + Police + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Contenu + + + + + + Qt::Vertical + + + + 20 + 534 + + + + + + - - - - En tête - - - - - - - - Marge - - - Qt::AlignCenter - - - - - - - - - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Aligement : - - - - - - - Gauche - - - - - - - Centré - - - - - - - Droite - - - - - - - - - - Police - - - - - - - - - - Tableau - - - - - - - - - - - - - - - - - - - - Marge - - - Qt::AlignCenter - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Alignement : - - - - - - - Gauche - - - - - - - Centré - - - - - - - Droite - - - - - - - - - - Police - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp new file mode 100644 index 000000000..811d8975b --- /dev/null +++ b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp @@ -0,0 +1,59 @@ +/* + Copyright 2006-2020 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 . +*/ +#include "nomenclaturemodelpropertieswidget.h" +#include "ui_nomenclaturemodelpropertieswidget.h" +#include "nomenclaturemodel.h" + +/** + * @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget + * @param model + * @param parent + */ +NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget(NomenclatureModel *model, QWidget *parent) : + PropertiesEditorWidget(parent), + ui(new Ui::NomenclatureModelPropertiesWidget) +{ + ui->setupUi(this); + if (model) { + setModel(model); + } +} + +/** + * @brief NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget + */ +NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget() { + delete ui; +} + +/** + * @brief NomenclatureModelPropertiesWidget::setModel + * @param model + */ +void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) { + m_model = model; +} + +void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked() +{} + +void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() { + if (m_model) { + m_model->query("SELECT plant, location, label, comment, description FROM element_info ORDER BY plant, location, label, comment, description"); + } +} diff --git a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.h b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.h new file mode 100644 index 000000000..af4be3e1f --- /dev/null +++ b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.h @@ -0,0 +1,52 @@ +/* + Copyright 2006-2020 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 . +*/ +#ifndef NOMENCLATUREMODELPROPERTIESWIDGET_H +#define NOMENCLATUREMODELPROPERTIESWIDGET_H + +#include "PropertiesEditor/propertieseditorwidget.h" + +class NomenclatureModel; + +namespace Ui { +class NomenclatureModelPropertiesWidget; +} + +/** + * @brief The NomenclatureModelPropertiesWidget class + * This class is an editor for a NomenclatureModel + */ +class NomenclatureModelPropertiesWidget : public PropertiesEditorWidget +{ + Q_OBJECT + + public: + explicit NomenclatureModelPropertiesWidget(NomenclatureModel *model = nullptr, QWidget *parent = nullptr); + ~NomenclatureModelPropertiesWidget(); + + void setModel(NomenclatureModel *model); + + private slots: + void on_m_edit_query_pb_clicked(); + void on_m_refresh_pb_clicked(); + + private: + Ui::NomenclatureModelPropertiesWidget *ui; + NomenclatureModel *m_model = nullptr; +}; + +#endif // NOMENCLATUREMODELPROPERTIESWIDGET_H diff --git a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.ui b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.ui new file mode 100644 index 000000000..dc820adec --- /dev/null +++ b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.ui @@ -0,0 +1,58 @@ + + + NomenclatureModelPropertiesWidget + + + + 0 + 0 + 106 + 78 + + + + Form + + + + + + Requette + + + + :/ico/16x16/edit-rename.png:/ico/16x16/edit-rename.png + + + + + + + Recharger + + + + :/ico/16x16/view-refresh.png:/ico/16x16/view-refresh.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 506f5803e..e60eb49a6 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -46,7 +46,8 @@ static int BACKUP_INTERVAL = 120000; //interval in ms of backup = 2min */ QETProject::QETProject(QObject *parent) : QObject (parent), - m_titleblocks_collection(this) + m_titleblocks_collection(this), + m_data_base(this, this) { m_elements_collection = new XmlElementCollection(this); init(); @@ -60,7 +61,8 @@ QETProject::QETProject(QObject *parent) : */ QETProject::QETProject(const QString &path, QObject *parent) : QObject (parent), - m_titleblocks_collection(this) + m_titleblocks_collection(this), + m_data_base(this, this) { QFile file(path); m_state = openFile(&file); @@ -78,7 +80,8 @@ QETProject::QETProject(const QString &path, QObject *parent) : */ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) : QObject (parent), - m_titleblocks_collection(this) + m_titleblocks_collection(this), + m_data_base(this, this) { m_state = openFile(backup); //Failed to open from the backup, try to open the crashed @@ -112,6 +115,14 @@ QETProject::~QETProject() { qDeleteAll(m_diagrams_list); } +/** + * @brief QETProject::dataBase + * @return The data base of this project + */ +projectDataBase *QETProject::dataBase() { + return &m_data_base; +} + /** * @brief QETProject::uuid * @return the uuid of this project diff --git a/sources/qetproject.h b/sources/qetproject.h index 1743dd7e8..9f41a3bde 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -25,6 +25,7 @@ #include "titleblockproperties.h" #include "templatescollection.h" #include "properties/xrefproperties.h" +#include "projectdatabase.h" class Diagram; class ElementsLocation; @@ -71,6 +72,7 @@ class QETProject : public QObject // methods public: + projectDataBase *dataBase(); QUuid uuid() const; ProjectState state() const; QList diagrams() const; @@ -268,6 +270,7 @@ class QETProject : public QObject m_autosave_timer; KAutoSaveFile *m_backup_file = nullptr; QUuid m_uuid = QUuid::createUuid(); + projectDataBase m_data_base; }; Q_DECLARE_METATYPE(QETProject *) diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index cca4cab86..bc3ba80f3 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -16,19 +16,9 @@ along with QElectroTech. If not, see . */ #include "diagrampropertieseditordockwidget.h" -#include "elementpropertieswidget.h" #include "diagram.h" -#include "element.h" -#include "diagramimageitem.h" -#include "imagepropertieswidget.h" -#include "qetshapeitem.h" -#include "shapegraphicsitempropertieswidget.h" -#include "dynamicelementtextitem.h" -#include "elementtextitemgroup.h" -#include "independenttextitem.h" -#include "inditextpropertieswidget.h" -#include "qetgraphicstableitem.h" -#include "graphicstablepropertieseditor.h" +#include "PropertiesEditor/propertieseditorwidget.h" +#include "propertieseditorfactory.h" /** * @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget @@ -81,176 +71,21 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) */ void DiagramPropertiesEditorDockWidget::selectionChanged() { - if (!m_diagram) return; - - int count_ = m_diagram->selectedItems().size(); - - //The editor widget can only edit one item - //or several items of the same type - if (count_ != 1) - { - if (count_ == 0) { - clear(); - m_edited_qgi_type = -1; - return; - } - - const QList list_ = m_diagram->selectedItems(); - int type_ = list_.first()->type(); - for (QGraphicsItem *qgi : list_) - { - if (qgi->type() != type_) - { - clear(); - m_edited_qgi_type = -1; - return; - } - } + if (!m_diagram) { + return; } - QGraphicsItem *item = m_diagram->selectedItems().first(); - const int type_ = item->type(); - - switch (type_) - { - case Element::Type: //1000 - { - if (count_ > 1) - { - clear(); - m_edited_qgi_type = -1; - return; - } - //We already edit an element, just update the editor with a new element - if (m_edited_qgi_type == type_) - { - static_cast(editors().first())->setElement(static_cast(item)); - return; - } - - clear(); - m_edited_qgi_type = type_; - addEditor(new ElementPropertiesWidget(static_cast(item), this)); - break; - } - case IndependentTextItem::Type: //1005 - { - QList text_list; - for (QGraphicsItem *qgi : m_diagram->selectedItems()) { - text_list.append(static_cast(qgi)); - } - - if (m_edited_qgi_type == type_) - { - static_cast(editors().first())->setText(text_list); - return; - } - - clear(); - m_edited_qgi_type = type_; - addEditor(new IndiTextPropertiesWidget(text_list, this)); - break; - } - case DiagramImageItem::Type: //1007 - { - if (count_ > 1) - { - clear(); - m_edited_qgi_type = -1; - return; - } - - clear(); - m_edited_qgi_type = type_; - addEditor(new ImagePropertiesWidget(static_cast(item), this)); - break; - } - case QetShapeItem::Type: //1008 - { - QList shapes_list; - for (QGraphicsItem *qgi : m_diagram->selectedItems()) { - shapes_list.append(static_cast(qgi)); - } - - if (m_edited_qgi_type == type_) - { - static_cast(editors().first())->setItems(shapes_list); - return; - } - - clear(); - m_edited_qgi_type = type_; - addEditor(new ShapeGraphicsItemPropertiesWidget(shapes_list, this)); - break; - } - case DynamicElementTextItem::Type: //1010 - { - if (count_ > 1) - { - clear(); - m_edited_qgi_type = -1; - return; - } - - DynamicElementTextItem *deti = static_cast(item); - - //For dynamic element text, we open the element editor to edit it - //If we already edit an element, just update the editor with a new element - if (m_edited_qgi_type == Element::Type) - { - static_cast(editors().first())->setDynamicText(deti); - return; - } - - clear(); - m_edited_qgi_type = Element::Type; - addEditor(new ElementPropertiesWidget(deti, this)); - break; - } - case QGraphicsItemGroup::Type: - { - if (count_ > 1) - { - clear(); - m_edited_qgi_type = -1; - return; - } - - if(ElementTextItemGroup *group = dynamic_cast(item)) - { - //For element text item group, we open the element editor to edit it - //If we already edit an element, just update the editor with a new element - if(m_edited_qgi_type == Element::Type) - { - static_cast(editors().first())->setTextsGroup(group); - return; - } - - clear(); - m_edited_qgi_type = Element::Type; - addEditor(new ElementPropertiesWidget(group, this)); - } - break; - } - case QetGraphicsTableItem::Type: - { - if (count_ > 1) - { - clear(); - m_edited_qgi_type = -1; - return; - } - - clear(); - m_edited_qgi_type = type_; - addEditor(new GraphicsTablePropertiesEditor(static_cast(item), this)); - break; - } - default: - m_edited_qgi_type = -1; - clear(); + auto editor_ = PropertiesEditorFactory::propertiesEditor(m_diagram->selectedItems(), editors().count()? editors().first() : nullptr, this); + if (!editor_) { + clear(); + return; + } + if (editors().count() && + editors().first() != editor_) { + clear(); } + addEditor(editor_); for (PropertiesEditorWidget *pew : editors()) { pew->setLiveEdit(true); }