QETProject have is own database + add widget to edit nomenclature model

QETProject have is own ProjectDataBase, then when the database is
updated, everything that need the database is also updated trough the
signal emitted by the database.
Begin a widget to edit the NomenclatureModel
This commit is contained in:
Claveau Joshua
2020-03-29 18:17:27 +02:00
parent 66abfbe180
commit 8819146a01
16 changed files with 764 additions and 423 deletions

View File

@@ -75,6 +75,20 @@ QVector<QStringList> 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;
}

View File

@@ -23,9 +23,8 @@
#include <QSqlQuery>
#include <QPointer>
#include "qetproject.h"
class Element;
class QETProject;
/**
* @brief The projectDataBase class
@@ -43,6 +42,10 @@ class projectDataBase : public QObject
virtual ~projectDataBase() override;
QVector<QStringList> elementsInfoFromQuery(const QString &query);
void updateDB();
signals:
void dataBaseUpdated();
private:
bool createDataBase();

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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<NomenclatureModel *>(model))
{
if (editor &&
editor->metaObject()->className() == NomenclatureModelPropertiesWidget::staticMetaObject.className())
{
static_cast<NomenclatureModelPropertiesWidget *>(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<QGraphicsItem *> 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<Element*>(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<ElementPropertiesWidget*>(editor)->setElement(elmt);
return editor;
}
return new ElementPropertiesWidget(elmt, parent);
}
case IndependentTextItem::Type: //1005
{
QList<IndependentTextItem *> text_list;
for (QGraphicsItem *qgi : items) {
text_list.append(static_cast<IndependentTextItem*>(qgi));
}
if (class_name == IndiTextPropertiesWidget::staticMetaObject.className())
{
static_cast<IndiTextPropertiesWidget*>(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<DiagramImageItem*>(item), parent);
}
case QetShapeItem::Type: //1008
{
QList<QetShapeItem *> shapes_list;
for (QGraphicsItem *qgi : items) {
shapes_list.append(static_cast<QetShapeItem*>(qgi));
}
if (class_name == ShapeGraphicsItemPropertiesWidget::staticMetaObject.className())
{
static_cast<ShapeGraphicsItemPropertiesWidget*>(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<DynamicElementTextItem *>(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<ElementPropertiesWidget*>(editor)->setDynamicText(deti);
return editor;
}
return new ElementPropertiesWidget(deti, parent);
}
case QGraphicsItemGroup::Type:
{
if (count_ > 1) {
return nullptr;
}
if(ElementTextItemGroup *group = dynamic_cast<ElementTextItemGroup *>(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<ElementPropertiesWidget *>(editor)->setTextsGroup(group);
return editor;
}
return new ElementPropertiesWidget(group, parent);
}
break;
}
case QetGraphicsTableItem::Type:
{
if (count_ > 1) {
return nullptr;
}
auto table = static_cast<QetGraphicsTableItem*>(item);
if (class_name == GraphicsTablePropertiesEditor::staticMetaObject.className())
{
static_cast<GraphicsTablePropertiesEditor*>(editor)->setTable(table);
return editor;
}
return new GraphicsTablePropertiesEditor(table, parent);
}
default:
return nullptr;
}
return nullptr;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef PROPERTIESEDITORFACTORY_H
#define PROPERTIESEDITORFACTORY_H
#include <QList>
class QAbstractItemModel;
class QGraphicsItem;
class PropertiesEditorWidget;
class QWidget;
namespace PropertiesEditorFactory
{
PropertiesEditorWidget *propertiesEditor(QAbstractItemModel *model, PropertiesEditorWidget *editor = nullptr, QWidget *parent=nullptr);
PropertiesEditorWidget *propertiesEditor(QList<QGraphicsItem *> items, PropertiesEditorWidget *editor = nullptr, QWidget *parent = nullptr);
}
#endif // PROPERTIESEDITORFACTORY_H

View File

@@ -17,6 +17,7 @@
*/
#include "nomenclaturemodel.h"
#include "qetapp.h"
#include "qetproject.h"
#include <QModelIndex>
#include <QFont>
@@ -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<int>(Qt::DisplayRole));
}

View File

@@ -20,8 +20,6 @@
#include <QAbstractTableModel>
#include <QPointer>
#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<QETProject> m_project;
QString m_query;
projectDataBase m_database;
QVector<QStringList> m_record;
QHash<int, QHash<int, QVariant>> m_header_data;
QHash<int, QVariant> m_index_0_0_data;

View File

@@ -391,6 +391,7 @@ void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelI
setUpColumnAndRowMinimumSize();
adjustSize();
setSize(size_);
qDebug() << "data changed";
}
/**

View File

@@ -22,6 +22,7 @@
#include "diagram.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "itemmodelcommand.h"
#include "propertieseditorfactory.h"
#include <QAbstractItemModel>
#include <QFontDialog>
@@ -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();
}

View File

@@ -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)

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>484</height>
<width>353</width>
<height>534</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,237 +15,271 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position</string>
<widget class="QTabWidget" name="m_tab">
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="m_display_tab">
<attribute name="title">
<string>Affichage</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>En tête</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QSpinBox" name="m_header_left_margin"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_header_top_margin"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Aligement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_header_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Tableau</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="2">
<widget class="QSpinBox" name="m_table_right_margin"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="m_table_top_margin"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_table_bottom_margin"/>
</item>
<item row="1" column="0">
<widget class="QSpinBox" name="m_table_left_margin"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Alignement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_table_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_content_tab">
<attribute name="title">
<string>Contenu</string>
</attribute>
<layout class="QVBoxLayout" name="m_content_layout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>534</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>En tête</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QSpinBox" name="m_header_left_margin"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_header_top_margin"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Aligement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_header_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Tableau</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="2">
<widget class="QSpinBox" name="m_table_right_margin"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="m_table_top_margin"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_table_bottom_margin"/>
</item>
<item row="1" column="0">
<widget class="QSpinBox" name="m_table_left_margin"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Alignement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_table_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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");
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NomenclatureModelPropertiesWidget</class>
<widget class="QWidget" name="NomenclatureModelPropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>106</width>
<height>78</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="m_edit_query_pb">
<property name="text">
<string>Requette</string>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/edit-rename.png</normaloff>:/ico/16x16/edit-rename.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_refresh_pb">
<property name="text">
<string>Recharger</string>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/view-refresh.png</normaloff>:/ico/16x16/view-refresh.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="../../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -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

View File

@@ -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<Diagram *> 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 *)

View File

@@ -16,19 +16,9 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#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<QGraphicsItem *> 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<ElementPropertiesWidget*>(editors().first())->setElement(static_cast<Element*>(item));
return;
}
clear();
m_edited_qgi_type = type_;
addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
break;
}
case IndependentTextItem::Type: //1005
{
QList<IndependentTextItem *> text_list;
for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
text_list.append(static_cast<IndependentTextItem*>(qgi));
}
if (m_edited_qgi_type == type_)
{
static_cast<IndiTextPropertiesWidget*>(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<DiagramImageItem*>(item), this));
break;
}
case QetShapeItem::Type: //1008
{
QList<QetShapeItem *> shapes_list;
for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
shapes_list.append(static_cast<QetShapeItem*>(qgi));
}
if (m_edited_qgi_type == type_)
{
static_cast<ShapeGraphicsItemPropertiesWidget*>(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<DynamicElementTextItem *>(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<ElementPropertiesWidget*>(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<ElementTextItemGroup *>(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<ElementPropertiesWidget *>(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<QetGraphicsTableItem*>(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);
}