mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Merge remote-tracking branch 'origin/QetGraphicsTableItem'
This commit is contained in:
@@ -102,6 +102,8 @@ INCLUDEPATH += sources \
|
||||
sources/NameList/ui \
|
||||
sources/utils \
|
||||
sources/pugixml \
|
||||
sources/dataBase \
|
||||
sources/dataBase/ui
|
||||
|
||||
|
||||
# Fichiers sources
|
||||
@@ -130,7 +132,9 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
|
||||
$$files(sources/NameList/*.h) \
|
||||
$$files(sources/NameList/ui/*.h) \
|
||||
$$files(sources/utils/*.h) \
|
||||
$$files(sources/pugixml/*.hpp)
|
||||
$$files(sources/pugixml/*.hpp) \
|
||||
$$files(sources/dataBase/*.h) \
|
||||
$$files(sources/dataBase/ui/*.h)
|
||||
|
||||
SOURCES += $$files(sources/*.cpp) \
|
||||
$$files(sources/editor/*.cpp) \
|
||||
@@ -158,7 +162,9 @@ SOURCES += $$files(sources/*.cpp) \
|
||||
$$files(sources/NameList/*.cpp) \
|
||||
$$files(sources/NameList/ui/*.cpp) \
|
||||
$$files(sources/utils/*.cpp) \
|
||||
$$files(sources/pugixml/*.cpp)
|
||||
$$files(sources/pugixml/*.cpp) \
|
||||
$$files(sources/dataBase/*.cpp) \
|
||||
$$files(sources/dataBase/ui/*.cpp)
|
||||
|
||||
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
|
||||
RESOURCES += qelectrotech.qrc
|
||||
@@ -181,7 +187,8 @@ FORMS += $$files(sources/richtext/*.ui) \
|
||||
$$files(sources/ui/configpage/*.ui) \
|
||||
$$files(sources/SearchAndReplace/ui/*.ui) \
|
||||
$$files(sources/NameList/ui/*.ui) \
|
||||
$$files(sources/qetgraphicsitem/ViewItem/ui/*.ui)
|
||||
$$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) \
|
||||
$$files(sources/dataBase/ui/*.ui)
|
||||
|
||||
UI_SOURCES_DIR = sources/ui/
|
||||
UI_HEADERS_DIR = sources/ui/
|
||||
|
||||
@@ -40,12 +40,12 @@ BorderTitleBlock::BorderTitleBlock(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
// at first, the internal titleblock template renderer uses the default titleblock template
|
||||
titleblock_template_renderer_ = new TitleBlockTemplateRenderer(this);
|
||||
titleblock_template_renderer_ -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
|
||||
m_titleblock_template_renderer = new TitleBlockTemplateRenderer(this);
|
||||
m_titleblock_template_renderer -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
|
||||
|
||||
// disable the QPicture-based cache from Qt 4.8 to avoid rendering errors and crashes
|
||||
if (!QRegExp("4\\.[0-7]\\.").exactMatch(qVersion())) {
|
||||
titleblock_template_renderer_ -> setUseCache(false);
|
||||
m_titleblock_template_renderer -> setUseCache(false);
|
||||
}
|
||||
|
||||
// dimensions par defaut du schema
|
||||
@@ -73,9 +73,13 @@ BorderTitleBlock::~BorderTitleBlock() {
|
||||
QRectF BorderTitleBlock::titleBlockRect() const
|
||||
{
|
||||
if (m_edge == Qt::BottomEdge)
|
||||
return QRectF(diagram_rect_.bottomLeft(), QSize(diagram_rect_.width(), titleblock_template_renderer_ -> height()));
|
||||
return QRectF(diagram_rect_.bottomLeft(), QSize(diagram_rect_.width(), m_titleblock_template_renderer -> height()));
|
||||
else
|
||||
return QRectF(diagram_rect_.topRight(), QSize(titleblock_template_renderer_ -> height(), diagram_rect_.height()));
|
||||
return QRectF(diagram_rect_.topRight(), QSize(m_titleblock_template_renderer -> height(), diagram_rect_.height()));
|
||||
}
|
||||
|
||||
DiagramContext BorderTitleBlock::titleblockInformation() const {
|
||||
return m_titleblock_template_renderer->context();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +97,7 @@ QRectF BorderTitleBlock::titleBlockRectForQPainter() const
|
||||
if (m_edge == Qt::BottomEdge) //Rect at bottom have same position and dimension of displayed rect
|
||||
return titleBlockRect();
|
||||
else
|
||||
return QRectF (diagram_rect_.bottomRight(), QSize(diagram_rect_.height(), titleblock_template_renderer_ -> height()));
|
||||
return QRectF (diagram_rect_.bottomRight(), QSize(diagram_rect_.height(), m_titleblock_template_renderer -> height()));
|
||||
|
||||
}
|
||||
|
||||
@@ -317,7 +321,7 @@ void BorderTitleBlock::importBorder(const BorderProperties &bp) {
|
||||
@see TitleBlockTemplateRenderer::titleBlockTemplate()
|
||||
*/
|
||||
const TitleBlockTemplate *BorderTitleBlock::titleBlockTemplate() {
|
||||
return(titleblock_template_renderer_ -> titleBlockTemplate());
|
||||
return(m_titleblock_template_renderer -> titleBlockTemplate());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,14 +329,14 @@ const TitleBlockTemplate *BorderTitleBlock::titleBlockTemplate() {
|
||||
@see TitleBlockTemplateRenderer::setTitleBlockTemplate()
|
||||
*/
|
||||
void BorderTitleBlock::setTitleBlockTemplate(const TitleBlockTemplate *titleblock_template) {
|
||||
titleblock_template_renderer_ -> setTitleBlockTemplate(titleblock_template);
|
||||
m_titleblock_template_renderer -> setTitleBlockTemplate(titleblock_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@return The name of the template used to render the titleblock.
|
||||
*/
|
||||
QString BorderTitleBlock::titleBlockTemplateName() const {
|
||||
QString tbt_name = titleblock_template_renderer_ -> titleBlockTemplate() -> name();
|
||||
QString tbt_name = m_titleblock_template_renderer -> titleBlockTemplate() -> name();
|
||||
return((tbt_name == "default") ? "" : tbt_name);
|
||||
}
|
||||
|
||||
@@ -344,7 +348,7 @@ QString BorderTitleBlock::titleBlockTemplateName() const {
|
||||
*/
|
||||
void BorderTitleBlock::titleBlockTemplateChanged(const QString &template_name) {
|
||||
if (titleBlockTemplateName() != template_name) return;
|
||||
titleblock_template_renderer_ -> invalidateRenderedTemplate();
|
||||
m_titleblock_template_renderer -> invalidateRenderedTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -496,14 +500,14 @@ void BorderTitleBlock::draw(QPainter *painter)
|
||||
if (m_edge == Qt::BottomEdge)
|
||||
{
|
||||
painter -> translate(tbt_rect.topLeft());
|
||||
titleblock_template_renderer_ -> render(painter, tbt_rect.width());
|
||||
m_titleblock_template_renderer -> render(painter, tbt_rect.width());
|
||||
painter -> translate(-tbt_rect.topLeft());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->translate(tbt_rect.topLeft());
|
||||
painter->rotate(-90);
|
||||
titleblock_template_renderer_ -> render(painter, tbt_rect.width());
|
||||
m_titleblock_template_renderer -> render(painter, tbt_rect.width());
|
||||
painter->rotate(90);
|
||||
painter -> translate(-tbt_rect.topLeft());
|
||||
}
|
||||
@@ -581,7 +585,7 @@ void BorderTitleBlock::drawDxf(int width, int height, bool keep_aspect_ratio, QS
|
||||
if (display_titleblock_) {
|
||||
//qp -> translate(titleblock_rect_.topLeft());
|
||||
QRectF rect = titleBlockRect();
|
||||
titleblock_template_renderer_ -> renderDxf(rect, rect.width(), file_path, color);
|
||||
m_titleblock_template_renderer -> renderDxf(rect, rect.width(), file_path, color);
|
||||
//qp -> translate(-titleblock_rect_.topLeft());
|
||||
}
|
||||
|
||||
@@ -765,7 +769,7 @@ void BorderTitleBlock::updateDiagramContextForTitleBlock(const DiagramContext &i
|
||||
context.addValue("previous-folio-num", m_previous_folio_num);
|
||||
context.addValue("next-folio-num", m_next_folio_num);
|
||||
|
||||
titleblock_template_renderer_ -> setContext(context);
|
||||
m_titleblock_template_renderer -> setContext(context);
|
||||
}
|
||||
|
||||
QString BorderTitleBlock::incrementLetters(const QString &string) {
|
||||
@@ -866,9 +870,9 @@ void BorderTitleBlock::setAutoPageNum(const QString &auto_page_num) {
|
||||
void BorderTitleBlock::setPreviousFolioNum(const QString &previous)
|
||||
{
|
||||
m_previous_folio_num = previous;
|
||||
DiagramContext context = titleblock_template_renderer_->context();
|
||||
DiagramContext context = m_titleblock_template_renderer->context();
|
||||
context.addValue("previous-folio-num", m_previous_folio_num);
|
||||
titleblock_template_renderer_->setContext(context);
|
||||
m_titleblock_template_renderer->setContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -878,7 +882,7 @@ void BorderTitleBlock::setPreviousFolioNum(const QString &previous)
|
||||
void BorderTitleBlock::setNextFolioNum(const QString &next)
|
||||
{
|
||||
m_next_folio_num = next;
|
||||
DiagramContext context = titleblock_template_renderer_->context();
|
||||
DiagramContext context = m_titleblock_template_renderer->context();
|
||||
context.addValue("next-folio-num", m_next_folio_num);
|
||||
titleblock_template_renderer_->setContext(context);
|
||||
m_titleblock_template_renderer->setContext(context);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ class BorderTitleBlock : public QObject
|
||||
qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); }
|
||||
|
||||
QRectF titleBlockRect () const;
|
||||
|
||||
DiagramContext titleblockInformation() const;
|
||||
private:
|
||||
QRectF titleBlockRectForQPainter () const;
|
||||
|
||||
@@ -255,6 +257,6 @@ class BorderTitleBlock : public QObject
|
||||
bool display_columns_;
|
||||
bool display_rows_;
|
||||
bool display_border_;
|
||||
TitleBlockTemplateRenderer *titleblock_template_renderer_;
|
||||
TitleBlockTemplateRenderer *m_titleblock_template_renderer;
|
||||
};
|
||||
#endif
|
||||
|
||||
457
sources/dataBase/projectdatabase.cpp
Normal file
457
sources/dataBase/projectdatabase.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
/*
|
||||
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 "projectdatabase.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetproject.h"
|
||||
#include "elementprovider.h"
|
||||
#include "element.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramposition.h"
|
||||
|
||||
#include <QSqlError>
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::projectDataBase
|
||||
* Default constructor
|
||||
* @param project : project from the database work
|
||||
* @param parent : parent QObject
|
||||
*/
|
||||
projectDataBase::projectDataBase(QETProject *project, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_project(project)
|
||||
{
|
||||
createDataBase();
|
||||
}
|
||||
|
||||
projectDataBase::projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_project(project)
|
||||
{
|
||||
createDataBase(connection_name, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::~projectDataBase
|
||||
* Destructor
|
||||
*/
|
||||
projectDataBase::~projectDataBase() {
|
||||
m_data_base.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::elementsInfoFromQuery
|
||||
* @param query
|
||||
* @return quickly return all information about elements from @query, ensure that all
|
||||
* record returned by the query can be casted to string.
|
||||
* Each item of the Qvector represent an element and each value of the QStringList represent the recorded value.
|
||||
*/
|
||||
QVector<QStringList> projectDataBase::elementsInfoFromQuery(const QString &query)
|
||||
{
|
||||
QVector<QStringList> result_;
|
||||
|
||||
QSqlQuery query_(query, m_data_base);
|
||||
if (!query_.exec()) {
|
||||
qDebug() << "Query error : " << query_.lastError();
|
||||
}
|
||||
|
||||
while (query_.next())
|
||||
{
|
||||
QStringList record_;
|
||||
auto i=0;
|
||||
while (query_.value(i).isValid())
|
||||
{
|
||||
record_ << query_.value(i).toString();
|
||||
++i;
|
||||
}
|
||||
result_ << record_;
|
||||
}
|
||||
|
||||
return result_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::headersFromElementsInfoQuery
|
||||
* @param query
|
||||
* @return the header according to @query.
|
||||
* Header can be false, notably when user create is own query.
|
||||
*/
|
||||
QStringList projectDataBase::headersFromElementsInfoQuery(const QString &query)
|
||||
{
|
||||
QStringList header_string;
|
||||
if (!query.startsWith("SELECT ") && !query.contains("FROM")) {
|
||||
return header_string;
|
||||
}
|
||||
|
||||
auto header = query;
|
||||
header.remove(0, 7); //Remove SELECT from the string;
|
||||
header.truncate(header.indexOf("FROM")); //Now we only have the string between SELECT and FROM
|
||||
header.replace(" ", ""); //remove white space
|
||||
QStringList list = header.split(","); //split each column
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return header_string;
|
||||
}
|
||||
|
||||
for (int i=0 ; i<list.size() ; i++)
|
||||
{
|
||||
auto str = list.at(i);
|
||||
|
||||
if(str == "e.pos") { //Query in element table wich have only pose use in this case
|
||||
header_string.append(tr("Position"));
|
||||
}
|
||||
else if (str.contains("ei.")) //Query in element_info table
|
||||
{
|
||||
str.remove(0,3);
|
||||
header_string.append(QETApp::elementTranslatedInfoKey(str));
|
||||
}
|
||||
else if (str == "d.pos") { //query in diagram table wich have only pos use in this case
|
||||
header_string.append(tr("Position du folio"));
|
||||
}
|
||||
else if (str.contains("di.")) //query in diagram_info table
|
||||
{
|
||||
str.remove(0,3);
|
||||
header_string.append(QETApp::diagramTranslatedInfoKey(str));
|
||||
}
|
||||
else //Default case
|
||||
{
|
||||
if (str == "pos") {
|
||||
header_string.append(tr("Position"));
|
||||
} else if (QETApp::elementInfoKeys().contains(str)) {
|
||||
header_string.append(QETApp::elementTranslatedInfoKey(str));
|
||||
} else {
|
||||
header_string.append(QETApp::diagramTranslatedInfoKey(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return header_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
{
|
||||
populateDiagramTable();
|
||||
populateDiagramInfoTable();
|
||||
populateElementTable();
|
||||
populateElementInfoTable();
|
||||
emit dataBaseUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::project
|
||||
* @return the project of this database
|
||||
*/
|
||||
QETProject *projectDataBase::project() const {
|
||||
return m_project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::createDataBase
|
||||
* Create the data base
|
||||
* @return : true if the data base was successfully created.
|
||||
*/
|
||||
bool projectDataBase::createDataBase(const QString &connection_name, const QString &name)
|
||||
{
|
||||
|
||||
QString connect_name=connection_name;
|
||||
if (connect_name.isEmpty()) {
|
||||
connect_name = "qet_project_db_" + m_project->uuid().toString();
|
||||
}
|
||||
if (m_data_base.connectionNames().contains(connect_name)) {
|
||||
m_data_base = QSqlDatabase::database(connect_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data_base = QSqlDatabase::addDatabase("QSQLITE", connect_name);
|
||||
m_data_base.setDatabaseName(name);
|
||||
if(!m_data_base.open()) {
|
||||
m_data_base.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_data_base.exec("PRAGMA temp_store = MEMORY");
|
||||
m_data_base.exec("PRAGMA journal_mode = MEMORY");
|
||||
m_data_base.exec("PRAGMA synchronous = OFF");
|
||||
|
||||
QSqlQuery query_(m_data_base);
|
||||
bool first_ = true;
|
||||
|
||||
//Create diagram table
|
||||
QString diagram_table("CREATE TABLE diagram ("
|
||||
"uuid VARCHAR(50) PRIMARY KEY NOT NULL,"
|
||||
"pos INTEGER)");
|
||||
if (!query_.exec(diagram_table)) {
|
||||
qDebug() << "diagram_table query : "<< query_.lastError();
|
||||
}
|
||||
|
||||
//Create the table element
|
||||
QString element_table("CREATE TABLE element"
|
||||
"( "
|
||||
"uuid VARCHAR(50) PRIMARY KEY NOT NULL, "
|
||||
"diagram_uuid VARCHAR(50) NOT NULL,"
|
||||
"pos VARCHAR(6) NOT NULL,"
|
||||
"type VARCHAR(50),"
|
||||
"sub_type VARCHAR(50),"
|
||||
"FOREIGN KEY (diagram_uuid) REFERENCES diagram (uuid)"
|
||||
")");
|
||||
if (!query_.exec(element_table)) {
|
||||
qDebug() <<" element_table query : "<< query_.lastError();
|
||||
}
|
||||
|
||||
//Create the diagram info table
|
||||
QString diagram_info_table("CREATE TABLE diagram_info (diagram_uuid VARCHAR(50) PRIMARY KEY NOT NULL, ");
|
||||
first_ = true;
|
||||
for (auto string : QETApp::diagramInfoKeys())
|
||||
{
|
||||
if (first_) {
|
||||
first_ = false;
|
||||
} else {
|
||||
diagram_info_table += ", ";
|
||||
}
|
||||
diagram_info_table += string += string=="date" ? " DATE" : " VARCHAR(100)";
|
||||
}
|
||||
diagram_info_table += ", FOREIGN KEY (diagram_uuid) REFERENCES diagram (uuid))";
|
||||
if (!query_.exec(diagram_info_table)) {
|
||||
qDebug() << "diagram_info_table query : " << query_.lastError();
|
||||
}
|
||||
|
||||
//Create the element info table
|
||||
QString element_info_table("CREATE TABLE element_info(element_uuid VARCHAR(50) PRIMARY KEY NOT NULL,");
|
||||
first_=true;
|
||||
for (auto string : QETApp::elementInfoKeys())
|
||||
{
|
||||
if (first_) {
|
||||
first_ = false;
|
||||
} else {
|
||||
element_info_table += ",";
|
||||
}
|
||||
|
||||
element_info_table += string += " VARCHAR(100)";
|
||||
}
|
||||
element_info_table += ", FOREIGN KEY (element_uuid) REFERENCES element (uuid));";
|
||||
|
||||
if (!query_.exec(element_info_table)) {
|
||||
qDebug() << " element_info_table query : " << query_.lastError();
|
||||
}
|
||||
}
|
||||
|
||||
updateDB();
|
||||
return true;
|
||||
}
|
||||
|
||||
void projectDataBase::populateDiagramTable()
|
||||
{
|
||||
QSqlQuery query_(m_data_base);
|
||||
query_.exec("DELETE FROM diagram");
|
||||
|
||||
QString insert_("INSERT INTO diagram (uuid, pos) VALUES (:uuid, :pos)");
|
||||
query_.prepare(insert_);
|
||||
for (auto diagram : m_project->diagrams())
|
||||
{
|
||||
query_.bindValue(":uuid", diagram->uuid().toString());
|
||||
query_.bindValue(":pos", m_project->folioIndex(diagram));
|
||||
if(!query_.exec()) {
|
||||
qDebug() << "projectDataBase::populateDiagramTable insert error : " << query_.lastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::populateElementTable
|
||||
* Populate the element table
|
||||
*/
|
||||
void projectDataBase::populateElementTable()
|
||||
{
|
||||
QSqlQuery query_(m_data_base);
|
||||
query_.exec("DELETE FROM element");
|
||||
|
||||
QString insert_("INSERT INTO element (uuid, diagram_uuid, pos, type, sub_type) VALUES (:uuid, :diagram_uuid, :pos, :type, :sub_type)");
|
||||
query_.prepare(insert_);
|
||||
|
||||
for (auto diagram : m_project->diagrams())
|
||||
{
|
||||
ElementProvider ep(diagram);
|
||||
QList<Element *> elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master);
|
||||
//Insert all value into the database
|
||||
for (auto elmt : elements_list)
|
||||
{
|
||||
query_.bindValue(":uuid", elmt->uuid().toString());
|
||||
query_.bindValue(":diagram_uuid", diagram->uuid().toString());
|
||||
query_.bindValue(":pos", diagram->convertPosition(elmt->scenePos()).toString());
|
||||
query_.bindValue(":type", elmt->linkTypeToString());
|
||||
query_.bindValue(":sub_type", elmt->kindInformations()["type"].toString());
|
||||
if (!query_.exec()) {
|
||||
qDebug() << "projectDataBase::populateElementTable insert error : " << query_.lastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::populateElementsTable
|
||||
* Populate the elements table
|
||||
*/
|
||||
void projectDataBase::populateElementInfoTable()
|
||||
{
|
||||
QSqlQuery query(m_data_base);
|
||||
query.exec("DELETE FROM element_info");
|
||||
|
||||
|
||||
//Prepare the query used for insert new record
|
||||
QStringList bind_values;
|
||||
for (auto key : QETApp::elementInfoKeys()) {
|
||||
bind_values << key.prepend(":");
|
||||
}
|
||||
QString insert("INSERT INTO element_info (element_uuid," +
|
||||
QETApp::elementInfoKeys().join(", ") +
|
||||
") VALUES (:uuid," +
|
||||
bind_values.join(", ") +
|
||||
")");
|
||||
|
||||
query.prepare(insert);
|
||||
|
||||
for (auto *diagram : m_project->diagrams())
|
||||
{
|
||||
ElementProvider ep(diagram);
|
||||
QList<Element *> elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master);
|
||||
|
||||
//Insert all value into the database
|
||||
for (auto elmt : elements_list)
|
||||
{
|
||||
query.bindValue(":uuid", elmt->uuid().toString());
|
||||
auto hash = elementInfoToString(elmt);
|
||||
for (auto key : hash.keys())
|
||||
{
|
||||
QString value = hash.value(key);
|
||||
QString bind = key.prepend(":");
|
||||
query.bindValue(bind, value);
|
||||
}
|
||||
|
||||
if (!query.exec()) {
|
||||
qDebug() << "projectDataBase::populateElementInfoTable insert error : " << query.lastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void projectDataBase::populateDiagramInfoTable()
|
||||
{
|
||||
QSqlQuery query(m_data_base);
|
||||
query.exec("DELETE FROM diagram_info");
|
||||
|
||||
//Prepare the query used for insert new record
|
||||
QStringList bind_values;
|
||||
for (auto key : QETApp::diagramInfoKeys()) {
|
||||
bind_values << key.prepend(":");
|
||||
}
|
||||
QString insert("INSERT INTO diagram_info (diagram_uuid, " +
|
||||
QETApp::diagramInfoKeys().join(", ") +
|
||||
") VALUES (:uuid, " +
|
||||
bind_values.join(", ") +
|
||||
")");
|
||||
|
||||
query.prepare(insert);
|
||||
|
||||
for (auto *diagram : m_project->diagrams())
|
||||
{
|
||||
query.bindValue(":uuid", diagram->uuid());
|
||||
|
||||
auto infos = diagram->border_and_titleblock.titleblockInformation();
|
||||
for (auto key : QETApp::diagramInfoKeys())
|
||||
{
|
||||
if (key == "date") {
|
||||
query.bindValue(":date", QDate::fromString(infos.value("date").toString(), Qt::SystemLocaleShortDate));
|
||||
} else {
|
||||
auto value = infos.value(key);
|
||||
auto bind = key.prepend(":");
|
||||
query.bindValue(bind, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!query.exec()) {
|
||||
qDebug() << "projectDataBase::populateDiagramInfoTable insert error : " << query.lastError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::elementInfoToString
|
||||
* @param elmt
|
||||
* @return the element information in hash as key for the info name and value as the information value.
|
||||
*/
|
||||
QHash<QString, QString> projectDataBase::elementInfoToString(Element *elmt)
|
||||
{
|
||||
QHash<QString, QString> hash; //Store the value for each columns
|
||||
for (auto key : QETApp::elementInfoKeys())
|
||||
{
|
||||
if (key == "label") {
|
||||
hash.insert(key, elmt->actualLabel());
|
||||
}
|
||||
else {
|
||||
hash.insert(key, elmt->elementInformations()[key].toString());
|
||||
}
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief projectDataBase::exportDb
|
||||
* @param parent
|
||||
* @param caption
|
||||
* @param dir
|
||||
* @param filter
|
||||
* @param selectedFilter
|
||||
* @param options
|
||||
*/
|
||||
void projectDataBase::exportDb(projectDataBase *db, QWidget *parent, const QString &caption, const QString &dir)
|
||||
{
|
||||
auto caption_ = caption;
|
||||
if (caption_.isEmpty()) {
|
||||
caption_ = tr("Exporter la base de données interne du projet");
|
||||
}
|
||||
|
||||
auto dir_ = dir;
|
||||
if(dir_.isEmpty()) {
|
||||
dir_ = db->project()->filePath();
|
||||
if (dir_.isEmpty()) {
|
||||
dir_ = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first();
|
||||
dir_ += QString("/") += tr("sans_nom") += ".sqlite";
|
||||
} else {
|
||||
dir_.remove(".qet");
|
||||
dir_.append(".sqlite");
|
||||
}
|
||||
}
|
||||
|
||||
auto path_ = QFileDialog::getSaveFileName(parent, caption_, dir_, "*.sqlite");
|
||||
if (path_.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Database is filled at creation, work is done.
|
||||
QString connection_name("export_project_db_" + db->project()->uuid().toString());
|
||||
projectDataBase file_db(db->project(), connection_name, path_);
|
||||
QSqlDatabase::removeDatabase(connection_name);
|
||||
}
|
||||
74
sources/dataBase/projectdatabase.h
Normal file
74
sources/dataBase/projectdatabase.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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 PROJECTDATABASE_H
|
||||
#define PROJECTDATABASE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QPointer>
|
||||
#include <QFileDialog>
|
||||
|
||||
class Element;
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The projectDataBase class
|
||||
* This class wrap a sqlite data base where you can find several thing about
|
||||
* the content of a project.
|
||||
*
|
||||
* NOTE this class is still in developement.
|
||||
*/
|
||||
class projectDataBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
projectDataBase(QETProject *project, QObject *parent = nullptr);
|
||||
private:
|
||||
projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent = nullptr);
|
||||
public:
|
||||
virtual ~projectDataBase() override;
|
||||
|
||||
QVector<QStringList> elementsInfoFromQuery(const QString &query);
|
||||
void updateDB();
|
||||
QETProject *project() const;
|
||||
|
||||
static QStringList headersFromElementsInfoQuery(const QString &query);
|
||||
|
||||
signals:
|
||||
void dataBaseUpdated();
|
||||
|
||||
private:
|
||||
bool createDataBase(const QString &connection_name= QString(), const QString &name = QString());
|
||||
void populateDiagramTable();
|
||||
void populateElementTable();
|
||||
void populateElementInfoTable();
|
||||
void populateDiagramInfoTable();
|
||||
static QHash<QString, QString> elementInfoToString(Element *elmt);
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QSqlDatabase m_data_base;
|
||||
QSqlQuery m_insert_elements_query;
|
||||
|
||||
public:
|
||||
static void exportDb(projectDataBase *db, QWidget *parent = nullptr, const QString &caption = QString(), const QString &dir = QString());
|
||||
};
|
||||
|
||||
#endif // PROJECTDATABASE_H
|
||||
364
sources/dataBase/ui/elementquerywidget.cpp
Normal file
364
sources/dataBase/ui/elementquerywidget.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
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 "elementquerywidget.h"
|
||||
#include "ui_elementquerywidget.h"
|
||||
#include "qetapp.h"
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::ElementQueryWidget
|
||||
* @param parent
|
||||
*/
|
||||
ElementQueryWidget::ElementQueryWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ElementQueryWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_export_info.insert("e.pos", tr("Position"));
|
||||
m_export_info.insert("di.title", tr("Titre du folio"));
|
||||
m_export_info.insert("d.pos", tr("Position du folio"));
|
||||
m_export_info.insert("di.folio", tr("Numéro du folio"));
|
||||
|
||||
m_button_group.setExclusive(false);
|
||||
m_button_group.addButton(ui->m_all_cb, 0);
|
||||
m_button_group.addButton(ui->m_terminal_cb, 1);
|
||||
m_button_group.addButton(ui->m_simple_cb, 2);
|
||||
m_button_group.addButton(ui->m_button_cb, 3);
|
||||
m_button_group.addButton(ui->m_coil_cb, 4);
|
||||
m_button_group.addButton(ui->m_protection_cb, 5);
|
||||
connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), [this](int id)
|
||||
{
|
||||
auto check_box = static_cast<QCheckBox *>(m_button_group.button(0));
|
||||
if (id == 0)
|
||||
{
|
||||
switch (check_box->checkState()) {
|
||||
case Qt::Checked :
|
||||
for (auto button : m_button_group.buttons()) {
|
||||
button->setChecked(true);
|
||||
}
|
||||
break;
|
||||
case Qt::Unchecked :
|
||||
for (auto button : m_button_group.buttons()) {
|
||||
button->setChecked(false);
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int checked = 0;
|
||||
for (int i=1 ; i<5 ; ++i) {
|
||||
if (m_button_group.button(i)->isChecked()) {++checked;}
|
||||
}
|
||||
|
||||
switch (checked)
|
||||
{
|
||||
case 0 :
|
||||
check_box->setCheckState(Qt::Unchecked);
|
||||
break;
|
||||
case 5:
|
||||
check_box->setCheckState(Qt::Checked);
|
||||
break;
|
||||
default:
|
||||
check_box->setCheckState(Qt::PartiallyChecked);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateQueryLine();
|
||||
});
|
||||
|
||||
setUpItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::~ElementQueryWidget
|
||||
*/
|
||||
ElementQueryWidget::~ElementQueryWidget() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::queryStr
|
||||
* @return The current query
|
||||
*/
|
||||
QString ElementQueryWidget::queryStr() const
|
||||
{
|
||||
//User define is own query
|
||||
if (ui->m_edit_sql_query_cb->isChecked()) {
|
||||
return ui->m_sql_query->text();
|
||||
}
|
||||
//Made a string list with the colomns (keys) choosen by the user
|
||||
QStringList keys = selectedKeys();
|
||||
|
||||
QString select ="SELECT ";
|
||||
QString order_by = " ORDER BY ";
|
||||
QString filter_;
|
||||
|
||||
QString column;
|
||||
bool first = true;
|
||||
for (auto key: keys) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
column += ", ";
|
||||
order_by += ", ";
|
||||
}
|
||||
column += key;
|
||||
order_by += key;
|
||||
|
||||
auto f = FilterFor(key);
|
||||
switch (f.first)
|
||||
{
|
||||
case 0: //No filter
|
||||
break;
|
||||
case 1: //Not empty
|
||||
filter_ += QString(" AND ") += key += " IS NOT NULL";
|
||||
break;
|
||||
case 2: //empty
|
||||
filter_ += QString(" AND ") += key += " IS NULL";
|
||||
break;
|
||||
case 3: // contain
|
||||
filter_ += QString(" AND ") += key += QString(" LIKE'%") += f.second += "%'";
|
||||
break;
|
||||
case 4: // not contain
|
||||
filter_ += QString(" AND ") += key += QString(" NOT LIKE'%") += f.second += "%'";
|
||||
break;
|
||||
case 5: // is equal
|
||||
filter_ += QString(" AND ") += key += QString("='") += f.second += "'";
|
||||
break;
|
||||
case 6: // is not equal
|
||||
filter_ += QString(" AND ") += key += QString("!='") += f.second += "'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString from = " FROM element_info ei, element e, diagram d, diagram_info di";
|
||||
QString where = " WHERE ei.element_uuid = e.uuid"
|
||||
" AND di.diagram_uuid = d.uuid"
|
||||
" AND e.diagram_uuid = d.uuid";
|
||||
|
||||
if (ui->m_all_cb->checkState() == Qt::PartiallyChecked)
|
||||
{
|
||||
if (ui->m_terminal_cb->isChecked()) {where += " AND e.type = 'Terminale'";}
|
||||
if (ui->m_simple_cb->isChecked()) {where += " AND e.type = 'Simple'";}
|
||||
if (ui->m_button_cb->isChecked()) {where += " AND e.sub_type = 'commutator'";}
|
||||
if (ui->m_coil_cb->isChecked()) {where += " AND e.sub_type = 'coil'";}
|
||||
if (ui->m_protection_cb->isChecked()) {where += " AND e.sub_type = 'protection'";}
|
||||
}
|
||||
|
||||
|
||||
QString q(select + column + from + where + filter_ + order_by);
|
||||
return q;
|
||||
}
|
||||
|
||||
QStringList ElementQueryWidget::header() const
|
||||
{
|
||||
//Made a string list with the colomns (keys) choosen by the user
|
||||
QStringList headers;
|
||||
int row = 0;
|
||||
while (auto *item = ui->m_choosen_list->item(row))
|
||||
{
|
||||
headers.append(item->data(Qt::DisplayRole).toString());
|
||||
++row;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::updateQueryLine
|
||||
*/
|
||||
void ElementQueryWidget::updateQueryLine() {
|
||||
ui->m_sql_query->setText(queryStr());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::selectedKeys
|
||||
* @return the current keys of selected infos to be exported
|
||||
*/
|
||||
QStringList ElementQueryWidget::selectedKeys() const
|
||||
{
|
||||
//Made a string list with the colomns (keys) choosen by the user
|
||||
QStringList keys;
|
||||
int row = 0;
|
||||
while (auto *item = ui->m_choosen_list->item(row))
|
||||
{
|
||||
keys.append(item->data(Qt::UserRole).toString());
|
||||
++row;
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
void ElementQueryWidget::setUpItems()
|
||||
{
|
||||
for(QString key : QETApp::elementInfoKeys())
|
||||
{
|
||||
auto item = new QListWidgetItem(QETApp::elementTranslatedInfoKey(key), ui->m_var_list);
|
||||
item->setData(Qt::UserRole, "ei." + key);
|
||||
m_items_list << item;
|
||||
}
|
||||
|
||||
|
||||
for (auto key : m_export_info.keys())
|
||||
{
|
||||
auto item = new QListWidgetItem(m_export_info.value(key), ui->m_var_list);
|
||||
item->setData(Qt::UserRole, key);
|
||||
m_items_list << item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::FilterFor
|
||||
* @param key
|
||||
* @return the filter associated to key
|
||||
*/
|
||||
QPair<int, QString> ElementQueryWidget::FilterFor(const QString &key) const {
|
||||
return m_filter.value(key, qMakePair(0, QString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::on_m_up_pb_clicked
|
||||
*/
|
||||
void ElementQueryWidget::on_m_up_pb_clicked()
|
||||
{
|
||||
auto row = ui->m_choosen_list->currentRow();
|
||||
if(row <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *item = ui->m_choosen_list->takeItem(row);
|
||||
ui->m_choosen_list->insertItem(row-1, item);
|
||||
ui->m_choosen_list->setCurrentItem(item);
|
||||
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::on_m_add_pb_clicked
|
||||
*/
|
||||
void ElementQueryWidget::on_m_add_pb_clicked()
|
||||
{
|
||||
if (auto *item = ui->m_var_list->takeItem(ui->m_var_list->currentRow())) {
|
||||
ui->m_choosen_list->addItem(item);
|
||||
}
|
||||
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::on_m_remove_pb_clicked
|
||||
*/
|
||||
void ElementQueryWidget::on_m_remove_pb_clicked()
|
||||
{
|
||||
if (auto *item = ui->m_choosen_list->takeItem(ui->m_choosen_list->currentRow())) {
|
||||
ui->m_var_list->addItem(item);
|
||||
}
|
||||
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::on_m_down_pb_clicked
|
||||
*/
|
||||
void ElementQueryWidget::on_m_down_pb_clicked()
|
||||
{
|
||||
auto row = ui->m_choosen_list->currentRow();
|
||||
if (row == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *item = ui->m_choosen_list->takeItem(row);
|
||||
ui->m_choosen_list->insertItem(row+1, item);
|
||||
ui->m_choosen_list->setCurrentItem(item);
|
||||
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementQueryWidget::on_m_edit_sql_query_cb_clicked
|
||||
*/
|
||||
void ElementQueryWidget::on_m_edit_sql_query_cb_clicked()
|
||||
{
|
||||
ui->m_sql_query->setEnabled(ui->m_edit_sql_query_cb->isChecked());
|
||||
ui->m_info_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked());
|
||||
ui->m_parametre_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked());
|
||||
|
||||
if (ui->m_edit_sql_query_cb->isChecked() && !m_custom_query.isEmpty())
|
||||
{
|
||||
ui->m_sql_query->setText(m_custom_query);
|
||||
}
|
||||
else if (!ui->m_edit_sql_query_cb->isChecked())
|
||||
{
|
||||
m_custom_query = ui->m_sql_query->text();
|
||||
updateQueryLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ElementQueryWidget::on_m_plant_textChanged(const QString &arg1) {
|
||||
Q_UNUSED(arg1)
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
void ElementQueryWidget::on_m_location_textChanged(const QString &arg1) {
|
||||
Q_UNUSED(arg1)
|
||||
updateQueryLine();
|
||||
}
|
||||
|
||||
void ElementQueryWidget::on_m_filter_le_textEdited(const QString &arg1)
|
||||
{
|
||||
if (auto item = ui->m_choosen_list->currentItem())
|
||||
{
|
||||
auto key = item->data(Qt::UserRole).toString();
|
||||
auto type = ui->m_filter_type_cb->currentIndex();
|
||||
auto value = arg1;
|
||||
|
||||
m_filter.insert(key, qMakePair(type, value));
|
||||
updateQueryLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ElementQueryWidget::on_m_filter_type_cb_activated(int index)
|
||||
{
|
||||
if (auto item = ui->m_choosen_list->currentItem())
|
||||
{
|
||||
auto key = item->data(Qt::UserRole).toString();
|
||||
auto type = index;
|
||||
auto value = ui->m_filter_le->text();
|
||||
|
||||
m_filter.insert(key, qMakePair(type, value));
|
||||
ui->m_filter_le->setDisabled(index <= 2);
|
||||
updateQueryLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ElementQueryWidget::on_m_choosen_list_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
|
||||
{
|
||||
Q_UNUSED(previous)
|
||||
|
||||
if (!current)
|
||||
return;
|
||||
|
||||
auto key = current->data(Qt::UserRole).toString();
|
||||
auto p = FilterFor(key);
|
||||
ui->m_filter_type_cb->setCurrentIndex(p.first);
|
||||
ui->m_filter_le->setText(p.second);
|
||||
ui->m_filter_le->setEnabled(p.first>=3);
|
||||
}
|
||||
73
sources/dataBase/ui/elementquerywidget.h
Normal file
73
sources/dataBase/ui/elementquerywidget.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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 ELEMENTQUERYWIDGET_H
|
||||
#define ELEMENTQUERYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QButtonGroup>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace Ui {
|
||||
class ElementQueryWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The ElementQueryWidget class
|
||||
* A widget use to edit a sql query for get element information
|
||||
* This widget only work to get information from ProjectDataBase
|
||||
*/
|
||||
class ElementQueryWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ElementQueryWidget(QWidget *parent = nullptr);
|
||||
~ElementQueryWidget();
|
||||
|
||||
QString queryStr() const;
|
||||
QStringList header() const;
|
||||
|
||||
private slots:
|
||||
void on_m_up_pb_clicked();
|
||||
void on_m_add_pb_clicked();
|
||||
void on_m_remove_pb_clicked();
|
||||
void on_m_down_pb_clicked();
|
||||
void on_m_edit_sql_query_cb_clicked();
|
||||
void on_m_plant_textChanged(const QString &arg1);
|
||||
void on_m_location_textChanged(const QString &arg1);
|
||||
void on_m_filter_le_textEdited(const QString &arg1);
|
||||
void on_m_filter_type_cb_activated(int index);
|
||||
|
||||
void updateQueryLine();
|
||||
QStringList selectedKeys() const;
|
||||
void setUpItems();
|
||||
QPair<int, QString> FilterFor(const QString &key) const;
|
||||
|
||||
void on_m_choosen_list_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
|
||||
private:
|
||||
Ui::ElementQueryWidget *ui;
|
||||
QHash <QString, QString> m_export_info;
|
||||
QButtonGroup m_button_group;
|
||||
QList <QListWidgetItem *> m_items_list;
|
||||
QString m_custom_query;
|
||||
QHash <QString, QPair<int, QString>> m_filter;
|
||||
};
|
||||
|
||||
#endif // ELEMENTQUERYWIDGET_H
|
||||
418
sources/dataBase/ui/elementquerywidget.ui
Normal file
418
sources/dataBase/ui/elementquerywidget.ui
Normal file
@@ -0,0 +1,418 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ElementQueryWidget</class>
|
||||
<widget class="QWidget" name="ElementQueryWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>341</width>
|
||||
<height>527</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="m_info_widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<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 row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Informations disponibles</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Informations à exporter</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="m_var_list"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QListWidget" name="m_choosen_list"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<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>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_up_pb">
|
||||
<property name="toolTip">
|
||||
<string>Monter la sélection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/go-up.png</normaloff>:/ico/16x16/go-up.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_add_pb">
|
||||
<property name="toolTip">
|
||||
<string>Ajouter la sélection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_remove_pb">
|
||||
<property name="toolTip">
|
||||
<string>Supprimer la sélection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/list-remove.png</normaloff>:/ico/16x16/list-remove.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_down_pb">
|
||||
<property name="toolTip">
|
||||
<string>Descendre la sélection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/go-down.png</normaloff>:/ico/16x16/go-down.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<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>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="m_filter_type_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Pas de filtre</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>N'est pas vide</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Est vide</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Contient</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Ne contient pas</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Est égal à</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>N'est pas égale à</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="m_filter_le"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Filtre :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="m_parametre_widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<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="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Type d'éléments</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="m_simple_cb">
|
||||
<property name="text">
|
||||
<string>Simples</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="m_all_cb">
|
||||
<property name="text">
|
||||
<string>Tous</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="m_coil_cb">
|
||||
<property name="text">
|
||||
<string>Contacteurs et relais</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="m_button_cb">
|
||||
<property name="text">
|
||||
<string>Boutons et commutateurs</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="m_terminal_cb">
|
||||
<property name="text">
|
||||
<string>Borniers</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="m_protection_cb">
|
||||
<property name="text">
|
||||
<string>Organes de protection</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="m_load_pb">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ouvrir la configuration sélectionné</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/folder-open.png</normaloff>:/ico/16x16/folder-open.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QComboBox" name="m_conf_cb">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="m_save_name_le"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="m_save_current_conf_pb">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Sauvegarder la configuration actuelle</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/document-save.png</normaloff>:/ico/16x16/document-save.png</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_edit_sql_query_cb">
|
||||
<property name="toolTip">
|
||||
<string>Requête SQL personnalisée</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Requête SQL :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_sql_query">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../qelectrotech.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -444,6 +444,14 @@ void Diagram::keyReleaseEvent(QKeyEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::uuid
|
||||
* @return the uuid of this diagram
|
||||
*/
|
||||
QUuid Diagram::uuid() {
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::setEventInterface
|
||||
* Set event_interface has current interface.
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <QtWidgets>
|
||||
#include <QtXml>
|
||||
#include <QHash>
|
||||
#include <QUuid>
|
||||
|
||||
#include "bordertitleblock.h"
|
||||
#include "conductorproperties.h"
|
||||
#include "exportproperties.h"
|
||||
@@ -119,6 +121,7 @@ class Diagram : public QGraphicsScene
|
||||
|
||||
bool m_freeze_new_elements;
|
||||
bool m_freeze_new_conductors_;
|
||||
QUuid m_uuid = QUuid::createUuid();
|
||||
|
||||
// METHODS
|
||||
protected:
|
||||
@@ -133,6 +136,7 @@ class Diagram : public QGraphicsScene
|
||||
void keyReleaseEvent (QKeyEvent *) override;
|
||||
|
||||
public:
|
||||
QUuid uuid();
|
||||
void setEventInterface (DiagramEventInterface *event_interface);
|
||||
void clearEventInterface();
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@ void DiagramContext::add(DiagramContext other)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramContext::remove
|
||||
* @param key
|
||||
*/
|
||||
void DiagramContext::remove(const QString &key) {
|
||||
m_content.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@return a list containing all the keys in the context object.
|
||||
*/
|
||||
|
||||
@@ -62,6 +62,7 @@ class DiagramContext
|
||||
};
|
||||
|
||||
void add(DiagramContext other);
|
||||
void remove(const QString &key);
|
||||
QList<QString> keys(KeyOrder = None) const;
|
||||
bool contains(const QString &) const;
|
||||
const QVariant operator[](const QString &) const;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "qetproject.h"
|
||||
#include "diagram.h"
|
||||
#include "qetgraphicsitem/element.h"
|
||||
#include "qetgraphicstableitem.h"
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
/**
|
||||
* @brief ElementProvider::ElementProvider Constructor
|
||||
@@ -27,8 +29,8 @@
|
||||
*/
|
||||
ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram)
|
||||
{
|
||||
diag_list = prj->diagrams();
|
||||
diag_list.removeOne(diagram);
|
||||
m_diagram_list = prj->diagrams();
|
||||
m_diagram_list.removeOne(diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,7 @@ ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram)
|
||||
* @param diag Diagram to search
|
||||
*/
|
||||
ElementProvider::ElementProvider(Diagram *diag) {
|
||||
diag_list << diag;
|
||||
m_diagram_list << diag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +54,7 @@ QList <Element *> ElementProvider::freeElement(const int filter) const{
|
||||
QList <Element *> free_elmt;
|
||||
|
||||
//serch in all diagram
|
||||
foreach (Diagram *d, diag_list) {
|
||||
foreach (Diagram *d, m_diagram_list) {
|
||||
//get all element in diagram d
|
||||
QList <Element *> elmt_list;
|
||||
elmt_list = d->elements();
|
||||
@@ -72,7 +74,7 @@ QList <Element *> ElementProvider::freeElement(const int filter) const{
|
||||
QList <Element *> ElementProvider::fromUuids(QList<QUuid> uuid_list) const {
|
||||
QList <Element *> found_element;
|
||||
|
||||
foreach (Diagram *d, diag_list) {
|
||||
foreach (Diagram *d, m_diagram_list) {
|
||||
foreach(Element *elmt, d->elements()) {
|
||||
if (uuid_list.contains(elmt->uuid())) {
|
||||
found_element << elmt;
|
||||
@@ -94,7 +96,7 @@ QList <Element *> ElementProvider::find(const int filter) const {
|
||||
QList <Element *> elmt_;
|
||||
|
||||
//serch in all diagram
|
||||
foreach (Diagram *d, diag_list) {
|
||||
foreach (Diagram *d, m_diagram_list) {
|
||||
//get all element in diagram d
|
||||
QList <Element *> elmt_list;
|
||||
elmt_list = d->elements();
|
||||
@@ -105,3 +107,52 @@ QList <Element *> ElementProvider::find(const int filter) const {
|
||||
}
|
||||
return (elmt_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementProvider::table
|
||||
* @param table
|
||||
* @param model
|
||||
* @return All tables wich display the derivated class of @model (if set) and not already in all the chain of next/previous table of @table (if set)
|
||||
* If table and model are nullptr, return every tables
|
||||
*/
|
||||
QVector<QetGraphicsTableItem *> ElementProvider::table(QetGraphicsTableItem *table, QAbstractItemModel *model)
|
||||
{
|
||||
QVector<QetGraphicsTableItem *> v_;
|
||||
QVector<QetGraphicsTableItem *> linked_vector;
|
||||
|
||||
if (table)
|
||||
{
|
||||
auto linked_table = table->previousTable() ? table->previousTable() : table->nextTable(); //table can be inside a chain, at the head of a chain or alone
|
||||
while (linked_table) { //Go to the first table
|
||||
if (linked_table->previousTable())
|
||||
linked_table = linked_table->previousTable();
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (linked_table) { //Store each linked table in linked_vector
|
||||
linked_vector.append(linked_table);
|
||||
linked_table = linked_table->nextTable();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto d : m_diagram_list) {
|
||||
for (auto item_ : d->items())
|
||||
{
|
||||
if(item_->type() == QetGraphicsTableItem::Type)
|
||||
{
|
||||
auto found_table = static_cast<QetGraphicsTableItem *>(item_);
|
||||
|
||||
if (linked_vector.contains(found_table)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!model ||
|
||||
(found_table->model() &&
|
||||
model->metaObject()->className() == found_table->model()->metaObject()->className()))
|
||||
{v_.append(found_table);}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return v_;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
|
||||
#include <QUuid>
|
||||
#include <QList>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class QETProject;
|
||||
class Diagram;
|
||||
class Element;
|
||||
class QetGraphicsTableItem;
|
||||
|
||||
/**
|
||||
this class can search in the given diagram or project some kind of element
|
||||
@@ -39,9 +41,10 @@ class ElementProvider
|
||||
QList <Element *> freeElement(const int filter) const;
|
||||
QList <Element *> fromUuids(QList <QUuid>) const;
|
||||
QList <Element *> find(const int filter) const;
|
||||
QVector <QetGraphicsTableItem *> table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr);
|
||||
|
||||
private:
|
||||
QList <Diagram *> diag_list;
|
||||
QList <Diagram *> m_diagram_list;
|
||||
};
|
||||
|
||||
#endif // ELEMENTPROVIDER_H
|
||||
|
||||
207
sources/factory/propertieseditorfactory.cpp
Normal file
207
sources/factory/propertieseditorfactory.cpp
Normal 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;
|
||||
}
|
||||
34
sources/factory/propertieseditorfactory.h
Normal file
34
sources/factory/propertieseditorfactory.h
Normal 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
|
||||
@@ -297,15 +297,15 @@ QStringList QETApp::elementInfoKeys()
|
||||
|
||||
<< "comment"
|
||||
<< "function"
|
||||
<< "tension-protocol"
|
||||
<< "tension_protocol"
|
||||
<< "auxiliary1"
|
||||
<< "auxiliary2"
|
||||
|
||||
<< "description"
|
||||
<< "designation"
|
||||
<< "manufacturer"
|
||||
<< "manufacturer-reference"
|
||||
<< "machine-manufacturer-reference"
|
||||
<< "manufacturer_reference"
|
||||
<< "machine_manufacturer_reference"
|
||||
<< "supplier"
|
||||
<< "quantity"
|
||||
<< "unity";
|
||||
@@ -328,15 +328,15 @@ QString QETApp::elementTranslatedInfoKey(const QString &info)
|
||||
|
||||
else if (info == "comment") return tr("Commentaire");
|
||||
else if (info == "function") return tr("Fonction");
|
||||
else if (info == "tension-protocol") return tr("Tension / Protocole");
|
||||
else if (info == "tension_protocol") return tr("Tension / Protocole");
|
||||
else if (info == "auxiliary1") return tr("Bloc auxiliaire 1");
|
||||
else if (info == "auxiliary2") return tr("Bloc auxiliaire 2");
|
||||
|
||||
else if (info == "description") return tr("Description textuelle");
|
||||
else if (info == "designation") return tr("Numéro d'article");
|
||||
else if (info == "manufacturer") return tr("Fabricant");
|
||||
else if (info == "manufacturer-reference") return tr("Numéro de commande");
|
||||
else if (info == "machine-manufacturer-reference") return tr("Numéro interne");
|
||||
else if (info == "manufacturer_reference") return tr("Numéro de commande");
|
||||
else if (info == "machine_manufacturer_reference") return tr("Numéro interne");
|
||||
else if (info == "supplier") return tr("Fournisseur");
|
||||
else if (info == "quantity") return tr("Quantité");
|
||||
else if (info == "unity") return tr("Unité");
|
||||
@@ -362,16 +362,16 @@ QString QETApp::elementInfoToVar(const QString &info)
|
||||
else if (info == "description") return QString("%{description}");
|
||||
else if (info == "designation") return QString("%{designation}");
|
||||
else if (info == "manufacturer") return QString("%{manufacturer}");
|
||||
else if (info == "manufacturer-reference") return QString("%{manufacturer-reference}");
|
||||
else if (info == "manufacturer_reference") return QString("%{manufacturer_reference}");
|
||||
else if (info == "supplier") return QString("%{supplier}");
|
||||
else if (info == "quantity") return QString("%{quantity}");
|
||||
else if (info == "unity") return QString("%{unity}");
|
||||
else if (info == "auxiliary1") return QString("%{auxiliary1}");
|
||||
else if (info == "auxiliary2") return QString("%{auxiliary2}");
|
||||
else if (info == "machine-manufacturer-reference") return QString("%{machine-manufacturer-reference}");
|
||||
else if (info == "machine_manufacturer_reference") return QString("%{machine_manufacturer_reference}");
|
||||
else if (info == "location") return QString("%{location}");
|
||||
else if (info == "function") return QString("%{function}");
|
||||
else if (info == "tension-protocol") return QString("%{tension-protocol}");
|
||||
else if (info == "tension_protocol") return QString("%{tension_protocol}");
|
||||
|
||||
return (QString ("%{void}"));
|
||||
}
|
||||
@@ -408,7 +408,7 @@ QString QETApp::conductorTranslatedInfoKey(const QString &key)
|
||||
|
||||
/**
|
||||
* @brief QETApp::diagramInfoKeys
|
||||
* @return the diagram default information keys
|
||||
* @return the diagram default default information keys
|
||||
*/
|
||||
QStringList QETApp::diagramInfoKeys()
|
||||
{
|
||||
@@ -420,6 +420,8 @@ QStringList QETApp::diagramInfoKeys()
|
||||
list.append("plant");
|
||||
list.append("locmach");
|
||||
list.append("indexrev");
|
||||
list.append("date");
|
||||
list.append("display_folio");
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -439,6 +441,7 @@ QString QETApp::diagramTranslatedInfoKey(const QString &key)
|
||||
else if (key == "plant") return tr("Installation");
|
||||
else if (key == "locmach") return tr("Localisation");
|
||||
else if (key == "indexrev") return tr("Indice Rev");
|
||||
else if (key == "date") return tr("Date");
|
||||
else return QString();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "conductornumexport.h"
|
||||
#include "qetgraphicstableitem.h"
|
||||
#include "bomexportdialog.h"
|
||||
#include "nomenclaturemodel.h"
|
||||
|
||||
#include <KAutoSaveFile>
|
||||
|
||||
@@ -386,9 +387,29 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Add a nomenclature item
|
||||
m_add_nomenclature = new QAction(QET::Icons::TableOfContent, tr("Ajouter un tableau lambda (Fonctionnalité en cours de devellopement)"),this);
|
||||
connect(m_add_nomenclature, &QAction::triggered, [this]() {
|
||||
if(this->currentDiagramView()) {
|
||||
this->currentDiagramView()->diagram()->addItem(new QetGraphicsTableItem());
|
||||
connect(m_add_nomenclature, &QAction::triggered, [this]()
|
||||
{
|
||||
if(this->currentDiagramView())
|
||||
{
|
||||
auto table = new QetGraphicsTableItem();
|
||||
|
||||
/*******ONLY FOR TEST DURING DEVEL*********/
|
||||
auto model = new NomenclatureModel(this->currentProject(), this->currentProject());
|
||||
QString query("SELECT ei.plant, ei.location, ei.label, ei.comment, ei.description, ei.manufacturer, e.pos, di.title, di.folio"
|
||||
" FROM element_info ei, element e, diagram_info di"
|
||||
" WHERE ei.element_uuid = e.uuid AND e.diagram_uuid = di.diagram_uuid"
|
||||
" ORDER BY ei.plant, ei.location, ei.label");
|
||||
model->query(query);
|
||||
model->autoHeaders();
|
||||
model->setData(model->index(0,0), Qt::AlignLeft, Qt::TextAlignmentRole);
|
||||
model->setData(model->index(0,0), QETApp::diagramTextsFont(), Qt::FontRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, Qt::AlignHCenter, Qt::TextAlignmentRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, QETApp::diagramTextsFont(), Qt::FontRole);
|
||||
table->setModel(model);
|
||||
/******************************************/
|
||||
|
||||
this->currentDiagramView()->diagram()->addItem(table);
|
||||
table->setPos(50,50);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -407,6 +428,11 @@ void QETDiagramEditor::setUpActions()
|
||||
}
|
||||
});
|
||||
|
||||
m_export_project_db = new QAction(QET::Icons::DocumentSpreadsheet, tr("Exporter la base de donnée interne du projet"), this);
|
||||
connect(m_export_project_db, &QAction::triggered, [this]() {
|
||||
projectDataBase::exportDb(this->currentProject()->dataBase(), this);
|
||||
});
|
||||
|
||||
//MDI view style
|
||||
m_tabbed_view_mode = new QAction(tr("en utilisant des onglets"), this);
|
||||
m_tabbed_view_mode->setStatusTip(tr("Présente les différents projets ouverts des onglets", "status bar tip"));
|
||||
@@ -751,6 +777,8 @@ void QETDiagramEditor::setUpMenu() {
|
||||
menu_project -> addAction(m_csv_export);
|
||||
menu_project -> addAction(m_project_export_conductor_num);
|
||||
menu_project -> addAction(m_project_terminalBloc);
|
||||
menu_project -> addSeparator();
|
||||
menu_project -> addAction(m_export_project_db);
|
||||
|
||||
main_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils principale"));
|
||||
view_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Affichage"));
|
||||
@@ -878,7 +906,10 @@ void QETDiagramEditor::saveAs() {
|
||||
bool QETDiagramEditor::newProject()
|
||||
{
|
||||
auto new_project = new QETProject(this);
|
||||
|
||||
// add new diagram
|
||||
new_project -> addNewDiagram();
|
||||
|
||||
return addProject(new_project);
|
||||
}
|
||||
|
||||
@@ -1904,8 +1935,7 @@ void QETDiagramEditor::activateProject(ProjectView *project_view) {
|
||||
activateWidget(project_view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETDiagramEditor::projectWasClosed
|
||||
/*** @brief QETDiagramEditor::projectWasClosed
|
||||
* Manage the close of a project.
|
||||
* @param project_view
|
||||
*/
|
||||
@@ -1919,7 +1949,6 @@ void QETDiagramEditor::projectWasClosed(ProjectView *project_view)
|
||||
undo_group.removeStack(project -> undoStack());
|
||||
QETApp::unregisterProject(project);
|
||||
}
|
||||
|
||||
//When project is closed, a lot of signal are emited, notably if there is an item selected in a diagram.
|
||||
//In some special case, since signal/slot connection can be direct or queued, some signal are handled after QObject is deleted, and crash qet
|
||||
//notably in the function Diagram::elements when she call items() (I don't know exactly why).
|
||||
@@ -2129,7 +2158,7 @@ void QETDiagramEditor::removeDiagramFromProject() {
|
||||
*/
|
||||
void QETDiagramEditor::diagramWasAdded(DiagramView *dv)
|
||||
{
|
||||
connect(dv->diagram(), &QGraphicsScene::selectionChanged, this, &QETDiagramEditor::selectionChanged, Qt::DirectConnection);
|
||||
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
|
||||
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
|
||||
}
|
||||
|
||||
@@ -2218,10 +2247,10 @@ void QETDiagramEditor::generateTerminalBlock()
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
if (openedProjects().count()){
|
||||
success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.8/bin/qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
|
||||
success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.5/bin/qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
|
||||
}
|
||||
else {
|
||||
success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.8/bin/qet_tb_generator");
|
||||
success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.5/bin/qet_tb_generator");
|
||||
}
|
||||
#else
|
||||
if (openedProjects().count()){
|
||||
@@ -2282,7 +2311,7 @@ void QETDiagramEditor::generateTerminalBlock()
|
||||
" First install on macOSX"
|
||||
"</B>""</U>"
|
||||
"<br>"
|
||||
"1. Install, if required, python 3.8 "
|
||||
"1. Install, if required, python 3.5 "
|
||||
"<br>"
|
||||
" Visit :"
|
||||
"<br>"
|
||||
|
||||
@@ -187,6 +187,7 @@ class QETDiagramEditor : public QETMainWindow
|
||||
QAction *m_add_nomenclature; ///< Add nomenclature graphics item;
|
||||
QAction *m_project_terminalBloc; ///< generate terminal block
|
||||
QAction *m_project_export_conductor_num; ///<Export the wire num to csv
|
||||
QAction *m_export_project_db; ///Export to file the internal database of the current project
|
||||
QAction *m_tile_window; ///< Show MDI subwindows as tile
|
||||
QAction *m_cascade_window; ///< Show MDI subwindows as cascade
|
||||
QAction *m_previous_window; ///< Switch to the previous document
|
||||
|
||||
229
sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp
Normal file
229
sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
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 "nomenclaturemodel.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetproject.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QFont>
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::NomenclatureModel
|
||||
* @param project :project of this nomenclature
|
||||
* @param parent : parent QObject
|
||||
*/
|
||||
NomenclatureModel::NomenclatureModel(QETProject *project, QObject *parent) :
|
||||
QAbstractTableModel(parent),
|
||||
m_project(project)
|
||||
{
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::rowCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int NomenclatureModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_record.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::columnCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int NomenclatureModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
if (m_record.count()) {
|
||||
return m_record.first().count();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::setHeaderData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* Only horizontal orientation is accepted.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool NomenclatureModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return false;
|
||||
}
|
||||
auto hash_ = m_header_data.value(section);
|
||||
hash_.insert(role, value);
|
||||
m_header_data.insert(section, hash_);
|
||||
headerDataChanged(orientation, section, section);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::headerData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant NomenclatureModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (m_header_data.contains(section))
|
||||
{
|
||||
auto hash_ = m_header_data.value(section);
|
||||
if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt
|
||||
return hash_.value(Qt::EditRole);
|
||||
}
|
||||
return m_header_data.value(section).value(role);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::setData
|
||||
* Only store the data for the index 0.0
|
||||
* @param index
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool NomenclatureModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() != 0 || index.column() != 0) {
|
||||
return false;
|
||||
}
|
||||
m_index_0_0_data.insert(role, value);
|
||||
emit dataChanged(index, index, QVector<int>(role));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::data
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param index
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant NomenclatureModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() == 0 &&
|
||||
index.column() == 0 &&
|
||||
role != Qt::DisplayRole) {
|
||||
return m_index_0_0_data.value(role);
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QVariant v(m_record.at(index.row()).at(index.column()));
|
||||
return v;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::query
|
||||
* Query the internall bd with @query.
|
||||
* @param query
|
||||
*/
|
||||
void NomenclatureModel::query(const QString &query)
|
||||
{
|
||||
auto rm_ = m_query != query;
|
||||
if (rm_) {
|
||||
emit beginResetModel();
|
||||
}
|
||||
|
||||
m_query = query;
|
||||
|
||||
if (m_project)
|
||||
{
|
||||
if (rm_) {
|
||||
disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
m_project->dataBase()->updateDB();
|
||||
if (rm_) {
|
||||
m_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
if (rm_) { emit endResetModel();}
|
||||
}
|
||||
|
||||
QETProject *NomenclatureModel::project() const {
|
||||
return m_project.data();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::autoHeaders
|
||||
* Try to determine the name of each columns header
|
||||
*/
|
||||
void NomenclatureModel::autoHeaders()
|
||||
{
|
||||
auto headers = projectDataBase::headersFromElementsInfoQuery(m_query);
|
||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
||||
this->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::dataBaseUpdated
|
||||
* slot called when the project database is updated
|
||||
*/
|
||||
void NomenclatureModel::dataBaseUpdated()
|
||||
{
|
||||
auto new_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
|
||||
|
||||
//This a very special case, if this nomenclature model is added
|
||||
//befor any element, column count return 0, so in this case we emit column inserted
|
||||
if (new_record.size() != m_record.size())
|
||||
{
|
||||
emit beginInsertColumns(index(0,0), 0, m_record.size()-1);
|
||||
m_record = new_record;
|
||||
emit endInsertColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_record = new_record;
|
||||
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));
|
||||
}
|
||||
}
|
||||
59
sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h
Normal file
59
sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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 NOMENCLATUREMODEL_H
|
||||
#define NOMENCLATUREMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QPointer>
|
||||
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The NomenclatureModel class
|
||||
* An element nomenclature Model.
|
||||
* This model represent a 2D data.
|
||||
*/
|
||||
class NomenclatureModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NomenclatureModel(QETProject *project, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void query(const QString &query);
|
||||
QETProject *project() const;
|
||||
void autoHeaders();
|
||||
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QString m_query;
|
||||
QVector<QStringList> m_record;
|
||||
QHash<int, QHash<int, QVariant>> m_header_data;
|
||||
QHash<int, QVariant> m_index_0_0_data;
|
||||
};
|
||||
|
||||
#endif // NOMENCLATUREMODEL_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2019 QElectroTech Team
|
||||
Copyright 2006-2020 QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
|
||||
static int no_model_height = 20;
|
||||
static int no_model_width = 40;
|
||||
/**
|
||||
* @brief QetGraphicsHeaderItem::QetGraphicsHeaderItem
|
||||
* @param parent
|
||||
@@ -42,13 +44,23 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
}
|
||||
|
||||
m_model = model;
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
|
||||
} else {
|
||||
setUpMinimumSectionsSize();
|
||||
}
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
@@ -93,7 +105,6 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->setBrush(brush);
|
||||
|
||||
painter->setPen(pen);
|
||||
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
painter->drawRect(m_current_rect);
|
||||
|
||||
if (!m_model)
|
||||
@@ -101,6 +112,7 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
@@ -142,6 +154,19 @@ QRect QetGraphicsHeaderItem::rect() const {
|
||||
*/
|
||||
void QetGraphicsHeaderItem::resizeSection(int logicalIndex, int size)
|
||||
{
|
||||
if (!m_model)
|
||||
{
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.append(no_model_width);
|
||||
m_sections_minimum_width.clear();
|
||||
m_sections_minimum_width.append(no_model_width);
|
||||
m_current_rect.setWidth(no_model_width);
|
||||
setUpBoundingRect();
|
||||
update();
|
||||
emit sectionResized(0, no_model_width);
|
||||
return;
|
||||
}
|
||||
|
||||
if (logicalIndex >= m_current_sections_width.size() ||
|
||||
m_current_sections_width.at(logicalIndex) == size) {
|
||||
return;
|
||||
@@ -191,7 +216,12 @@ void QetGraphicsHeaderItem::setMargins(const QMargins &margins)
|
||||
*/
|
||||
void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
|
||||
{
|
||||
if (!m_model) {
|
||||
if (!m_model)
|
||||
{
|
||||
m_minimum_section_height = no_model_height;
|
||||
m_sections_minimum_width.clear();
|
||||
m_sections_minimum_width.append(no_model_width);
|
||||
m_minimum_width = no_model_width;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -264,3 +294,11 @@ void QetGraphicsHeaderItem::adjustSize()
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void QetGraphicsHeaderItem::modelReseted()
|
||||
{
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
enum { Type = UserType + 1301 };
|
||||
int type() const override { return Type; }
|
||||
|
||||
void setModel(QAbstractItemModel *model);
|
||||
void setModel(QAbstractItemModel *model = nullptr);
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
@@ -68,6 +68,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
void setUpBoundingRect();
|
||||
void headerDataChanged(Qt::Orientations orientation, int first, int last);
|
||||
void adjustSize();
|
||||
void modelReseted();
|
||||
|
||||
private:
|
||||
QRectF m_bounding_rect;
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
static int no_model_height = 20;
|
||||
static int no_model_width = 40;
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::QetGraphicsTableItem
|
||||
* Default constructor
|
||||
@@ -52,31 +55,6 @@ QetGraphicsTableItem::QetGraphicsTableItem(QGraphicsItem *parent) :
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::heightResized, this, [this]() {
|
||||
m_header_item->setPos(0, 0-m_header_item->rect().height());
|
||||
});
|
||||
|
||||
/*******ONLY FOR TEST DURING DEVEL*********/
|
||||
auto model = new QStandardItemModel(this);
|
||||
int r = 20;
|
||||
int c = 5;
|
||||
|
||||
for (int row = 0; row < r; ++row)
|
||||
{
|
||||
for (int column = 0; column < c; ++column) {
|
||||
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
|
||||
model->setItem(row, column, item);
|
||||
}
|
||||
}
|
||||
model->setData(model->index(0,0), Qt::AlignLeft, Qt::TextAlignmentRole);
|
||||
model->setData(model->index(0,0), QETApp::diagramTextsFont(), Qt::FontRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, Qt::AlignHCenter, Qt::TextAlignmentRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, QETApp::diagramTextsFont(), Qt::FontRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, "Label");
|
||||
model->setHeaderData(1, Qt::Horizontal, "Folio");
|
||||
model->setHeaderData(2, Qt::Horizontal, "Fonction");
|
||||
model->setHeaderData(3, Qt::Horizontal, "Fabricant");
|
||||
model->setHeaderData(4, Qt::Horizontal, "Installation");
|
||||
this->setModel(model);
|
||||
this->setPos(50,50);
|
||||
/******************************************/
|
||||
}
|
||||
|
||||
QetGraphicsTableItem::~QetGraphicsTableItem()
|
||||
@@ -91,8 +69,10 @@ QetGraphicsTableItem::~QetGraphicsTableItem()
|
||||
*/
|
||||
void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
if (m_model)
|
||||
{
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
m_model = model;
|
||||
m_header_item->setModel(model);
|
||||
@@ -101,7 +81,11 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
adjustSize();
|
||||
|
||||
m_header_item->setPos(0, -m_header_item->rect().height());
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +123,25 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
pen.setWidthF(0.7);
|
||||
pen.setColor(Qt::black);
|
||||
painter->setPen(pen);
|
||||
painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value<QFont>());
|
||||
|
||||
painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height());
|
||||
|
||||
if (isSelected())
|
||||
{
|
||||
painter->save();
|
||||
QColor color(Qt::darkBlue);
|
||||
color.setAlpha(20);
|
||||
painter->setBrush(QBrush (color));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height());
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
if(!m_model)
|
||||
{
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
@@ -159,9 +153,18 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
|
||||
//Calcule the number of rows to display.
|
||||
auto row_count = m_model->rowCount();
|
||||
|
||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||
row_count -= m_previous_table->displayNRowOffset();
|
||||
|
||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
//Draw horizontal lines
|
||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(m_model->rowCount());
|
||||
for(auto i= 1 ; i-1<m_model->rowCount() ; ++i)
|
||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||
for(auto i= 1 ; i-1<row_count ; ++i)
|
||||
{
|
||||
QPointF p1(m_header_item->rect().left(), cell_height*i);
|
||||
QPointF p2(m_header_item->rect().right(), cell_height*i);
|
||||
@@ -169,7 +172,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
for (auto i= 0 ; i<m_model->rowCount() ; ++i)
|
||||
for (auto i=0 ; i<row_count ; ++i)
|
||||
{
|
||||
QPointF top_left(m_margin.left(), i==0? m_margin.top() : cell_height*i + m_margin.top());
|
||||
|
||||
@@ -181,9 +184,10 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
}
|
||||
QSize size(m_header_item->sectionSize(j) - m_margin.left() - m_margin.right(),
|
||||
static_cast<int>(cell_height) - m_margin.top() - m_margin.bottom());
|
||||
auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i;
|
||||
painter->drawText(QRectF(top_left, size),
|
||||
m_model->data(m_model->index(0,0), Qt::TextAlignmentRole).toInt(),
|
||||
m_model->index(i, j).data().toString());
|
||||
m_model->index(index_row, j).data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,10 +244,155 @@ QSize QetGraphicsTableItem::size() const
|
||||
*/
|
||||
QSize QetGraphicsTableItem::minimumSize() const
|
||||
{
|
||||
QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*m_model->rowCount());
|
||||
if (!m_model) {
|
||||
return QSize(no_model_width, no_model_height);
|
||||
}
|
||||
|
||||
auto row_count = m_model->rowCount();
|
||||
if (m_previous_table) {
|
||||
row_count -= m_previous_table->displayNRowOffset();
|
||||
}
|
||||
|
||||
if (m_number_of_displayed_row > 0)
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
|
||||
|
||||
QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*row_count);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setDisplayNRow
|
||||
* Limit the number of row to display
|
||||
* @param number : set to 0 or less to disabled the limit of row to display
|
||||
*/
|
||||
void QetGraphicsTableItem::setDisplayNRow(const int &number) {
|
||||
m_number_of_displayed_row = number;
|
||||
setToMinimumHeight();
|
||||
if (m_next_table)
|
||||
m_next_table->previousTableDisplayRowChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::displayNRow
|
||||
* @return the number of row displayed.
|
||||
* A value of 0 or less mean there is no limit
|
||||
*/
|
||||
int QetGraphicsTableItem::displayNRow() const {
|
||||
return m_number_of_displayed_row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setPreviousTable
|
||||
* Set the previous table to @table.
|
||||
* If this table already have a previous table, the previous table will be replaced.
|
||||
* Set new table to nullptr to remove an existing previous table.
|
||||
* The table uses the model of the new previous table.
|
||||
* Since the table does not take ownership of the model, it is your responsibility to manage the old model.
|
||||
* Linked tables (table with next and/or previous table) share the same model, a table always take the model of the previous table..
|
||||
* When remove a previous table (set to nullptr) from a table, the model is also removed, you need to set a new model
|
||||
* @param table
|
||||
*/
|
||||
void QetGraphicsTableItem::setPreviousTable(QetGraphicsTableItem *table)
|
||||
{
|
||||
if (m_previous_table == table) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto old_previous_table = m_previous_table;
|
||||
m_previous_table = table;
|
||||
if (m_previous_table) //set previous table and get her model
|
||||
{
|
||||
m_previous_table->setNextTable(this);
|
||||
setModel(m_previous_table->m_model);
|
||||
}
|
||||
else //Remove model
|
||||
{
|
||||
setModel(nullptr);
|
||||
}
|
||||
|
||||
if (old_previous_table &&
|
||||
old_previous_table->nextTable() == this) {
|
||||
old_previous_table->setNextTable(nullptr);
|
||||
}
|
||||
|
||||
//Set the m_model to every next table
|
||||
auto next_ = m_next_table;
|
||||
while (next_) {
|
||||
next_->setModel(m_model);
|
||||
next_ = next_->nextTable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setNextTable
|
||||
* Set the next table to @table
|
||||
* nullptr will remove an existing next table.
|
||||
* @param table
|
||||
*/
|
||||
void QetGraphicsTableItem::setNextTable(QetGraphicsTableItem *table)
|
||||
{
|
||||
if (m_next_table == table) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto old_next_table = m_next_table;
|
||||
|
||||
m_next_table = table;
|
||||
if (m_next_table) {
|
||||
m_next_table->setPreviousTable(this);
|
||||
}
|
||||
|
||||
if (old_next_table &&
|
||||
old_next_table->previousTable() == this) {
|
||||
old_next_table->setPreviousTable(nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::setTableName(const QString &name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString QetGraphicsTableItem::tableName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::displayNRowOffset
|
||||
* @return the offset (aka the last displayed row) of displayed row.
|
||||
* If this item have a previous table, the previous offset is added.
|
||||
*/
|
||||
int QetGraphicsTableItem::displayNRowOffset() const
|
||||
{
|
||||
auto offset_ = m_number_of_displayed_row;
|
||||
if(m_previous_table)
|
||||
offset_ += m_previous_table->displayNRowOffset();
|
||||
|
||||
return offset_;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const {
|
||||
return m_previous_table;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const {
|
||||
return m_next_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setToMinimumHeight
|
||||
* Set the height to the the minimum.
|
||||
* The width stay unchanged.
|
||||
*/
|
||||
void QetGraphicsTableItem::setToMinimumHeight()
|
||||
{
|
||||
auto size_ = size();
|
||||
size_.setHeight(1);
|
||||
setSize(size_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::hoverEnterEvent
|
||||
* Reimplemented from QetGraphicsItem
|
||||
@@ -251,9 +400,12 @@ QSize QetGraphicsTableItem::minimumSize() const
|
||||
*/
|
||||
void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (m_model)
|
||||
{
|
||||
adjustHandlerPos();
|
||||
this->scene()->addItem(&m_handler_item);
|
||||
m_handler_item.installSceneEventFilter(this);
|
||||
}
|
||||
QGraphicsObject::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
@@ -264,7 +416,9 @@ void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
*/
|
||||
void QetGraphicsTableItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (m_model) {
|
||||
m_handler_item.scene()->removeItem(&m_handler_item);
|
||||
}
|
||||
QGraphicsObject::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
@@ -299,6 +453,11 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
|
||||
return false;
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::modelReseted() {
|
||||
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
||||
setToMinimumHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize
|
||||
* Calcule the minimum row height and the minimum column width for each columns
|
||||
@@ -306,7 +465,10 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
|
||||
*/
|
||||
void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
|
||||
{
|
||||
if (!m_model) {
|
||||
if (!m_model)
|
||||
{
|
||||
m_minimum_row_height = no_model_height;
|
||||
m_minimum_column_width = m_header_item->minimumSectionWidth();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -358,6 +520,8 @@ void QetGraphicsTableItem::setUpHandler()
|
||||
void QetGraphicsTableItem::handlerMousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
diagram()->clearSelection();
|
||||
this->setSelected(true);
|
||||
m_old_size = size();
|
||||
//User start to resize the table, disconnect the signal to avoid double paint.
|
||||
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
@@ -398,11 +562,21 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *ev
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
{
|
||||
if (!m_model)
|
||||
{
|
||||
auto h_ = m_header_item->minimumSectionWidth();
|
||||
for (auto i=0 ; i<h_.size() ; ++i) {
|
||||
m_header_item->resizeSection(i, h_.at(i));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto a = m_current_size.width() - minimumSize().width();
|
||||
auto b = a/m_model->columnCount();
|
||||
auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0
|
||||
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i) {
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(i), m_header_item->minimumSectionWidth().at(i)) + b);
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(std::min(m_minimum_column_width.size()-1, i)),
|
||||
m_header_item->minimumSectionWidth().at(std::min(m_header_item->minimumSectionWidth().size()-1, i))) + b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +614,12 @@ void QetGraphicsTableItem::headerSectionResized()
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustSize()
|
||||
{
|
||||
//If there is no model, set the size to minimum
|
||||
if (!m_model) {
|
||||
setSize(minimumSize());
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_current_size.height() < minimumSize().height())
|
||||
{
|
||||
prepareGeometryChange();
|
||||
@@ -457,3 +637,10 @@ void QetGraphicsTableItem::adjustSize()
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::previousTableDisplayRowChanged() {
|
||||
setToMinimumHeight();
|
||||
if (m_next_table) {
|
||||
m_next_table->previousTableDisplayRowChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2020 QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -35,6 +35,8 @@ class QetGraphicsHeaderItem;
|
||||
* Text font.
|
||||
* Text alignment in the cell
|
||||
* These two last parameters are not settable directly with the table but trough the model to be displayed by the table.
|
||||
* The table search for font and alignment only in the index(0,0) for all the table.
|
||||
* By consequence, set data in other index than 0,0 is useless also the alignment and font can't be set individually for each cell.
|
||||
*/
|
||||
class QetGraphicsTableItem : public QetGraphicsItem
|
||||
{
|
||||
@@ -42,6 +44,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
|
||||
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
|
||||
Q_PROPERTY(QSize size READ size WRITE setSize)
|
||||
Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow)
|
||||
|
||||
public:
|
||||
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
||||
@@ -50,7 +53,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
enum { Type = UserType + 1300 };
|
||||
int type() const override { return Type; }
|
||||
|
||||
void setModel(QAbstractItemModel *model);
|
||||
void setModel(QAbstractItemModel *model = nullptr);
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
@@ -61,6 +64,16 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
void setSize(const QSize &size);
|
||||
QSize size() const;
|
||||
QSize minimumSize() const;
|
||||
void setDisplayNRow(const int &number);
|
||||
int displayNRow() const;
|
||||
void setPreviousTable(QetGraphicsTableItem *table = nullptr);
|
||||
void setNextTable(QetGraphicsTableItem *table = nullptr);
|
||||
void setTableName(const QString &name);
|
||||
QString tableName() const;
|
||||
int displayNRowOffset() const;
|
||||
QetGraphicsTableItem *previousTable() const;
|
||||
QetGraphicsTableItem *nextTable() const;
|
||||
void setToMinimumHeight();
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
@@ -80,6 +93,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
void headerSectionResized();
|
||||
void adjustSize();
|
||||
void previousTableDisplayRowChanged();
|
||||
|
||||
private:
|
||||
QAbstractItemModel *m_model= nullptr;
|
||||
@@ -87,6 +101,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
QMargins m_margin;
|
||||
QVector<int> m_minimum_column_width;
|
||||
int m_minimum_row_height;
|
||||
int m_number_of_displayed_row = 0;
|
||||
QSize m_current_size,
|
||||
m_old_size;
|
||||
|
||||
@@ -95,6 +110,11 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
|
||||
QetGraphicsHandlerItem m_handler_item;
|
||||
QetGraphicsHeaderItem *m_header_item = nullptr;
|
||||
|
||||
QetGraphicsTableItem *m_previous_table = nullptr,
|
||||
*m_next_table = nullptr;
|
||||
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
#endif // QetGraphicsTableItem_H
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "diagram.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "itemmodelcommand.h"
|
||||
#include "propertieseditorfactory.h"
|
||||
#include "elementprovider.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QFontDialog>
|
||||
@@ -69,6 +71,12 @@ 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_current_model_editor = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
m_table_item = table;
|
||||
@@ -76,6 +84,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();
|
||||
}
|
||||
|
||||
@@ -117,6 +131,12 @@ QUndoCommand *GraphicsTablePropertiesEditor::associatedUndo() const
|
||||
return undo;
|
||||
}
|
||||
|
||||
if (ui->m_display_n_row_sb->value() != m_table_item->displayNRow()) {
|
||||
auto undo = new QPropertyUndoCommand(m_table_item.data(), "displayNRow", m_table_item->displayNRow(), ui->m_display_n_row_sb->value());
|
||||
undo->setText(tr("Modifier le nombre de ligne affiché par un tableau"));
|
||||
return undo;
|
||||
}
|
||||
|
||||
QMargins header_margins(ui->m_header_left_margin->value(),
|
||||
ui->m_header_top_margin->value(),
|
||||
ui->m_header_right_margin->value(),
|
||||
@@ -229,8 +249,33 @@ void GraphicsTablePropertiesEditor::updateUi()
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
|
||||
ui->m_table_name_le->setText(m_table_item->tableName());
|
||||
ui->m_x_pos->setValue(m_table_item->pos().x());
|
||||
ui->m_y_pos->setValue(m_table_item->pos().y());
|
||||
ui->m_display_n_row_sb->setValue(m_table_item->displayNRow());
|
||||
|
||||
ui->m_previous_table_cb->clear();
|
||||
m_other_table_vector.clear();
|
||||
|
||||
ui->m_previous_table_cb->addItem(tr("Aucun")); //Add no previous table
|
||||
|
||||
if (auto item_ = m_table_item->previousTable()) //Add the current previous table
|
||||
{
|
||||
m_other_table_vector.append(item_);
|
||||
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
|
||||
ui->m_previous_table_cb->setCurrentIndex(ui->m_previous_table_cb->findData(m_other_table_vector.indexOf(item_)));
|
||||
}
|
||||
|
||||
ElementProvider ep(m_table_item->diagram()->project());
|
||||
for (auto item_ : ep.table(m_table_item, m_table_item->model())) //Add available tables
|
||||
{
|
||||
if (item_ != m_table_item &&
|
||||
item_->nextTable() == nullptr)
|
||||
{
|
||||
m_other_table_vector.append(item_);
|
||||
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
|
||||
}
|
||||
}
|
||||
|
||||
auto margin = m_table_item->headerItem()->margins();
|
||||
ui->m_header_top_margin ->setValue(margin.top());
|
||||
@@ -249,8 +294,10 @@ void GraphicsTablePropertiesEditor::updateUi()
|
||||
return;
|
||||
}
|
||||
|
||||
m_header_button_group->button(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt())->setChecked(true);
|
||||
m_table_button_group->button(m_table_item->model()->data(m_table_item->model()->index(0,0), Qt::TextAlignmentRole).toInt())->setChecked(true);
|
||||
if (auto button = m_header_button_group->button(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt()))
|
||||
button->setChecked(true);
|
||||
if (auto button = m_table_button_group->button(m_table_item->model()->data(m_table_item->model()->index(0,0), Qt::TextAlignmentRole).toInt()))
|
||||
button->setChecked(true);
|
||||
|
||||
setUpEditConnection();
|
||||
}
|
||||
@@ -280,5 +327,19 @@ void GraphicsTablePropertiesEditor::setUpEditConnection()
|
||||
m_edit_connection << connect(ui->m_table_bottom_margin, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply);
|
||||
m_edit_connection << connect(m_table_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply);
|
||||
m_edit_connection << connect(m_header_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply);
|
||||
m_edit_connection << connect(ui->m_display_n_row_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsTablePropertiesEditor::on_m_table_name_le_textEdited(const QString &arg1) {
|
||||
m_table_item->setTableName(arg1);
|
||||
}
|
||||
|
||||
void GraphicsTablePropertiesEditor::on_m_previous_table_cb_activated(int index)
|
||||
{
|
||||
if (index == 0) {
|
||||
m_table_item->setPreviousTable();
|
||||
} else {
|
||||
m_table_item->setPreviousTable(m_other_table_vector.at(ui->m_previous_table_cb->currentData().toInt()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -51,6 +51,8 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
|
||||
void on_m_header_font_pb_clicked();
|
||||
void on_m_table_font_pb_clicked();
|
||||
virtual void updateUi() override;
|
||||
void on_m_table_name_le_textEdited(const QString &arg1);
|
||||
void on_m_previous_table_cb_activated(int index);
|
||||
|
||||
private:
|
||||
void setUpEditConnection();
|
||||
@@ -62,6 +64,8 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
|
||||
m_edit_connection;
|
||||
QButtonGroup *m_header_button_group = nullptr,
|
||||
*m_table_button_group = nullptr;
|
||||
QWidget *m_current_model_editor = nullptr;
|
||||
QVector<QetGraphicsTableItem *> m_other_table_vector;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins)
|
||||
|
||||
@@ -6,38 +6,73 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>331</width>
|
||||
<height>484</height>
|
||||
<width>467</width>
|
||||
<height>672</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="m_tab">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_display_tab">
|
||||
<attribute name="title">
|
||||
<string>Affichage</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_table_name_le">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Nom du tableau</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Position</string>
|
||||
<string>Position et lignes</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="4" colspan="2">
|
||||
<widget class="QComboBox" name="m_previous_table_cb">
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::InsertAtBottom</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>X :</string>
|
||||
<string>Aucun</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6" colspan="2">
|
||||
<widget class="QSpinBox" name="m_display_n_row_sb">
|
||||
<property name="specialValueText">
|
||||
<string>Toutes</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Lignes à afficher :</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>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Y :</string>
|
||||
@@ -47,13 +82,124 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="7">
|
||||
<widget class="QPushButton" name="m_next_pb">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Tableau suivant</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<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 row="0" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="6">
|
||||
<widget class="QPushButton" name="m_previous_cb">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Tableau précédent</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QSpinBox" name="m_x_pos">
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="7">
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QSpinBox" name="m_y_pos">
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="8">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2" colspan="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Tableau précédent :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -65,7 +211,33 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="4">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="m_header_left_margin">
|
||||
<property name="suffix">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QSpinBox" name="m_header_top_margin"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Marge</string>
|
||||
@@ -75,17 +247,24 @@
|
||||
</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">
|
||||
<item row="2" column="3">
|
||||
<widget class="QSpinBox" name="m_header_right_margin"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="m_header_top_margin"/>
|
||||
<item row="3" column="2">
|
||||
<widget class="QSpinBox" name="m_header_bottom_margin"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@@ -104,6 +283,19 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
@@ -132,6 +324,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -140,6 +345,9 @@
|
||||
<property name="text">
|
||||
<string>Police</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -153,19 +361,32 @@
|
||||
<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">
|
||||
<item row="2" column="2">
|
||||
<widget class="QSpinBox" name="m_table_bottom_margin"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="m_table_left_margin"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="0" column="2">
|
||||
<widget class="QSpinBox" name="m_table_top_margin"/>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QSpinBox" name="m_table_right_margin"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Marge</string>
|
||||
@@ -175,6 +396,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@@ -192,6 +426,19 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_9">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
@@ -220,6 +467,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -228,6 +488,9 @@
|
||||
<property name="text">
|
||||
<string>Police</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -248,6 +511,32 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../../qelectrotech.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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"
|
||||
#include "qetproject.h"
|
||||
#include "elementquerywidget.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget
|
||||
* @param model
|
||||
* @param parent
|
||||
*/
|
||||
NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget(NomenclatureModel *model, QWidget *parent) :
|
||||
PropertiesEditorWidget(parent),
|
||||
ui(new Ui::NomenclatureModelPropertiesWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget
|
||||
*/
|
||||
NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::setModel
|
||||
* @param model
|
||||
*/
|
||||
void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) {
|
||||
m_model = model;
|
||||
ui->m_edit_query_pb->setEnabled(m_model);
|
||||
ui->m_refresh_pb->setEnabled(m_model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked
|
||||
*/
|
||||
void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
{
|
||||
QDialog d(this);
|
||||
auto l = new QVBoxLayout(this);
|
||||
d.setLayout(l);
|
||||
|
||||
auto query_widget = new ElementQueryWidget(&d);
|
||||
l->addWidget(query_widget);
|
||||
|
||||
auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
l->addWidget(button_box);
|
||||
connect(button_box, &QDialogButtonBox::accepted, &d, &QDialog::accept);
|
||||
connect(button_box, &QDialogButtonBox::rejected, &d, &QDialog::reject);
|
||||
|
||||
if (d.exec())
|
||||
{
|
||||
m_model->query(query_widget->queryStr());
|
||||
auto headers = query_widget->header();
|
||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
||||
m_model->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
if (m_model && m_model->project()) {
|
||||
m_model->project()->dataBase()->updateDB();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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>92</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>Requête</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>
|
||||
@@ -45,7 +45,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)
|
||||
{
|
||||
setDefaultTitleBlockProperties(TitleBlockProperties::defaultProperties());
|
||||
|
||||
@@ -61,7 +62,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);
|
||||
@@ -79,7 +81,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
|
||||
@@ -113,6 +116,22 @@ 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
|
||||
*/
|
||||
QUuid QETProject::uuid() const {
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETProject::init
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "titleblockproperties.h"
|
||||
#include "templatescollection.h"
|
||||
#include "properties/xrefproperties.h"
|
||||
#include "projectdatabase.h"
|
||||
#include "reportproperties.h"
|
||||
|
||||
class Diagram;
|
||||
@@ -72,6 +73,8 @@ class QETProject : public QObject
|
||||
|
||||
// methods
|
||||
public:
|
||||
projectDataBase *dataBase();
|
||||
QUuid uuid() const;
|
||||
ProjectState state() const;
|
||||
QList<Diagram *> diagrams() const;
|
||||
int getFolioSheetsQuantity() const; /// get the folio sheets quantity for this project
|
||||
@@ -267,6 +270,8 @@ class QETProject : public QObject
|
||||
QTimer m_save_backup_timer,
|
||||
m_autosave_timer;
|
||||
KAutoSaveFile *m_backup_file = nullptr;
|
||||
QUuid m_uuid = QUuid::createUuid();
|
||||
projectDataBase m_data_base;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QETProject *)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <QtXml>
|
||||
#include "diagramcontext.h"
|
||||
#include "qet.h"
|
||||
|
||||
/**
|
||||
This class provides a container for the properties of a particular title
|
||||
block, i.e. title, author, date, filename, folio, template, custom
|
||||
@@ -60,7 +61,6 @@ class TitleBlockProperties {
|
||||
QString version; ///< Version (displayed by the default template)
|
||||
QString folio; ///< Folio information (displayed by the default template)
|
||||
QString auto_page_num;
|
||||
QString location;
|
||||
DateManagement useDate; ///< Wheter to use the date attribute
|
||||
QString template_name; ///< Name of the template used to render the title block - an empty string means "the default template provided by the application"
|
||||
DiagramContext context; ///< Container for the additional, user-defined fields
|
||||
|
||||
@@ -60,7 +60,6 @@ class BOMExportDialog : public QDialog
|
||||
QString headers() const;
|
||||
bool createDataBase();
|
||||
void populateDataBase();
|
||||
void prepareQuery(QStringList keys);
|
||||
QHash<QString, QString> elementInfoToString(Element *elmt) const;
|
||||
QString queryStr() const;
|
||||
void updateQueryLine();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -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;
|
||||
if (!m_diagram) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QList<QGraphicsItem *> list_ = m_diagram->selectedItems();
|
||||
int type_ = list_.first()->type();
|
||||
for (QGraphicsItem *qgi : list_)
|
||||
{
|
||||
if (qgi->type() != type_)
|
||||
{
|
||||
auto editor_ = PropertiesEditorFactory::propertiesEditor(m_diagram->selectedItems(), editors().count()? editors().first() : nullptr, this);
|
||||
if (!editor_) {
|
||||
clear();
|
||||
m_edited_qgi_type = -1;
|
||||
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;
|
||||
if (editors().count() &&
|
||||
editors().first() != editor_) {
|
||||
clear();
|
||||
}
|
||||
|
||||
addEditor(editor_);
|
||||
for (PropertiesEditorWidget *pew : editors()) {
|
||||
pew->setLiveEdit(true);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "changeelementinformationcommand.h"
|
||||
#include "element.h"
|
||||
#include "diagram.h"
|
||||
#include <QObject>
|
||||
|
||||
/**
|
||||
@@ -49,6 +50,7 @@ bool ChangeElementInformationCommand::mergeWith(const QUndoCommand *other)
|
||||
*/
|
||||
void ChangeElementInformationCommand::undo() {
|
||||
m_element -> setElementInformations(m_old_info);
|
||||
updateProjectDB();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,4 +58,12 @@ void ChangeElementInformationCommand::undo() {
|
||||
*/
|
||||
void ChangeElementInformationCommand::redo() {
|
||||
m_element -> setElementInformations(m_new_info);
|
||||
updateProjectDB();
|
||||
}
|
||||
|
||||
void ChangeElementInformationCommand::updateProjectDB()
|
||||
{
|
||||
if(m_element->diagram()) {
|
||||
m_element->diagram()->project()->dataBase()->updateDB();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ class ChangeElementInformationCommand : public QUndoCommand
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
void updateProjectDB();
|
||||
|
||||
private:
|
||||
Element *m_element;
|
||||
DiagramContext m_old_info,
|
||||
|
||||
Reference in New Issue
Block a user