Compare commits

..

29 Commits

Author SHA1 Message Date
Simon De Backer
698db4e5c0 Add Copyright to machine_info class 2020-07-22 21:16:38 +02:00
Simon De Backer
6b95c6bf6f Add QScrollArea to configdialog and resize to max_screen 2020-07-22 21:03:54 +02:00
Simon De Backer
03425bcb5b Add gui resize depending on screen size
Init of request
https://qelectrotech.org/bugtracker/view.php?id=195
This is a start will have to be adjusted further.
2020-07-21 20:29:05 +02:00
Laurent Trinques
3a08e60856 aboutqetdialog.cpp minor 2020-07-21 16:01:28 +02:00
Laurent Trinques
e03e36fb2c AboutQETDialog add Linux RAM Total and MemAvailable 2020-07-21 15:58:35 +02:00
Laurent Trinques
8f5e759528 AboutQETDialog add Linux RAM 2020-07-21 14:45:41 +02:00
Laurent Trinques
bddf10588f AboutQETDialog add macOS cpuinfo 'model name' 2020-07-21 14:12:06 +02:00
Laurent Trinques
a33ae2bb13 AboutQETDialog add Linux gpu info 'model name' 2020-07-21 13:44:45 +02:00
Laurent Trinques
bd93e62341 AboutQETDialog add Linux cpuinfo 'model name' 2020-07-21 13:05:08 +02:00
Simon De Backer
119e12b1cf Add Screen info user 2020-07-20 22:41:27 +02:00
Claveau Joshua
f242e1bccc graphics table properties editor : minor
Add label to inform users that the number of row is less than the number
of information to display.
2020-07-20 20:29:13 +02:00
Claveau Joshua
709280e3c1 QetGraphicsTableItem : add dialog to inform user
When user edit the query of an existing table/s if the content to
display is bigger than the content who can be displayed by the table/s a
dialog is opened for inform user of the current situation.
2020-07-20 19:38:52 +02:00
Simon De Backer
3b14946421 Add compiler message @TODO + Mod doc set style de same 2020-07-19 22:19:21 +02:00
Simon De Backer
280e4605e8 Mod doc set style de same 2020-07-19 22:08:41 +02:00
Simon De Backer
fe4552200b Add compiler message @TODO 2020-07-19 22:06:42 +02:00
Simon De Backer
d3b237d06c Mod documentation + wrap code for better readability 2020-07-19 20:28:56 +02:00
Simon De Backer
26fd1a497c Add ignore lines to .gitignore
if doxygen Doxyfile is run all file's of folder doc are added
Qt user file should not see either
2020-07-19 20:24:37 +02:00
Simon De Backer
bbd3085b8d Fix indentation code + Mod doc 2020-07-19 20:06:22 +02:00
Simon De Backer
1251d7d9b0 Fix indentation code + Mod doc 2020-07-19 20:05:58 +02:00
Simon De Backer
2229a1938d Add documentation 2020-07-19 20:05:13 +02:00
Simon De Backer
ffcdccb469 Mod doc set style de same 2020-07-19 18:40:41 +02:00
Simon De Backer
5df6d7f403 Wrap code for better readability 2020-07-19 18:40:41 +02:00
Simon De Backer
4cd69a2450 Mod doc set style de same 2020-07-19 18:40:41 +02:00
Simon De Backer
102629b86f Mod doc set style de same + wrap code for better readability 2020-07-19 18:40:41 +02:00
Simon De Backer
7ddae811a5 Fix Wdeprecated-declarations QProcess::startDetached
QProcess::startDetached(const QString&)’ is deprecated
Use
QProcess::startDetached(const QString &program,
			const QStringList &arguments)
instead
2020-07-19 18:30:28 +02:00
Simon De Backer
cecacfc769 Fix compiler warining non-virtual destructor
ref:
https://stackoverflow.com/questions/38407723/how-to-delete-an-object-of-derived-class-that-has-no-dstructor
2020-07-19 15:48:46 +02:00
Simon De Backer
8c9b30acd6 Mod doc + Update Copyright date
And wrap code for better readability
2020-07-16 22:06:56 +02:00
Simon De Backer
6aa6d055ec Add translation for directory 2020-07-16 22:01:04 +02:00
Simon De Backer
495d9a5f51 Add documentation + wrap code for better readability 2020-07-16 22:00:33 +02:00
103 changed files with 2579 additions and 2478 deletions

5
.gitignore vendored
View File

@@ -1,2 +1,7 @@
*.snap *.snap
.flatpak-builder .flatpak-builder
# Qt build output
*.user
# doxygen Doxyfile output
doc/
QElectroTech.tag

View File

@@ -27,6 +27,7 @@
#include <QtCore/QSharedMemory> #include <QtCore/QSharedMemory>
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) // ### Qt 6: remove
#else #else
#pragma message("@TODO remove code for QT 5.10 or later")
#include <QRandomGenerator> #include <QRandomGenerator>
#endif #endif
#include "singleapplication.h" #include "singleapplication.h"
@@ -106,6 +107,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() ); qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() );
QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ) ); QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ) );
#else #else
#pragma message("@TODO remove code for QT 5.10 or later")
quint32 value = QRandomGenerator::global()->generate(); quint32 value = QRandomGenerator::global()->generate();
QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( value ) / RAND_MAX * 10 ) ); QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( value ) / RAND_MAX * 10 ) );
#endif #endif

View File

@@ -3,5 +3,7 @@
<name lang="fr">11- Schémas et plans d'installation, architecturaux et topographiques</name> <name lang="fr">11- Schémas et plans d'installation, architecturaux et topographiques</name>
<name lang="es">11- Dibujos y planos arquitectónicos y topográficos</name> <name lang="es">11- Dibujos y planos arquitectónicos y topográficos</name>
<name lang="da">11- Bygningsmæssige og topografiske installationstegninger og -skemaer</name> <name lang="da">11- Bygningsmæssige og topografiske installationstegninger og -skemaer</name>
<name lang="en">11- Installation, architectural and topographical diagrams and plans</name>
<name lang="be">11- Installatie, bouwkundig en topografische schema's en plannen</name>
</names> </names>
</qet-directory> </qet-directory>

View File

@@ -641,6 +641,7 @@ void ElementsCollectionWidget::search()
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList text_list = text.split("+", QString::SkipEmptyParts); QStringList text_list = text.split("+", QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
QStringList text_list = text.split("+", Qt::SkipEmptyParts); QStringList text_list = text.split("+", Qt::SkipEmptyParts);
#endif #endif
QModelIndexList match_index; QModelIndexList match_index;

View File

@@ -754,6 +754,7 @@ QDebug operator<< (QDebug debug, const ElementsLocation &location)
QDebugStateSaver saver(debug); QDebugStateSaver saver(debug);
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
#pragma message("@TODO remove code for QT 5.04 or later")
debug.noquote(); debug.noquote();
#else #else
debug.nospace(); debug.nospace();

View File

@@ -183,14 +183,13 @@ QString FileElementCollectionItem::name() const
*/ */
QString FileElementCollectionItem::collectionPath() const QString FileElementCollectionItem::collectionPath() const
{ {
QStandardItem* parent_ = parent();
if (isCollectionRoot()) { if (isCollectionRoot()) {
if (m_path == QETApp::commonElementsDirN()) if (m_path == QETApp::commonElementsDirN())
return "common://"; return "common://";
else else
return "custom://"; return "custom://";
} }
else if (parent_ && parent()->type() == FileElementCollectionItem::Type) { else if (parent() && parent()->type() == FileElementCollectionItem::Type) {
ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(parent()); ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(parent());
if (eci->isCollectionRoot()) if (eci->isCollectionRoot())
return eci->collectionPath() + m_path; return eci->collectionPath() + m_path;

View File

@@ -46,7 +46,7 @@ class QetGraphicsHandlerItem : public QGraphicsItem
QRectF m_handler_rect, QRectF m_handler_rect,
m_br; m_br;
qreal m_size; qreal m_size;
QColor m_color{Qt::black}; QColor m_color;
QPen m_pen; QPen m_pen;
public: public:

View File

@@ -27,12 +27,20 @@
- 17 columns of 60.0 px wide by 20.0px high - 17 columns of 60.0 px wide by 20.0px high
- 8 lines of 80.0 px high by 20.0px wide - 8 lines of 80.0 px high by 20.0px wide
Initialise un objet BorderProperties avec les proprietes par \~French Initialise un objet BorderProperties avec les proprietes par
defaut suivantes : defaut suivantes :
- 17 colonnes affichees de 60.0 px de large pour 20.0px de haut - 17 colonnes affichees de 60.0 px de large pour 20.0px de haut
- 8 lignes affichees de 80.0 px de haut pour 20.0px de large - 8 lignes affichees de 80.0 px de haut pour 20.0px de large
*/ */
BorderProperties::BorderProperties() BorderProperties::BorderProperties() :
columns_count(17),
columns_width(60.0),
columns_header_height(20.0),
display_columns(true),
rows_count(8),
rows_height(80.0),
rows_header_width(20.0),
display_rows(true)
{ {
} }
@@ -45,12 +53,11 @@ BorderProperties::~BorderProperties() {
/** /**
@brief BorderProperties::operator == @brief BorderProperties::operator ==
@param bp :
- other BorderProperties container/class \~ @param bp : Other BorderProperties container/class.
- autre conteneur BorderProperties \~French Autre conteneur BorderProperties
@return \~ @return True if it and this container are identical, false otherwise.
- true if it and this container are identical, false otherwise \~French True si ip et ce conteneur sont identiques, false sinon
- true si ip et ce conteneur sont identiques, false sinon
*/ */
bool BorderProperties::operator==(const BorderProperties &bp) { bool BorderProperties::operator==(const BorderProperties &bp) {
return( return(
@@ -67,12 +74,13 @@ bool BorderProperties::operator==(const BorderProperties &bp) {
/** /**
@brief BorderProperties::operator != @brief BorderProperties::operator !=
@param bp :
- other BorderProperties container/class \~ @param bp :
- autre conteneur BorderProperties Other BorderProperties container/class.
@return \~French Autre conteneur BorderProperties
- false if it and this container are identical, true otherwise \~ @return
- false si bp et ce conteneur sont identiques, true sinon False if it and this container are identical, true otherwise.
\~French False si bp et ce conteneur sont identiques, true sinon
*/ */
bool BorderProperties::operator!=(const BorderProperties &bp) { bool BorderProperties::operator!=(const BorderProperties &bp) {
return(!(*this == bp)); return(!(*this == bp));
@@ -80,69 +88,51 @@ bool BorderProperties::operator!=(const BorderProperties &bp) {
/** /**
@brief BorderProperties::toXml @brief BorderProperties::toXml
- Exports dimensions as XML attributes added to element e. Exports dimensions as XML attributes added to element e.
- Exporte les dimensions sous formes d'attributs XML ajoutes a l'element e. \~French Exporte les dimensions sous formes d'attributs XML ajoutes a l'element e.
@param e :
- XML element to which attributes will be added \~ @param e :
- Element XML auquel seront ajoutes des attributs XML element to which attributes will be added
\~French Element XML auquel seront ajoutes des attributs
*/ */
QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const { void BorderProperties::toXml(QDomElement &e) const {
e.setAttribute("cols", columns_count);
QDomElement e = dom_doc.createElement("border"); e.setAttribute("colsize", QString("%1").arg(columns_width));
e.setAttribute("rows", rows_count);
e.appendChild(createXmlProperty(dom_doc, "cols", columns_count)); e.setAttribute("rowsize", QString("%1").arg(rows_height));
e.appendChild(createXmlProperty(dom_doc, "colsize", columns_width)); e.setAttribute("displaycols", display_columns ? "true" : "false");
e.appendChild(createXmlProperty(dom_doc, "rows", rows_count)); e.setAttribute("displayrows", display_rows ? "true" : "false");
e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height));
e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows));
e.appendChild(createXmlProperty(dom_doc, "displaycols", display_columns));
return e;
} }
/**RETURNS True /**
@brief BorderProperties::fromXml @brief BorderProperties::fromXml
- Import dimensions from XML attributes of element e Import dimensions from XML attributes of element e
- Importe les dimensions a partir des attributs XML de l'element e \~French Importe les dimensions a partir des attributs XML de l'element e
@param e :
- XML element whose attributes will be read \~ @param e :
- Element XML dont les attributs seront lus XML element whose attributes will be read
\~French Element XML dont les attributs seront lus
*/ */
bool BorderProperties::fromXml(const QDomElement &e) { void BorderProperties::fromXml(QDomElement &e) {
if (e.hasAttribute("cols")) columns_count = e.attribute("cols").toInt();
if (propertyInteger(e, "cols", &columns_count) == PropertyFlags::NoValidConversion || if (e.hasAttribute("colsize")) columns_width = e.attribute("colsize").toInt();
propertyDouble(e, "colsize", &columns_width) == PropertyFlags::NoValidConversion || if (e.hasAttribute("rows")) rows_count = e.attribute("rows").toInt();
propertyInteger(e, "rows", &rows_count) == PropertyFlags::NoValidConversion || if (e.hasAttribute("rowsize")) rows_height = e.attribute("rowsize").toInt();
propertyDouble(e, "rowsize", &rows_height) == PropertyFlags::NoValidConversion || if (e.hasAttribute("displaycols")) display_columns = e.attribute("displaycols") == "true";
propertyBool(e, "displaycols", &display_columns) == PropertyFlags::NoValidConversion || if (e.hasAttribute("displayrows")) display_rows = e.attribute("displayrows") == "true";
propertyBool(e, "displayrows", &display_rows) == PropertyFlags::NoValidConversion)
return false;
return true;
}
bool BorderProperties::valideXml(QDomElement& e) {
if (propertyInteger(e, "cols") == PropertyFlags::Success ||
propertyDouble(e, "colsize") == PropertyFlags::Success ||
propertyInteger(e, "rows") == PropertyFlags::Success ||
propertyDouble(e, "rowsize") == PropertyFlags::Success ||
propertyBool(e, "displaycols") == PropertyFlags::Success ||
propertyBool(e, "displayrows") == PropertyFlags::Success)
return true;
return false;
} }
/** /**
@brief BorderProperties::toSettings @brief BorderProperties::toSettings
- Export dimensions in a QSettings object. Export dimensions in a QSettings object.
- Exporte les dimensions dans une configuration. \~French Exporte les dimensions dans une configuration.
@param settings :
- QSettings object to write \~ @param settings :
- Parametres a ecrire QSettings object to write
@param prefix : \~French Parametres a ecrire
- prefix to be added before the names of the parameters \~ @param prefix :
- prefixe a ajouter devant les noms des parametres prefix to be added before the names of the parameters
\~French prefixe a ajouter devant les noms des parametres
*/ */
void BorderProperties::toSettings(QSettings &settings, const QString &prefix) const { void BorderProperties::toSettings(QSettings &settings, const QString &prefix) const {
settings.setValue(prefix + "cols", columns_count); settings.setValue(prefix + "cols", columns_count);
@@ -155,16 +145,14 @@ void BorderProperties::toSettings(QSettings &settings, const QString &prefix) co
/** /**
@brief BorderProperties::fromSettings @brief BorderProperties::fromSettings
- Import dimensions from a QSettings object. Import dimensions from a QSettings object.
- Importe les dimensions depuis une configuration. \~French Importe les dimensions depuis une configuration.
@param settings : \~ @param settings : QSettings object to read
- QSettings object to read \~French Parametres a lire
- Parametres a lire \~ @param prefix : prefix to be added before the names of the parameters
@param prefix : \~French prefixe a ajouter devant les noms des parametres
- prefix to be added before the names of the parameters
- prefixe a ajouter devant les noms des parametres
*/ */
void BorderProperties::fromSettings(const QSettings &settings, const QString &prefix) { void BorderProperties::fromSettings(QSettings &settings, const QString &prefix) {
columns_count = settings.value(prefix + "cols", columns_count).toInt(); columns_count = settings.value(prefix + "cols", columns_count).toInt();
columns_width = qRound(settings.value(prefix + "colsize", columns_width).toDouble()); columns_width = qRound(settings.value(prefix + "colsize", columns_width).toDouble());
display_columns = settings.value(prefix + "displaycols", display_columns).toBool(); display_columns = settings.value(prefix + "displaycols", display_columns).toBool();

View File

@@ -20,15 +20,13 @@
#include <QtCore> #include <QtCore>
#include <QtXml> #include <QtXml>
#include "propertiesinterface.h"
/** /**
@brief The BorderProperties class @brief The BorderProperties class
This class is a container for dimensions and display properties of a This class is a container for dimensions and display properties of a
diagram. diagram.
@remark Attributes are public @remark Attributes are public
*/ */
class BorderProperties : public PropertiesInterface { class BorderProperties {
public: public:
// constructor, destructor, operators // constructor, destructor, operators
BorderProperties(); BorderProperties();
@@ -37,23 +35,22 @@ class BorderProperties : public PropertiesInterface {
bool operator==(const BorderProperties &); bool operator==(const BorderProperties &);
bool operator!=(const BorderProperties &); bool operator!=(const BorderProperties &);
QDomElement toXml(QDomDocument &dom_doc) const override; void toXml(QDomElement &) const;
bool fromXml(const QDomElement &) override; void fromXml(QDomElement &);
static bool valideXml(QDomElement& e); void toSettings(QSettings &, const QString & = QString()) const;
void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString());
void fromSettings(const QSettings &, const QString & = QString()) override;
static BorderProperties defaultProperties(); static BorderProperties defaultProperties();
// attributes // attributes
int columns_count{17}; ///< Columns count int columns_count; ///< Columns count
qreal columns_width{60.0}; ///< Columns width qreal columns_width; ///< Columns width
qreal columns_header_height{20.0}; ///< Column headers height qreal columns_header_height; ///< Column headers height
bool display_columns{true}; ///< Whether to display column headers bool display_columns; ///< Whether to display column headers
int rows_count{8}; ///< Rows count int rows_count; ///< Rows count
qreal rows_height{80.0}; ///< Rows height qreal rows_height; ///< Rows height
qreal rows_header_width{20.0}; ///< Row headers width qreal rows_header_width; ///< Row headers width
bool display_rows{true}; ///< Whether to display row headers bool display_rows; ///< Whether to display row headers
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,7 @@ class DiagramPosition;
class TitleBlockTemplate; class TitleBlockTemplate;
class TitleBlockTemplateRenderer; class TitleBlockTemplateRenderer;
/** /**
@brief The BorderTitleBlock class
This class represents the border and the titleblock which frame a This class represents the border and the titleblock which frame a
particular electric diagram. particular electric diagram.
*/ */
@@ -50,30 +51,43 @@ class BorderTitleBlock : public QObject
//METHODS TO GET DIMENSION //METHODS TO GET DIMENSION
//COLUMNS //COLUMNS
/// @return the number of columns /// @return the number of columns
int columnsCount() const { return(columns_count_); } int columnsCount() const { return(columns_count_); }
/// @return the columns width, in pixels /// @return the columns width, in pixels
qreal columnsWidth() const { return(columns_width_); } qreal columnsWidth() const { return(columns_width_); }
/// @return the total width of all columns, headers excluded /// @return the total width of all columns, headers excluded
qreal columnsTotalWidth() const { return(columns_count_ * columns_width_); } qreal columnsTotalWidth() const {
/// @return the column headers height, in pixels return(columns_count_ * columns_width_); }
qreal columnsHeaderHeight() const { return(columns_header_height_); } /// @return the column headers height, in pixels
qreal columnsHeaderHeight() const {
return(columns_header_height_); }
//ROWS //ROWS
/// @return the number of rows /// @return the number of rows
int rowsCount() const { return(rows_count_); } int rowsCount() const { return(rows_count_); }
/// @return the rows height, in pixels /// @return the rows height, in pixels
qreal rowsHeight() const { return(rows_height_); } qreal rowsHeight() const { return(rows_height_); }
/// @return the total height of all rows, headers excluded /// @return the total height of all rows, headers excluded
qreal rowsTotalHeight() const { return(rows_count_ * rows_height_); } qreal rowsTotalHeight() const {
/// @return la rows header width, in pixels return(rows_count_ * rows_height_); }
/// @return la rows header width, in pixels
qreal rowsHeaderWidth() const { return(rows_header_width_); } qreal rowsHeaderWidth() const { return(rows_header_width_); }
// border - title block = diagram // border - title block = diagram
/// @return the diagram width, i.e. the width of the border without title block /**
qreal diagramWidth() const { return(columnsTotalWidth() + rowsHeaderWidth()); } @brief diagramWidth
/// @return the diagram height, i.e. the height of the border without title block @return the diagram width,
qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); } i.e. the width of the border without title block
*/
qreal diagramWidth() const {
return(columnsTotalWidth() + rowsHeaderWidth()); }
/**
@brief diagramHeight
@return the diagram height,
i.e. the height of the border without title block
*/
qreal diagramHeight() const {
return(rowsTotalHeight() + columnsHeaderHeight()); }
QRectF titleBlockRect () const; QRectF titleBlockRect () const;
@@ -88,45 +102,49 @@ class BorderTitleBlock : public QObject
QRectF outsideBorderRect() const; QRectF outsideBorderRect() const;
QRectF insideBorderRect() const; QRectF insideBorderRect() const;
// methods to get title block basic data // methods to get title block basic data
/// @return the value of the title block "Author" field /// @return the value of the title block "Author" field
QString author() const { return(btb_author_); } QString author() const { return(btb_author_); }
/// @return the value of the title block "Date" field /// @return the value of the title block "Date" field
QDate date() const { return(btb_date_); } QDate date() const { return(btb_date_); }
/// @return the value of the title block "Title" field /// @return the value of the title block "Title" field
QString title() const { return(btb_title_); } QString title() const { return(btb_title_); }
/// @return the value of the title block "Folio" field /// @return the value of the title block "Folio" field
QString folio() const { return(btb_folio_); } QString folio() const { return(btb_folio_); }
/// @return the value of the title block "Folio" field as displayed /// @return the value of the title block "Folio" field as displayed
QString finalfolio() const { return(btb_final_folio_); } QString finalfolio() const { return(btb_final_folio_); }
/// @return the value of the title block "Plant" field /// @return the value of the title block "Plant" field
QString plant() const { return(btb_plant_); } QString plant() const { return(btb_plant_); }
/// @return the value of the title block "Locmach" field /// @return the value of the title block "Locmach" field
QString locmach() const { return(btb_locmach_); } QString locmach() const { return(btb_locmach_); }
/// @return the value of the revision index block "Folio" field /// @return the value of the revision index block "Folio" field
QString indexrev() const { return(btb_indexrev_); } QString indexrev() const { return(btb_indexrev_); }
/// @return the value of the title block "File" field /// @return the value of the title block "File" field
QString fileName() const { return(btb_filename_); } QString fileName() const { return(btb_filename_); }
/// @return the value of the title block Additional Fields /// @return the value of the title block Additional Fields
QString version() const { return(btb_version_); } QString version() const { return(btb_version_); }
/// @return the value of the title block Additional Fields /// @return the value of the title block Additional Fields
DiagramContext additionalFields() const { return (additional_fields_); } DiagramContext additionalFields() const {
/// @return the value of the title block return (additional_fields_); }
/// @return the value of the title block
QString autoPageNum() const { return(btb_auto_page_num_); } QString autoPageNum() const { return(btb_auto_page_num_); }
/// @return the value of the total number of folios /// @return the value of the total number of folios
int folioTotal() const { return(folio_total_);} int folioTotal() const { return(folio_total_);}
// methods to get display options // methods to get display options
/// @return true si le cartouche est affiche, false sinon /// @return true si le cartouche est affiche, false sinon
bool titleBlockIsDisplayed() const { return(display_titleblock_); } bool titleBlockIsDisplayed() const {
/// @return true si les entetes des colonnes sont affiches, false sinon return(display_titleblock_); }
/// @return true si les entetes des colonnes sont affiches,
/// false sinon
bool columnsAreDisplayed() const { return(display_columns_); } bool columnsAreDisplayed() const { return(display_columns_); }
/// @return true si les entetes des lignes sont affiches, false sinon /// @return true si les entetes des lignes sont affiches,
/// false sinon
bool rowsAreDisplayed() const { return(display_rows_); } bool rowsAreDisplayed() const { return(display_rows_); }
/// @return true si la bordure est affichee, false sinon /// @return true si la bordure est affichee, false sinon
bool borderIsDisplayed() const { return(display_border_); } bool borderIsDisplayed() const { return(display_border_); }
// methods to set dimensions // methods to set dimensions
void setColumnsCount(int); void setColumnsCount(int);
void setRowsCount(int); void setRowsCount(int);
void setColumnsWidth(const qreal &); void setColumnsWidth(const qreal &);
@@ -137,12 +155,13 @@ class BorderTitleBlock : public QObject
DiagramPosition convertPosition(const QPointF &); DiagramPosition convertPosition(const QPointF &);
// methods to set title block basic data // methods to set title block basic data
void setAuthor(const QString &author); void setAuthor(const QString &author);
void setDate(const QDate &date); void setDate(const QDate &date);
void setTitle(const QString &title); void setTitle(const QString &title);
void setFolio(const QString &folio); void setFolio(const QString &folio);
void setFolioData(int, int, const QString& = nullptr, const DiagramContext & = DiagramContext()); void setFolioData(int, int, const QString& = nullptr,
const DiagramContext & = DiagramContext());
void setPlant(const QString &plant); void setPlant(const QString &plant);
void setLocMach(const QString &locmach); void setLocMach(const QString &locmach);
void setIndicerev(const QString &indexrev); void setIndicerev(const QString &indexrev);
@@ -152,7 +171,7 @@ class BorderTitleBlock : public QObject
void setPreviousFolioNum(const QString &previous); void setPreviousFolioNum(const QString &previous);
void setNextFolioNum(const QString &next); void setNextFolioNum(const QString &next);
void titleBlockToXml(QDomElement &doc); void titleBlockToXml(QDomElement &);
void titleBlockFromXml(const QDomElement &); void titleBlockFromXml(const QDomElement &);
void borderToXml(QDomElement &); void borderToXml(QDomElement &);
void borderFromXml(const QDomElement &); void borderFromXml(const QDomElement &);
@@ -168,9 +187,11 @@ class BorderTitleBlock : public QObject
public slots: public slots:
void titleBlockTemplateChanged(const QString &); void titleBlockTemplateChanged(const QString &);
void titleBlockTemplateRemoved(const QString &, const TitleBlockTemplate * = nullptr); void titleBlockTemplateRemoved(
const QString &,
const TitleBlockTemplate * = nullptr);
// methods to set display options // methods to set display options
void displayTitleBlock(bool); void displayTitleBlock(bool);
void displayColumns(bool); void displayColumns(bool);
void displayRows(bool); void displayRows(bool);
@@ -179,77 +200,86 @@ class BorderTitleBlock : public QObject
private: private:
void updateRectangles(); void updateRectangles();
void updateDiagramContextForTitleBlock(const DiagramContext & = DiagramContext()); void updateDiagramContextForTitleBlock(
const DiagramContext & = DiagramContext());
QString incrementLetters(const QString &); QString incrementLetters(const QString &);
signals: signals:
/** /**
Signal emitted after the border has changed @brief borderChanged
@param old_border Former border Signal emitted after the border has changed
@param new_border New border @param old_border Former border
*/ @param new_border New border
*/
void borderChanged(QRectF old_border, QRectF new_border); void borderChanged(QRectF old_border, QRectF new_border);
/** /**
Signal emitted after display options have changed @brief displayChanged
*/ Signal emitted after display options have changed
*/
void displayChanged(); void displayChanged();
/** /**
Signal emitted after the title has changed @brief diagramTitleChanged
*/ Signal emitted after the title has changed
*/
void diagramTitleChanged(const QString &); void diagramTitleChanged(const QString &);
/** /**
@brief titleBlockFolioChanged @brief titleBlockFolioChanged
Signal emitted after Folio has changed Signal emitted after Folio has changed
*/ */
void titleBlockFolioChanged(const QString &); void titleBlockFolioChanged(const QString &);
/** /**
Signal emitted when the title block requires its data to be updated in order @brief needFolioData
to generate the folio field. Signal emitted when the title block
*/ requires its data to be updated
in order to generate the folio field.
*/
void needFolioData(); void needFolioData();
/** /**
Signal emitted when this object needs to set a specific title block @brief needTitleBlockTemplate
template. This object cannot handle the job since it does not know of Signal emitted when this object needs to
its parent project. set a specific title block template.
*/ This object cannot handle the job
since it does not know of its parent project.
*/
void needTitleBlockTemplate(const QString &); void needTitleBlockTemplate(const QString &);
// attributes // attributes
private: private:
// titleblock basic data // titleblock basic data
QString btb_author_; QString btb_author_; ///< titleblock author
QDate btb_date_; QDate btb_date_; ///< titleblock date
QString btb_title_; QString btb_title_; ///< titleblock title
QString btb_folio_; QString btb_folio_; ///< titleblock folio
QString btb_plant_; QString btb_plant_; ///< titleblock plant
QString btb_locmach_; QString btb_locmach_; ///< titleblock locmach
QString btb_indexrev_; QString btb_indexrev_; ///< titleblock index rev
QString btb_final_folio_; QString btb_final_folio_; ///< titleblock final folio
QString btb_auto_page_num_; QString btb_auto_page_num_; ///< titleblock auto page num
int folio_index_; int folio_index_; ///< titleblock index
int folio_total_; int folio_total_; ///< titleblock total
QString btb_filename_; QString btb_filename_; ///< titleblock filename
QString btb_version_; QString btb_version_; ///< titleblock version
/// titleblock additional fields
DiagramContext additional_fields_; DiagramContext additional_fields_;
Qt::Edge m_edge; Qt::Edge m_edge; ///< titleblock edge
QString m_next_folio_num, QString m_next_folio_num; ///< titleblock next folio num
m_previous_folio_num; QString m_previous_folio_num; ///< titleblock previous folio num
// border dimensions (rows and columns) // border dimensions (rows and columns)
// columns: number and dimensions // columns: number and dimensions
int columns_count_; int columns_count_; ///< columns count
qreal columns_width_; qreal columns_width_; ///< columns width
qreal columns_header_height_; qreal columns_header_height_; ///< columns header height
// rows: number and dimensions // rows: number and dimensions
int rows_count_; int rows_count_; ///< rows count
qreal rows_height_; qreal rows_height_; ///< rows height
qreal rows_header_width_; qreal rows_header_width_; ///< rows header width
// title block dimensions // title block dimensions
qreal titleblock_height_; qreal titleblock_height_;
// rectangles used for drawing operations // rectangles used for drawing operations
QRectF diagram_rect_; QRectF diagram_rect_;
// display options // display options

View File

@@ -1,5 +1,5 @@
/* /*
Copyright 2006-2014 The QElectroTech team Copyright 2006-2020 The QElectroTech team
This file is part of QElectroTech. This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify QElectroTech is free software: you can redistribute it and/or modify
@@ -26,16 +26,23 @@
#include "assignvariables.h" #include "assignvariables.h"
/** /**
* @brief ConductorAutoNumerotation::ConductorAutoNumerotation @brief ConductorAutoNumerotation::ConductorAutoNumerotation
* Constructor of autonum, after create a class, call numerate to apply the autonum. Constructor of autonum, after create a class,
* When autonum is applyed, they do with an undo command added to the stack of diagram. call numerate to apply the autonum.
* If you give a parent_undo at constructor, the undo command create in this class have parent_undo for parent, When autonum is applyed,
* and wasn't added to the stack of diagram (it's the responsabillty of the parent_undo) they do with an undo command added to the stack of diagram.
* @param conductor : the conductor to apply automatic numerotation If you give a parent_undo at constructor,
* @param diagram : the diagram of conductor the undo command create in this class have parent_undo for parent,
* @param parent_undo : parent undo command and wasn't added to the stack of diagram
*/ (it's the responsabillty of the parent_undo)
ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *conductor, Diagram *diagram, QUndoCommand *parent_undo) : @param conductor : the conductor to apply automatic numerotation
@param diagram : the diagram of conductor
@param parent_undo : parent undo command
*/
ConductorAutoNumerotation::ConductorAutoNumerotation(
Conductor *conductor,
Diagram *diagram,
QUndoCommand *parent_undo) :
m_diagram (diagram), m_diagram (diagram),
m_conductor (conductor), m_conductor (conductor),
conductor_list (conductor -> relatedPotentialConductors().values()), conductor_list (conductor -> relatedPotentialConductors().values()),
@@ -43,19 +50,22 @@ ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *conductor, Diagr
{} {}
/** /**
* @brief ConductorAutoNumerotation::numerate @brief ConductorAutoNumerotation::numerate
* execute the automatic numerotation execute the automatic numerotation
*/ */
void ConductorAutoNumerotation::numerate() { void ConductorAutoNumerotation::numerate() {
if (!m_conductor) return; if (!m_conductor) return;
if (conductor_list.size() >= 1 ) numeratePotential(); if (conductor_list.size() >= 1 ) numeratePotential();
else if (m_conductor -> properties().type == ConductorProperties::Multi) numerateNewConductor(); else if (m_conductor -> properties().type == ConductorProperties::Multi)
numerateNewConductor();
} }
/** /**
* @brief ConductorAutoNumerotation::applyText @brief ConductorAutoNumerotation::applyText
* apply the text @t to @conductor_ and all conductors at the same potential apply the text @t to @conductor_
*/ and all conductors at the same potential
@param t : Conductor text
*/
void ConductorAutoNumerotation::applyText(const QString& t) void ConductorAutoNumerotation::applyText(const QString& t)
{ {
if (!m_conductor) return; if (!m_conductor) return;
@@ -70,20 +80,36 @@ void ConductorAutoNumerotation::applyText(const QString& t)
if (m_parent_undo) if (m_parent_undo)
{ {
new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, m_parent_undo); new QPropertyUndoCommand(
m_conductor,
"properties",
old_value,
new_value,
m_parent_undo);
undo = m_parent_undo; undo = m_parent_undo;
} }
else else
{ {
undo = new QUndoCommand(); undo = new QUndoCommand();
new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, undo); new QPropertyUndoCommand(
undo->setText(QObject::tr("Modifier les propriétés d'un conducteur", "undo caption")); m_conductor,
"properties",
old_value,
new_value,
undo);
undo->setText(
QObject::tr(
"Modifier les propriétés d'un conducteur",
"undo caption"));
} }
if (!conductor_list.isEmpty()) if (!conductor_list.isEmpty())
{ {
if (!m_parent_undo) if (!m_parent_undo)
undo->setText(QObject::tr("Modifier les propriétés de plusieurs conducteurs", "undo caption")); undo->setText(
QObject::tr(
"Modifier les propriétés de plusieurs conducteurs",
"undo caption"));
foreach (Conductor *cond, conductor_list) foreach (Conductor *cond, conductor_list)
{ {
@@ -91,7 +117,12 @@ void ConductorAutoNumerotation::applyText(const QString& t)
old_value.setValue(cp2); old_value.setValue(cp2);
cp2.text = t; cp2.text = t;
new_value.setValue(cp2); new_value.setValue(cp2);
new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo); new QPropertyUndoCommand(
cond,
"properties",
old_value,
new_value,
undo);
} }
} }
@@ -100,15 +131,19 @@ void ConductorAutoNumerotation::applyText(const QString& t)
} }
/** /**
* @brief ConductorAutoNumerotation::newProperties @brief ConductorAutoNumerotation::newProperties
* Create a new properties according to the current autonum rule of diagram Create a new properties according to the current autonum rule of diagram
* @param d @param diagram : Diagram class
* @param cp @param cp : ConductorProperties
* @param seq @param seq : sequentialNumbers
*/ */
void ConductorAutoNumerotation::newProperties(Diagram *diagram, ConductorProperties &cp, autonum::sequentialNumbers &seq) void ConductorAutoNumerotation::newProperties(
Diagram *diagram,
ConductorProperties &cp,
autonum::sequentialNumbers &seq)
{ {
NumerotationContext context = diagram->project()->conductorAutoNum(diagram->conductorsAutonumName()); NumerotationContext context = diagram->project()->conductorAutoNum(
diagram->conductorsAutonumName());
if (context.isEmpty()) { if (context.isEmpty()) {
return; return;
} }
@@ -124,9 +159,9 @@ void ConductorAutoNumerotation::newProperties(Diagram *diagram, ConductorPropert
} }
/** /**
* @brief ConductorAutoNumerotation::numeratePotential @brief ConductorAutoNumerotation::numeratePotential
* Numerate a conductor on an existing potential Numerate a conductor on an existing potential
*/ */
void ConductorAutoNumerotation::numeratePotential() void ConductorAutoNumerotation::numeratePotential()
{ {
ConductorProperties cp = conductor_list.first()->properties(); ConductorProperties cp = conductor_list.first()->properties();
@@ -136,7 +171,8 @@ void ConductorAutoNumerotation::numeratePotential()
if (conductor->properties() != cp) if (conductor->properties() != cp)
properties_equal = false; properties_equal = false;
} }
//Every properties of the potential is equal, so we apply it to m_conductor // Every properties of the potential is equal,
// so we apply it to m_conductor
if (properties_equal) if (properties_equal)
{ {
m_conductor->setProperties(cp); m_conductor->setProperties(cp);
@@ -169,21 +205,25 @@ void ConductorAutoNumerotation::numeratePotential()
//the texts isn't identicals //the texts isn't identicals
else else
{ {
PotentialSelectorDialog psd(m_conductor, m_parent_undo, m_conductor->diagramEditor()); PotentialSelectorDialog psd(
m_conductor,
m_parent_undo,
m_conductor->diagramEditor());
psd.exec(); psd.exec();
} }
} }
/** /**
* @brief ConductorAutoNumerotation::numerateNewConductor @brief ConductorAutoNumerotation::numerateNewConductor
* create and apply a new numerotation to @m_conductor create and apply a new numerotation to @m_conductor
*/ */
void ConductorAutoNumerotation::numerateNewConductor() void ConductorAutoNumerotation::numerateNewConductor()
{ {
if (!m_conductor || m_diagram->conductorsAutonumName().isEmpty()) if (!m_conductor || m_diagram->conductorsAutonumName().isEmpty())
return; return;
NumerotationContext context = m_diagram->project()->conductorAutoNum(m_diagram -> conductorsAutonumName()); NumerotationContext context = m_diagram->project()->conductorAutoNum(
m_diagram -> conductorsAutonumName());
if (context.isEmpty()) if (context.isEmpty())
return; return;
@@ -194,10 +234,17 @@ void ConductorAutoNumerotation::numerateNewConductor()
cp.m_formula = formula; cp.m_formula = formula;
m_conductor->setProperties(cp); m_conductor->setProperties(cp);
autonum::setSequential(formula, m_conductor->rSequenceNum(), context, m_diagram, autoNum_name); autonum::setSequential(formula,
m_conductor->rSequenceNum(),
context,
m_diagram,
autoNum_name);
NumerotationContextCommands ncc (context, m_diagram); NumerotationContextCommands ncc (context, m_diagram);
m_diagram->project()->addConductorAutoNum(autoNum_name, ncc.next()); m_diagram->project()->addConductorAutoNum(autoNum_name, ncc.next());
applyText(autonum::AssignVariables::formulaToLabel(formula, m_conductor->rSequenceNum(), m_diagram)); applyText(autonum::AssignVariables::formulaToLabel(
formula,
m_conductor->rSequenceNum(),
m_diagram));
} }

View File

@@ -1,5 +1,5 @@
/* /*
Copyright 2006-2014 The QElectroTech team Copyright 2006-2020 The QElectroTech team
This file is part of QElectroTech. This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify QElectroTech is free software: you can redistribute it and/or modify
@@ -26,19 +26,26 @@ class Conductor;
class QUndoCommand; class QUndoCommand;
class ConductorProperties; class ConductorProperties;
/**
@brief The ConductorAutoNumerotation class
*/
class ConductorAutoNumerotation class ConductorAutoNumerotation
{ {
public: public:
//constructors & destructor //constructors & destructor
ConductorAutoNumerotation (Conductor *conductor, Diagram *diagram, QUndoCommand *undo_parent = nullptr); ConductorAutoNumerotation (Conductor *conductor,
Diagram *diagram,
QUndoCommand *undo_parent = nullptr);
//methods //methods
void numerate (); void numerate ();
void applyText (const QString&); void applyText (const QString&);
static void newProperties(Diagram *diagram, ConductorProperties &cp, autonum::sequentialNumbers &seq); static void newProperties(Diagram *diagram,
ConductorProperties &cp,
autonum::sequentialNumbers &seq);
private: private:
//methods //methods
void numeratePotential (); void numeratePotential ();
void numerateNewConductor (); void numerateNewConductor ();

View File

@@ -70,6 +70,7 @@ bool ConductorNumExport::toCsv()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
stream << wiresNum() << endl; stream << wiresNum() << endl;
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
stream << wiresNum() << &Qt::endl(stream); stream << wiresNum() << &Qt::endl(stream);
#endif #endif
} }

View File

@@ -22,7 +22,11 @@
/** /**
Constructeur par defaut Constructeur par defaut
*/ */
SingleLineProperties::SingleLineProperties() SingleLineProperties::SingleLineProperties() :
hasGround(true),
hasNeutral(true),
is_pen(false),
phases(1)
{ {
} }
@@ -192,17 +196,11 @@ void SingleLineProperties::drawPen(QPainter *painter, QET::ConductorSegmentType
ajoutes a l'element e. ajoutes a l'element e.
@param e Element XML auquel seront ajoutes des attributs @param e Element XML auquel seront ajoutes des attributs
*/ */
QDomElement SingleLineProperties::toXml(QDomDocument &doc) const { void SingleLineProperties::toXml(QDomElement &e) const {
e.setAttribute("ground", hasGround ? "true" : "false");
QDomElement e = doc.createElement("SingleLine"); e.setAttribute("neutral", hasNeutral ? "true" : "false");
e.appendChild(createXmlProperty(doc, "ground", hasGround)); e.setAttribute("phase", phases);
e.appendChild(createXmlProperty(doc, "neutral", hasNeutral)); if (isPen()) e.setAttribute("pen", "true");
e.appendChild(createXmlProperty(doc, "phase", phases));
if (isPen())
e.appendChild(createXmlProperty(doc, "pen", true));
return e;
} }
/** /**
@@ -210,36 +208,11 @@ QDomElement SingleLineProperties::toXml(QDomDocument &doc) const {
de l'element e de l'element e
@param e Element XML dont les attributs seront lus @param e Element XML dont les attributs seront lus
*/ */
bool SingleLineProperties::fromXml(const QDomElement &e) { void SingleLineProperties::fromXml(QDomElement &e) {
if (propertyBool(e, "ground", &hasGround) != PropertyFlags::Success || hasGround = e.attribute("ground") == "true";
propertyBool(e, "neutral", &hasNeutral) != PropertyFlags::Success) hasNeutral = e.attribute("neutral") == "true";
return false; setPhasesCount(e.attribute("phase").toInt());
is_pen = (hasGround && hasNeutral && e.attribute("pen", "false") == "true");
int phase;
if (propertyInteger(e, "phase", &phase) != PropertyFlags::Success)
return false;
setPhasesCount(phase);
bool pen;
if (propertyBool(e, "pen", &pen) != PropertyFlags::Success)
return false;
is_pen = (hasGround && hasNeutral && pen);
return true;
}
bool SingleLineProperties::valideXml(QDomElement& e) {
if (propertyBool(e, "ground") != PropertyFlags::Success ||
propertyBool(e, "neutral") != PropertyFlags::Success)
return false;
if (propertyInteger(e, "phase") != PropertyFlags::Success)
return false;
if (propertyBool(e, "pen") != PropertyFlags::Success)
return false;
return true;
} }
/** /**
@@ -272,134 +245,110 @@ ConductorProperties::~ConductorProperties() {
* Export conductor propertie, in the XML element 'e' * Export conductor propertie, in the XML element 'e'
* @param e the xml element * @param e the xml element
*/ */
QDomElement ConductorProperties::toXml(QDomDocument& doc) const void ConductorProperties::toXml(QDomElement &e) const
{ {
e.setAttribute("type", typeToString(type));
QDomElement e = doc.createElement("defaultconductor"); if (color != QColor(Qt::black))
e.setAttribute("color", color.name());
e.appendChild(createXmlProperty(doc, "type", typeToString(type)));
e.appendChild(createXmlProperty(doc, "color", color)); e.setAttribute("bicolor", m_bicolor? "true" : "false");
e.setAttribute("color2", m_color_2.name());
e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor)); e.setAttribute("dash-size", QString::number(m_dash_size));
e.appendChild(createXmlProperty(doc, "color2", m_color_2));
e.appendChild(createXmlProperty(doc, "dash-size", m_dash_size));
if (type == Single) if (type == Single)
e.appendChild(singleLineProperties.toXml(doc)); singleLineProperties.toXml(e);
e.appendChild(createXmlProperty(doc, "num", text)); e.setAttribute("num", text);
e.appendChild(createXmlProperty(doc, "text_color", text_color)); e.setAttribute("text_color", text_color.name());
e.appendChild(createXmlProperty(doc, "formula", m_formula)); e.setAttribute("formula", m_formula);
e.appendChild(createXmlProperty(doc, "function", m_function)); e.setAttribute("function", m_function);
e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol)); e.setAttribute("tension_protocol", m_tension_protocol);
e.appendChild(createXmlProperty(doc, "conductor_color", m_wire_color)); e.setAttribute("conductor_color", m_wire_color);
e.appendChild(createXmlProperty(doc, "conductor_section", m_wire_section)); e.setAttribute("conductor_section", m_wire_section);
e.appendChild(createXmlProperty(doc, "numsize", text_size)); e.setAttribute("numsize", QString::number(text_size));
e.appendChild(createXmlProperty(doc, "condsize", cond_size)); e.setAttribute("condsize", QString::number(cond_size));
e.appendChild(createXmlProperty(doc, "displaytext", m_show_text)); e.setAttribute("displaytext", m_show_text);
e.appendChild(createXmlProperty(doc, "onetextperfolio", m_one_text_per_folio)); e.setAttribute("onetextperfolio", m_one_text_per_folio);
e.appendChild(createXmlProperty(doc, "onetextperfolio", verti_rotate_text)); e.setAttribute("vertirotatetext", QString::number(verti_rotate_text));
e.appendChild(createXmlProperty(doc, "horizrotatetext", horiz_rotate_text)); e.setAttribute("horizrotatetext", QString::number(horiz_rotate_text));
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>(); QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
e.appendChild(createXmlProperty(doc, "horizontal-alignment", me.valueToKey(m_horizontal_alignment))); e.setAttribute("horizontal-alignment", me.valueToKey(m_horizontal_alignment));
e.appendChild(createXmlProperty(doc, "vertical-alignment", me.valueToKey(m_vertical_alignment))); e.setAttribute("vertical-alignment", me.valueToKey(m_vertical_alignment));
QString conductor_style = writeStyle(); QString conductor_style = writeStyle();
if (!conductor_style.isEmpty()) if (!conductor_style.isEmpty())
e.appendChild(createXmlProperty(doc, "style", conductor_style)); e.setAttribute("style", conductor_style);
return e;
} }
/** RETURNS True /**
* @brief ConductorProperties::fromXml * @brief ConductorProperties::fromXml
* Import conductor propertie, from the attribute of the xml element 'e' * Import conductor propertie, from the attribute of the xml element 'e'
* @param e the xml document * @param e the xml document
*/ */
bool ConductorProperties::fromXml(const QDomElement &e) void ConductorProperties::fromXml(QDomElement &e)
{ {
// get conductor color // get conductor color
propertyColor(e, "color", &color); QColor xml_color= QColor(e.attribute("color"));
propertyBool(e, "bicolor", &m_bicolor); color = (xml_color.isValid()? xml_color : QColor(Qt::black));
propertyColor(e, "color2", &m_color_2);
propertyInteger(e, "dash-size", &m_dash_size); QString bicolor_str = e.attribute("bicolor", "false");
m_bicolor = bicolor_str == "true"? true : false;
QColor xml_color_2 = QColor(e.attribute("color2"));
m_color_2 = xml_color_2.isValid()? xml_color_2 : QColor(Qt::black);
m_dash_size = e.attribute("dash-size", QString::number(1)).toInt();
// read style of conductor // read style of conductor
QString style_string; readStyle(e.attribute("style"));
propertyString(e, "style", &style_string);
readStyle(style_string); if (e.attribute("type") == typeToString(Single))
{
QString type_t; // get specific properties for single conductor
if (propertyString(e, "type", &type_t) == PropertyFlags::Success) { singleLineProperties.fromXml(e);
if (type_t == typeToString(Single)) type = Single;
{ }
// get specific properties for single conductor else
singleLineProperties.fromXml(e); type = Multi;
type = Single;
}
else if (type_t == typeToString(Multi))
type = Multi;
else {
//Keep retrocompatible with version older than 0,4
//If the propertie @type is simple (removed since QET 0,4), we set text no visible.
//@TODO remove this code for qet 0.6 or later
if (type_t == "simple") m_show_text = false;
}
}
propertyString(e, "num", &text);
text = e.attribute("num");
// get text color // get text color
propertyColor(e, "text_color", &text_color); QColor xml_text_color= QColor(e.attribute("text_color"));
propertyString(e, "formula", &m_formula); text_color = (xml_text_color.isValid()? xml_text_color : QColor(Qt::black));
propertyString(e, "function", &m_function); m_formula = e.attribute("formula");
propertyString(e, "tension_protocol", &m_tension_protocol); m_function = e.attribute("function");
propertyString(e, "conductor_color", &m_wire_color); m_tension_protocol = e.attribute("tension_protocol");
propertyString(e, "conductor_section", &m_wire_section); m_wire_color = e.attribute("conductor_color");
propertyInteger(e, "numsize", &text_size); m_wire_section = e.attribute("conductor_section");
propertyDouble(e, "condsize", &cond_size); text_size = e.attribute("numsize", QString::number(9)).toInt();
propertyBool(e, "displaytext", &m_show_text); cond_size = e.attribute("condsize", QString::number(1)).toDouble();
propertyBool(e, "onetextperfolio", &m_one_text_per_folio); m_show_text = e.attribute("displaytext", QString::number(1)).toInt();
propertyDouble(e, "vertirotatetext", &verti_rotate_text); m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt();
propertyDouble(e, "horizrotatetext", &horiz_rotate_text); verti_rotate_text = e.attribute("vertirotatetext").toDouble();
horiz_rotate_text = e.attribute("horizrotatetext").toDouble();
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>(); QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
m_horizontal_alignment = Qt::Alignment(
me.keyToValue(
e.attribute(
"horizontal-alignment",
"AlignBottom"
).toStdString().data()));
m_vertical_alignment = Qt::Alignment(
me.keyToValue(
e.attribute(
"vertical-alignment",
"AlignRight"
).toStdString().data()));
QString alinment_temp; //Keep retrocompatible with version older than 0,4
if (propertyString(e, "horizontal-alignment", &alinment_temp) == PropertyFlags::Success) //If the propertie @type is simple (removed since QET 0,4), we set text no visible.
m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); //@TODO remove this code for qet 0.6 or later
if (propertyString(e, "vertical-alignment", &alinment_temp) == PropertyFlags::Success) #pragma message("@TODO remove this code for qet 0.6 or later")
m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); if (e.attribute("type") == "simple") m_show_text = false;
return true;
}
bool ConductorProperties::valideXml(QDomElement& e) {
if (propertyColor(e, "color") ||
propertyBool(e, "bicolor") ||
propertyColor(e, "color2") ||
propertyInteger(e, "dash-size") ||
propertyString(e, "type") ||
propertyString(e, "num") ||
propertyColor(e, "text_color") ||
propertyString(e, "formula") ||
propertyString(e, "function") ||
propertyString(e, "tension_protocol") ||
propertyString(e, "conductor_color") ||
propertyString(e, "conductor_section") ||
propertyInteger(e, "numsize") ||
propertyDouble(e, "condsize") ||
propertyBool(e, "displaytext") ||
propertyBool(e, "onetextperfolio") ||
propertyDouble(e, "vertirotatetext") ||
propertyDouble(e, "horizrotatetext") ||
propertyString(e, "horizontal-alignment") ||
propertyString(e, "vertical-alignment"))
return false;
return true;
} }
/** /**
@@ -439,7 +388,7 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
@param settings Parametres a lire @param settings Parametres a lire
@param prefix prefixe a ajouter devant les noms des parametres @param prefix prefixe a ajouter devant les noms des parametres
*/ */
void ConductorProperties::fromSettings(const QSettings &settings, const QString &prefix) void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix)
{ {
QColor settings_color = QColor(settings.value(prefix + "color").toString()); QColor settings_color = QColor(settings.value(prefix + "color").toString());
color = (settings_color.isValid()? settings_color : QColor(Qt::black)); color = (settings_color.isValid()? settings_color : QColor(Qt::black));
@@ -816,6 +765,7 @@ void ConductorProperties::readStyle(const QString &style_string) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList styles = style_string.split(";", QString::SkipEmptyParts); QStringList styles = style_string.split(";", QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code QString::SkipEmptyParts for QT 5.14 or later")
QStringList styles = style_string.split(";", Qt::SkipEmptyParts); QStringList styles = style_string.split(";", Qt::SkipEmptyParts);
#endif #endif
@@ -883,7 +833,7 @@ void SingleLineProperties::toSettings(QSettings &settings, const QString &prefix
@param settings Parametres a lire @param settings Parametres a lire
@param prefix prefix a ajouter devant les noms des parametres @param prefix prefix a ajouter devant les noms des parametres
*/ */
void SingleLineProperties::fromSettings(const QSettings &settings, const QString &prefix) { void SingleLineProperties::fromSettings(QSettings &settings, const QString &prefix) {
hasGround = settings.value(prefix + "hasGround", true).toBool(); hasGround = settings.value(prefix + "hasGround", true).toBool();
hasNeutral = settings.value(prefix + "hasNeutral", true).toBool(); hasNeutral = settings.value(prefix + "hasNeutral", true).toBool();
phases = settings.value(prefix + "phases", 1).toInt(); phases = settings.value(prefix + "phases", 1).toInt();

View File

@@ -22,14 +22,13 @@
#include <QColor> #include <QColor>
#include <QSettings> #include <QSettings>
#include "propertiesinterface.h"
class QPainter; class QPainter;
/** /**
@brief The SingleLineProperties class
This class represents the properties of a singleline conductor. This class represents the properties of a singleline conductor.
*/ */
class SingleLineProperties: public PropertiesInterface { class SingleLineProperties {
public: public:
SingleLineProperties(); SingleLineProperties();
virtual ~SingleLineProperties(); virtual ~SingleLineProperties();
@@ -38,54 +37,54 @@ class SingleLineProperties: public PropertiesInterface {
unsigned short int phasesCount(); unsigned short int phasesCount();
bool isPen() const; bool isPen() const;
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &); void draw(QPainter *, QET::ConductorSegmentType, const QRectF &);
QDomElement toXml(QDomDocument& doc) const override; void toXml(QDomElement &) const;
bool fromXml(const QDomElement &) override; void fromXml(QDomElement &);
static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const;
void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString());
void fromSettings(const QSettings &, const QString & = QString()) override;
/// Whether the singleline conductor should display the ground symbol /// Whether the singleline conductor should display the ground symbol
bool hasGround{true}; bool hasGround;
/// Whether the singleline conductor should display the neutral symbol /// Whether the singleline conductor should display the neutral symbol
bool hasNeutral{true}; bool hasNeutral;
/// Protective Earth Neutral: visually merge neutral and ground /// Protective Earth Neutral: visually merge neutral and ground
bool is_pen{false}; bool is_pen;
int operator==(const SingleLineProperties &) const; int operator==(const SingleLineProperties &) const;
int operator!=(const SingleLineProperties &) const; int operator!=(const SingleLineProperties &) const;
private: private:
unsigned short int phases{1}; unsigned short int phases;
void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
}; };
/** /**
@brief The ConductorProperties class
This class represents the functional properties of a particular conductor, This class represents the functional properties of a particular conductor,
i.e. properties other than path and terminals. i.e. properties other than path and terminals.
*/ */
class ConductorProperties: public PropertiesInterface class ConductorProperties
{ {
public: public:
ConductorProperties(); ConductorProperties();
virtual ~ConductorProperties(); virtual ~ConductorProperties();
/** /**
* @brief The ConductorType enum Represents the kind of a particular conductor: @brief The ConductorType enum Represents
* Single: singleline symbols, no text input the kind of a particular conductor:
* Multi: text input, no symbol Single: singleline symbols, no text input
*/ Multi: text input, no symbol
*/
enum ConductorType { Single, Multi }; enum ConductorType { Single, Multi };
//Attributes //Attributes
ConductorType type{ConductorType::Single}; ConductorType type;
// TODO: set default values! QColor color,
QColor color{QColor(Qt::black)}, m_color_2,
m_color_2{QColor(Qt::black)}, text_color;
text_color{QColor(Qt::black)};
QString text, QString text,
m_function, m_function,
@@ -94,36 +93,35 @@ class ConductorProperties: public PropertiesInterface
m_wire_section, m_wire_section,
m_formula; m_formula;
int text_size{9}, int text_size,
m_dash_size = 1; m_dash_size = 1;
double cond_size{1}, double cond_size,
verti_rotate_text, verti_rotate_text,
horiz_rotate_text; horiz_rotate_text;
bool m_show_text{true}, bool m_show_text,
m_one_text_per_folio{true}, m_one_text_per_folio,
m_bicolor = false; m_bicolor = false;
Qt::Alignment m_horizontal_alignment = Qt::AlignBottom, Qt::Alignment m_horizontal_alignment = Qt::AlignBottom,
m_vertical_alignment = Qt::AlignRight; m_vertical_alignment = Qt::AlignRight;
Qt::PenStyle style{Qt::PenStyle::SolidLine}; Qt::PenStyle style;
SingleLineProperties singleLineProperties; SingleLineProperties singleLineProperties;
// methods // methods
QDomElement toXml(QDomDocument &doc) const override; void toXml(QDomElement &) const;
bool fromXml(const QDomElement &) override; void fromXml(QDomElement &);
static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const;
void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString());
void fromSettings(const QSettings &, const QString & = QString()) override;
static QString typeToString(ConductorType); static QString typeToString(ConductorType);
void applyForEqualAttributes(QList<ConductorProperties> list); void applyForEqualAttributes(QList<ConductorProperties> list);
static ConductorProperties defaultProperties(); static ConductorProperties defaultProperties();
// operators // operators
bool operator==(const ConductorProperties &) const; bool operator==(const ConductorProperties &) const;
bool operator!=(const ConductorProperties &) const; bool operator!=(const ConductorProperties &) const;

View File

@@ -15,46 +15,74 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QScrollArea>
#include "configdialog.h" #include "configdialog.h"
#include "configpages.h" #include "configpages.h"
#include "qetapp.h" #include "qetapp.h"
#include "machine_info.h"
/** /**
Constructeur Constructeur
@param parent QWidget parent @param parent QWidget parent
*/ */
ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
Machine_info *mymachineinfo= new Machine_info(this);
//ScrollArea for low screens
QScrollArea *scroll = new QScrollArea(this);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// liste des pages // liste des pages
pages_list = new QListWidget(); pages_list = new QListWidget();
pages_list -> setViewMode(QListView::IconMode); pages_list -> setViewMode(QListView::IconMode);
pages_list -> setIconSize(QSize(128, 128)); if(mymachineinfo->get_max_screen_height()<1000){
pages_list -> setIconSize(QSize(64, 64));
} else {
pages_list -> setIconSize(QSize(128, 128));
}
pages_list -> setMovement(QListView::Static); pages_list -> setMovement(QListView::Static);
pages_list -> setMinimumWidth(168); pages_list -> setMinimumWidth(168);
pages_list -> setMaximumWidth(168); pages_list -> setMaximumWidth(168);
pages_list -> setSpacing(16); pages_list -> setSpacing(16);
pages_list -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); pages_list -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// pages // pages
pages_widget = new QStackedWidget(); pages_widget = new QStackedWidget();
// boutons // boutons
buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); buttons = new QDialogButtonBox(
QDialogButtonBox::Ok
|QDialogButtonBox::Cancel);
QWidget *viewport = new QWidget(this);
scroll->setWidget(viewport);
scroll->setWidgetResizable(true);
// layouts // layouts
QHBoxLayout *hlayout1 = new QHBoxLayout(); QHBoxLayout *hlayout1 = new QHBoxLayout(viewport);
// add needed widgets to layout "hlayout1"
hlayout1 -> addWidget(pages_list); hlayout1 -> addWidget(pages_list);
hlayout1 -> addWidget(pages_widget); hlayout1 -> addWidget(pages_widget);
QVBoxLayout *vlayout1 = new QVBoxLayout(); //add hlayout1 to widget
vlayout1 -> addLayout(hlayout1); viewport->setLayout(hlayout1);
vlayout1 -> addWidget(buttons);
setLayout(vlayout1); // Add a layout for QDialog
QVBoxLayout *dialog_layout = new QVBoxLayout(this);
dialog_layout->addWidget(scroll); // add scroll to the QDialog's layout
dialog_layout -> addWidget(buttons);
setLayout(dialog_layout);
// connexion signaux / slots // connexion signaux / slots
connect(buttons, SIGNAL(accepted()), this, SLOT(applyConf())); connect(buttons, SIGNAL(accepted()), this, SLOT(applyConf()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
connect(pages_list, SIGNAL(currentRowChanged(int)), pages_widget, SLOT(setCurrentIndex(int))); connect(pages_list, SIGNAL(currentRowChanged(int)),
pages_widget, SLOT(setCurrentIndex(int)));
resize(mymachineinfo->get_max_screen_width(),
mymachineinfo->get_max_screen_height());
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
if (parent) { if (parent) {
setWindowFlags(Qt::Sheet); setWindowFlags(Qt::Sheet);

View File

@@ -46,6 +46,7 @@ ElementQueryWidget::ElementQueryWidget(QWidget *parent) :
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), [this](int id) connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), [this](int id)
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idClicked), [this](int id) connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idClicked), [this](int id)
#endif #endif
{ {

View File

@@ -624,12 +624,13 @@ QDomDocument Diagram::toXml(bool whole_content) {
// proprietes du schema // proprietes du schema
if (whole_content) { if (whole_content) {
// TODO: compare with old version border_and_titleblock.titleBlockToXml(dom_root);
border_and_titleblock.titleBlockToXml(dom_root);
border_and_titleblock.borderToXml(dom_root); border_and_titleblock.borderToXml(dom_root);
// Default conductor properties // Default conductor properties
dom_root.appendChild(defaultConductorProperties.toXml(document)); QDomElement default_conductor = document.createElement("defaultconductor");
defaultConductorProperties.toXml(default_conductor);
dom_root.appendChild(default_conductor);
// Conductor autonum // Conductor autonum
if (!m_conductors_autonum_name.isEmpty()) { if (!m_conductors_autonum_name.isEmpty()) {
@@ -750,11 +751,12 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
// table de correspondance entre les adresses des bornes et leurs ids // table de correspondance entre les adresses des bornes et leurs ids
QHash<Terminal *, int> table_adr_id;
if (!list_elements.isEmpty()) { if (!list_elements.isEmpty()) {
auto dom_elements = document.createElement("elements"); auto dom_elements = document.createElement("elements");
for (auto elmt : list_elements) { for (auto elmt : list_elements) {
dom_elements.appendChild(elmt->toXml(document)); dom_elements.appendChild(elmt->toXml(document, table_adr_id));
} }
dom_root.appendChild(dom_elements); dom_root.appendChild(dom_elements);
} }
@@ -762,7 +764,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
if (!list_conductors.isEmpty()) { if (!list_conductors.isEmpty()) {
auto dom_conductors = document.createElement("conductors"); auto dom_conductors = document.createElement("conductors");
for (auto cond : list_conductors) { for (auto cond : list_conductors) {
dom_conductors.appendChild(cond->toXml(document)); dom_conductors.appendChild(cond->toXml(document, table_adr_id));
} }
dom_root.appendChild(dom_conductors); dom_root.appendChild(dom_conductors);
} }
@@ -870,14 +872,14 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider
* \param added_elements Elements found in the xml file * \param added_elements Elements found in the xml file
* \return * \return
*/ */
Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash<int, Terminal *>& table_adr_id, QList<Element *>& added_elements) { Terminal* findTerminal(int conductor_index, QDomElement& f, QHash<int, Terminal *>& table_adr_id, QList<Element *>& added_elements) {
assert(conductor_index == 1 || conductor_index == 2); assert(conductor_index == 1 || conductor_index == 2);
QString element_index = "element" + QString::number(conductor_index); QString element_index = "element" + QString::number(conductor_index);
QString terminal_index = "terminal" + QString::number(conductor_index); QString terminal_index = "terminal" + QString::number(conductor_index);
QUuid element_uuid; if (f.hasAttribute(element_index)) {
if (PropertiesInterface::propertyUuid(conductor, element_index, &element_uuid) == PropertiesInterface::PropertyFlags::Success) { QUuid element_uuid = QUuid(f.attribute(element_index));
// element1 did not exist in the conductor part of the xml until prior 0.7 // element1 did not exist in the conductor part of the xml until prior 0.7
// It is used as an indicator that uuid's are used to identify terminals // It is used as an indicator that uuid's are used to identify terminals
bool element_found = false; bool element_found = false;
@@ -885,8 +887,7 @@ Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash<int, T
if (element->uuid() != element_uuid) if (element->uuid() != element_uuid)
continue; continue;
element_found = true; element_found = true;
QUuid terminal_uuid; QUuid terminal_uuid = QUuid(f.attribute(terminal_index));
PropertiesInterface::propertyUuid(conductor, terminal_index, &terminal_uuid);
for (auto terminal: element->terminals()) { for (auto terminal: element->terminals()) {
if (terminal->uuid() != terminal_uuid) if (terminal->uuid() != terminal_uuid)
continue; continue;
@@ -900,16 +901,12 @@ Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash<int, T
qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found"; qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found";
} else { } else {
// Backward compatibility. Until version 0.7 a generated id is used to link the terminal. // Backward compatibility. Until version 0.7 a generated id is used to link the terminal.
int id_p1 = -1; int id_p1 = f.attribute(terminal_index).toInt();
if (PropertiesInterface::propertyInteger(conductor, terminal_index, &id_p1) != PropertiesInterface::PropertyFlags::Success) {
qDebug() << "diagramm.cpp:findTerminal(): Reading Id was not successfull";
}
if (!table_adr_id.contains(id_p1)) { if (!table_adr_id.contains(id_p1)) {
qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found"; qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found";
} else } else
return table_adr_id.value(id_p1); return table_adr_id.value(id_p1);
} }
qDebug() << "Diagram::findTerminal(): No terminal found.";
return nullptr; return nullptr;
} }
@@ -927,11 +924,9 @@ Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash<int, T
@return true si l'import a reussi, false sinon @return true si l'import a reussi, false sinon
*/ */
bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) { bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) {
const QDomElement& root = document; const QDomElement& root = document;
// The first element must be a diagram // The first element must be a diagram
if (root.tagName() != "diagram") return(false); if (root.tagName() != "diagram") return(false);
qDebug() << "Diagram::fromXml; Diagram: " << root.attribute("title");
// Read attributes of this diagram // Read attributes of this diagram
if (consider_informations) { if (consider_informations) {
@@ -943,7 +938,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
} }
// Load border and titleblock // Load border and titleblock
border_and_titleblock.titleBlockFromXml(root); border_and_titleblock.titleBlockFromXml(root);
border_and_titleblock.borderFromXml(root); border_and_titleblock.borderFromXml(root);
// Find the element "defaultconductor". // Find the element "defaultconductor".
@@ -953,7 +948,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
defaultConductorProperties.fromXml(default_conductor_elmt); defaultConductorProperties.fromXml(default_conductor_elmt);
} }
// Load the autonum // Load the autonum
m_conductors_autonum_name = root.attribute("conductorAutonum"); m_conductors_autonum_name = root.attribute("conductorAutonum");
@@ -1011,10 +1005,10 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
} }
} }
} }
//Load all elements from the collection in the XML //Load all elements from the XML
QList<Element *> added_elements; QList<Element *> added_elements;
QHash<int, Terminal *> table_adr_id; QHash<int, Terminal *> table_adr_id;
foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element")) // read all elements from the diagram foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element"))
{ {
if (!Element::valideXml(element_xml)) continue; if (!Element::valideXml(element_xml)) continue;
@@ -1029,8 +1023,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
} }
int state = 0; int state = 0;
// Create element from the collection Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state);
Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); // read element definition from the collection!
if (state) if (state)
{ {
QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state); QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state);
@@ -1041,7 +1034,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
addItem(nvel_elmt); addItem(nvel_elmt);
//Loading fail, remove item from the diagram //Loading fail, remove item from the diagram
if (!nvel_elmt->fromXml(element_xml, table_adr_id, handle_inputs_rotation)) // load element definition from the diagram if (!nvel_elmt->fromXml(element_xml, table_adr_id, handle_inputs_rotation))
{ {
removeItem(nvel_elmt); removeItem(nvel_elmt);
delete nvel_elmt; delete nvel_elmt;
@@ -1080,29 +1073,27 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
// Load conductor // Load conductor
QList<Conductor *> added_conductors; QList<Conductor *> added_conductors;
foreach (QDomElement conductorElement, QET::findInDomElement(root, "conductors", "conductor")) foreach (QDomElement f, QET::findInDomElement(root, "conductors", "conductor"))
{ {
if (!Conductor::valideXml(conductorElement)) continue; if (!Conductor::valideXml(f)) continue;
//Check if terminal that conductor must be linked is know //Check if terminal that conductor must be linked is know
Terminal* p1 = findTerminal(1, conductorElement, table_adr_id, added_elements); Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements);
Terminal* p2 = findTerminal(2, conductorElement, table_adr_id, added_elements); Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements);
if (p1 && p2 && p1 != p2) // why the condition for unequal is required? if (p1 && p2 && p1 != p2)
{ {
Conductor *c = new Conductor(p1, p2); Conductor *c = new Conductor(p1, p2);
if (c->isValid()) if (c->isValid())
{ {
addItem(c); addItem(c);
c -> fromXml(conductorElement); c -> fromXml(f);
added_conductors << c; added_conductors << c;
} }
else else
delete c; delete c;
} else { }
qDebug() << "Diagramm::fromXML(): No matching terminals found.";
}
} }
//Load tables //Load tables
@@ -1150,6 +1141,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
content_ptr -> m_images = added_images.toSet(); content_ptr -> m_images = added_images.toSet();
content_ptr -> m_shapes = added_shapes.toSet(); content_ptr -> m_shapes = added_shapes.toSet();
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
content_ptr -> m_text_fields = QSet<IndependentTextItem *>( content_ptr -> m_text_fields = QSet<IndependentTextItem *>(
added_texts.begin(), added_texts.begin(),
added_texts.end()); added_texts.end());

View File

@@ -96,7 +96,7 @@ class Diagram : public QGraphicsScene
/// margin around the diagram /// margin around the diagram
static const qreal margin; static const qreal margin;
/// background color of diagram /// background color of diagram
static QColor background_color; // default value set in cpp file static QColor background_color;
/// Hash containing max values for folio sequential autonums in this diagram /// Hash containing max values for folio sequential autonums in this diagram
QHash <QString, QStringList> m_elmt_unitfolio_max; QHash <QString, QStringList> m_elmt_unitfolio_max;
QHash <QString, QStringList> m_elmt_tenfolio_max; QHash <QString, QStringList> m_elmt_tenfolio_max;
@@ -166,7 +166,7 @@ class Diagram : public QGraphicsScene
QList < QSet <Conductor *> > potentials(); QList < QSet <Conductor *> > potentials();
// methods related to XML import/export // methods related to XML import/export
QDomDocument toXml(bool = true); QDomDocument toXml(bool = true);
bool initFromXml(QDomElement &, QPointF = QPointF(), bool initFromXml(QDomElement &, QPointF = QPointF(),
bool = true, DiagramContent * = nullptr); bool = true, DiagramContent * = nullptr);
bool fromXml(QDomDocument &, QPointF = QPointF(), bool fromXml(QDomDocument &, QPointF = QPointF(),

View File

@@ -197,17 +197,15 @@ void DiagramContext::toSettings(QSettings &settings, const QString &array_name)
Read this context properties from \a settings by running through the array Read this context properties from \a settings by running through the array
named \a array_name. named \a array_name.
*/ */
void DiagramContext::fromSettings(const QSettings &settings, const QString &array_name) { void DiagramContext::fromSettings(QSettings &settings, const QString &array_name) {
// TODO: find better solution than const cast int size = settings.beginReadArray(array_name);
QSettings& s = const_cast<QSettings&>(settings);
int size = s.beginReadArray(array_name);
for (int i = 0 ; i < size; ++ i) { for (int i = 0 ; i < size; ++ i) {
s.setArrayIndex(i); settings.setArrayIndex(i);
QString key = settings.value("name").toString(); QString key = settings.value("name").toString();
if (key.isEmpty()) continue; if (key.isEmpty()) continue;
addValue(key, settings.value("value").toString()); addValue(key, settings.value("value").toString());
} }
s.endArray(); settings.endArray();
} }
/** /**

View File

@@ -79,7 +79,7 @@ class DiagramContext
void fromXml(const QDomElement &, const QString & = "property"); void fromXml(const QDomElement &, const QString & = "property");
void fromXml(const pugi::xml_node &dom_element, const QString &tag_name = "property"); void fromXml(const pugi::xml_node &dom_element, const QString &tag_name = "property");
void toSettings(QSettings &, const QString &) const; void toSettings(QSettings &, const QString &) const;
void fromSettings(const QSettings &, const QString &); void fromSettings(QSettings &, const QString &);
static QString validKeyRegExp(); static QString validKeyRegExp();

View File

@@ -41,6 +41,7 @@ DiagramPrintDialog::DiagramPrintDialog(QETProject *project, QWidget *parent) :
// orientation paysage par defaut // orientation paysage par defaut
printer_ -> setOrientation(QPrinter::Landscape); printer_ -> setOrientation(QPrinter::Landscape);
backup_diagram_background_color = Diagram::background_color;
Diagram::background_color = Qt::white; Diagram::background_color = Qt::white;
} }

View File

@@ -88,6 +88,6 @@ class DiagramPrintDialog : public QWidget
QLineEdit *filepath_field_; QLineEdit *filepath_field_;
QPushButton *browse_button_; QPushButton *browse_button_;
QDialogButtonBox *buttons_; QDialogButtonBox *buttons_;
QColor backup_diagram_background_color{Diagram::background_color}; QColor backup_diagram_background_color;
}; };
#endif #endif

View File

@@ -416,6 +416,7 @@ void ChangeZValueCommand::applyRaise(const QList<QGraphicsItem *> &items_list) {
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove
my_items_list.swap(i, i + 1); my_items_list.swap(i, i + 1);
#else #else
#pragma message("@TODO remove code for QT 5.13 or later")
my_items_list.swapItemsAt(i, i + 1); my_items_list.swapItemsAt(i, i + 1);
#endif #endif
} }
@@ -438,6 +439,7 @@ void ChangeZValueCommand::applyLower(const QList<QGraphicsItem *> &items_list) {
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove
my_items_list.swap(i, i - 1); my_items_list.swap(i, i - 1);
#else #else
#pragma message("@TODO remove code for QT 5.13 or later")
my_items_list.swapItemsAt(i, i - 1); my_items_list.swapItemsAt(i, i - 1);
#endif #endif
} }

View File

@@ -144,7 +144,7 @@ void CustomElementGraphicPart::setAntialiased(const bool b)
* Each style separate by ; and name-style/value are separate by : * Each style separate by ; and name-style/value are separate by :
* @param qde : QDOmElement used to write the style. * @param qde : QDOmElement used to write the style.
*/ */
void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomElement &qde) const void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const
{ {
QString css_like_styles; QString css_like_styles;
@@ -479,8 +479,9 @@ void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomEleme
else if (_color == HTMLGrayBlackColor) css_like_styles += "HTMLGrayBlack"; else if (_color == HTMLGrayBlackColor) css_like_styles += "HTMLGrayBlack";
else if (_color == NoneColor) css_like_styles += "none"; else if (_color == NoneColor) css_like_styles += "none";
qde.appendChild(createXmlProperty(xml_document, "style", css_like_styles));
qde.appendChild(createXmlProperty(xml_document, "antialias", _antialiased ? "true" : "false")); qde.setAttribute("style", css_like_styles);
qde.setAttribute("antialias", _antialiased ? "true" : "false");
} }
@@ -492,18 +493,14 @@ void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomEleme
void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde) void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde)
{ {
resetStyles(); resetStyles();
QString style_string;
propertyString(qde, "style", &style_string);
//Get the list of pair style/value //Get the list of pair style/value
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList styles = style_string.split(";", QString::SkipEmptyParts); QStringList styles = qde.attribute("style").split(";", QString::SkipEmptyParts);
#else #else
QStringList styles = style_string.split(";", Qt::SkipEmptyParts); #pragma message("@TODO remove code for QT 5.14 or later")
QStringList styles = qde.attribute("style").split(";", Qt::SkipEmptyParts);
#endif #endif
//Check each pair of style //Check each pair of style
QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$"); QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$");
@@ -847,9 +844,7 @@ void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde)
} }
} }
//Get antialiasing //Get antialiasing
QString a; _antialiased = qde.attribute("antialias") == "true";
propertyString(qde, "antialias", &a);
_antialiased = a == "true";
} }

View File

@@ -95,7 +95,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
virtual void resetAllHandlerColor() {} virtual void resetAllHandlerColor() {}
protected: protected:
void stylesToXml (QDomDocument &xml_document, QDomElement &) const; void stylesToXml (QDomElement &) const;
void stylesFromXml(const QDomElement &); void stylesFromXml(const QDomElement &);
void resetStyles (); void resetStyles ();
void applyStylesToQPainter(QPainter &) const; void applyStylesToQPainter(QPainter &) const;

View File

@@ -19,7 +19,6 @@
#define CUSTOM_ELEMENT_PART_H #define CUSTOM_ELEMENT_PART_H
#include "qet.h" #include "qet.h"
#include "propertiesinterface.h"
class CustomElement; class CustomElement;
class ElementPrimitiveDecorator; class ElementPrimitiveDecorator;
@@ -36,7 +35,7 @@ class QGraphicsSceneMouseEvent;
is no point for those classes to store their visual representation with is no point for those classes to store their visual representation with
anything more complex than a QImage. anything more complex than a QImage.
*/ */
class CustomElementPart: public PropertiesInterface { class CustomElementPart {
// constructors, destructor // constructors, destructor
public: public:
/** /**
@@ -56,6 +55,14 @@ class CustomElementPart: public PropertiesInterface {
// methods // methods
public: public:
/**
Load the primitive from an XML element that describes it
*/
virtual void fromXml(const QDomElement &) = 0;
/**
Export the primitive as an XML element
*/
virtual const QDomElement toXml(QDomDocument &) const = 0;
/** /**
Set a specific property of the primitive Set a specific property of the primitive
*/ */

View File

@@ -95,21 +95,17 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
* @param xml_document : Xml document to use for create the xml element. * @param xml_document : Xml document to use for create the xml element.
* @return : an xml element that describe this arc * @return : an xml element that describe this arc
*/ */
QDomElement PartArc::toXml(QDomDocument &xml_document) const { const QDomElement PartArc::toXml(QDomDocument &xml_document) const {
QDomElement xml_element = xml_document.createElement("arc"); QDomElement xml_element = xml_document.createElement("arc");
QPointF top_left(sceneTopLeft()); QPointF top_left(sceneTopLeft());
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); xml_element.setAttribute("width", QString("%1").arg(rect().width()));
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); xml_element.setAttribute("height", QString("%1").arg(rect().height()));
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); //to maintain compatibility with the previous version, we write the angle in degrees.
xml_element.setAttribute("start", QString("%1").arg(m_start_angle / 16));
//to maintain compatibility with the previous version, we write the angle in degrees. xml_element.setAttribute("angle", QString("%1").arg(m_span_angle / 16));
xml_element.appendChild(createXmlProperty(xml_document, "start", m_start_angle / 16)); stylesToXml(xml_element);
xml_element.appendChild(createXmlProperty(xml_document, "angle", m_span_angle / 16));
stylesToXml(xml_document, xml_element);
return(xml_element); return(xml_element);
} }
@@ -118,41 +114,15 @@ QDomElement PartArc::toXml(QDomDocument &xml_document) const {
* Import the properties of this arc from a xml element. * Import the properties of this arc from a xml element.
* @param qde : Xml document to use. * @param qde : Xml document to use.
*/ */
bool PartArc::fromXml(const QDomElement &qde) { void PartArc::fromXml(const QDomElement &qde) {
stylesFromXml(qde); stylesFromXml(qde);
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
qde.attribute("y", "0").toDouble()),
QSizeF(qde.attribute("width", "0").toDouble(),
qde.attribute("height", "0").toDouble()) );
double x=0, y=0, w=0, h=0; m_start_angle = qde.attribute("start", "0").toDouble() * 16;
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16;
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "height", &h) == PropertyFlags::NoValidConversion)
return false;
m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) );
m_start_angle = 0;
if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion)
return false;
m_start_angle *= 16;
m_span_angle = -1440;
if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion)
return false;
m_span_angle *= 16;
return true;
}
bool PartArc::valideXml(QDomElement& element) {
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "width") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "height") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "start") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "angle") == PropertyFlags::NoValidConversion)
return false;
return true;
} }
/** /**

View File

@@ -51,9 +51,8 @@ class PartArc : public AbstractPartEllipse
//Name and XML //Name and XML
QString name() const override { return(QObject::tr("arc", "element part name")); } QString name() const override { return(QObject::tr("arc", "element part name")); }
QString xmlName() const override { return(QString("arc")); } QString xmlName() const override { return(QString("arc")); }
QDomElement toXml (QDomDocument &) const override; const QDomElement toXml (QDomDocument &) const override;
bool fromXml (const QDomElement &) override; void fromXml (const QDomElement &) override;
static bool valideXml(QDomElement& element);
QPainterPath shape() const override; QPainterPath shape() const override;
QPainterPath shadowShape() const override; QPainterPath shadowShape() const override;

View File

@@ -85,38 +85,37 @@ void PartDynamicTextField::handleUserTransformation(const QRectF &initial_select
* @param document * @param document
* @return * @return
*/ */
QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
{ {
QDomElement root_element = dom_doc.createElement(xmlName()); QDomElement root_element = dom_doc.createElement(xmlName());
root_element.appendChild(createXmlProperty(dom_doc, "x", pos().x())); root_element.setAttribute("x", QString::number(pos().x()));
root_element.appendChild(createXmlProperty(dom_doc, "y", pos().y())); root_element.setAttribute("y", QString::number(pos().y()));
root_element.appendChild(createXmlProperty(dom_doc, "z", zValue())); root_element.setAttribute("z", QString::number(zValue()));
root_element.appendChild(createXmlProperty(dom_doc, "rotation", QET::correctAngle(rotation()))); root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
root_element.setAttribute("font", font().toString());
root_element.appendChild(createXmlProperty(dom_doc, "font", font().toString())); root_element.setAttribute("uuid", m_uuid.toString());
root_element.appendChild(createXmlProperty(dom_doc, "uuid", m_uuid)); root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.appendChild(createXmlProperty(dom_doc, "frame", m_frame)); root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.appendChild(createXmlProperty(dom_doc, "text_width", m_text_width));
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
root_element.appendChild(createXmlProperty(dom_doc, "text_from", me.valueToKey(m_text_from))); root_element.setAttribute("text_from", me.valueToKey(m_text_from));
me = QMetaEnum::fromType<Qt::Alignment>(); me = QMetaEnum::fromType<Qt::Alignment>();
if(this->alignment() &Qt::AlignRight) if(this->alignment() &Qt::AlignRight)
root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignRight))); root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
else if(this->alignment() &Qt::AlignLeft) else if(this->alignment() &Qt::AlignLeft)
root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignLeft))); root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
else if(this->alignment() &Qt::AlignHCenter) else if(this->alignment() &Qt::AlignHCenter)
root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignHCenter))); root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
if(this->alignment() &Qt::AlignBottom) if(this->alignment() &Qt::AlignBottom)
root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignBottom))); root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
else if(this->alignment() & Qt::AlignTop) else if(this->alignment() & Qt::AlignTop)
root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignTop))); root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
else if(this->alignment() &Qt::AlignVCenter) else if(this->alignment() &Qt::AlignVCenter)
root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignVCenter))); root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
QDomElement dom_text = dom_doc.createElement("text"); QDomElement dom_text = dom_doc.createElement("text");
dom_text.appendChild(dom_doc.createTextNode(toPlainText())); dom_text.appendChild(dom_doc.createTextNode(toPlainText()));
@@ -153,54 +152,39 @@ QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
* @brief PartDynamicTextField::fromXml * @brief PartDynamicTextField::fromXml
* @param element * @param element
*/ */
bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) void PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
{ {
if (dom_elmt.tagName() != xmlName()) { if (dom_elmt.tagName() != xmlName()) {
qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name"; qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name";
return false; return;
} }
double x=0, y=0, z=0, rot=0;
if (propertyDouble(dom_elmt, "x", &x) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "y", &y) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "z", &z) == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "rotation", &rot) == PropertyFlags::NoValidConversion)
return false;
QGraphicsTextItem::setPos(x, y); QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(),
setZValue(z); dom_elmt.attribute("y", QString::number(0)).toDouble());
QGraphicsTextItem::setRotation(rot); setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble());
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
QString font; if (dom_elmt.hasAttribute("font"))
if (propertyString(dom_elmt, "font", &font) == PropertyFlags::Success)
{ {
QFont font_; QFont font_;
font_.fromString(font); font_.fromString(dom_elmt.attribute("font"));
setFont(font_); setFont(font_);
} else { //Keep compatibility TODO remove in futur } else { //Keep compatibility TODO remove in futur
setFont(QETApp::dynamicTextsItemFont(9)); setFont(QETApp::dynamicTextsItemFont(9));
} }
propertyUuid(dom_elmt, "uuid", &m_uuid); m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
bool frame; setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
propertyBool(dom_elmt, "frame", &frame); setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
double text_width=-1;
propertyDouble(dom_elmt, "text_width", &text_width);
setTextWidth(text_width);
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
QString text_from; m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(dom_elmt.attribute("text_from").toStdString().data()));
propertyString(dom_elmt, "text_from", &text_from);
m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(text_from.toStdString().data()));
me = QMetaEnum::fromType<Qt::Alignment>(); me = QMetaEnum::fromType<Qt::Alignment>();
QString alignment; if(dom_elmt.hasAttribute("Halignment"))
if(propertyString(dom_elmt, "Halignment", &alignment) != PropertyFlags::NotFound) setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute("Halignment").toStdString().data())));
setAlignment(Qt::Alignment(me.keyToValue(alignment.toStdString().data()))); if(dom_elmt.hasAttribute(("Valignment")))
if(propertyString(dom_elmt, "Valignment", &alignment) != PropertyFlags::NotFound) setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute("Valignment").toStdString().data())) | this->alignment());
setAlignment(Qt::Alignment(me.keyToValue(alignment.toStdString().data())) | this->alignment());
//Text //Text
QDomElement dom_text = dom_elmt.firstChildElement("text"); QDomElement dom_text = dom_elmt.firstChildElement("text");
@@ -226,29 +210,6 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
QDomElement dom_color = dom_elmt.firstChildElement("color"); QDomElement dom_color = dom_elmt.firstChildElement("color");
if(!dom_color.isNull()) if(!dom_color.isNull())
setColor(QColor(dom_color.text())); setColor(QColor(dom_color.text()));
return true;
}
bool PartDynamicTextField::valideXml(QDomElement& dom_elmt) {
if (propertyDouble(dom_elmt, "x") == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "y") == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "z") == PropertyFlags::NoValidConversion ||
propertyDouble(dom_elmt, "rotation") == PropertyFlags::NoValidConversion)
return false;
if (propertyUuid(dom_elmt, "uuid") == PropertyFlags::NoValidConversion)
return false;
if (propertyString(dom_elmt, "text_from"))
return false;
if(propertyString(dom_elmt, "Halignment") == PropertyFlags::NotFound)
return false;
if(propertyString(dom_elmt, "Valignment") == PropertyFlags::NotFound)
return false;
return true;
} }
/** /**

View File

@@ -74,10 +74,9 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
void startUserTransformation(const QRectF &initial_selection_rect) override; void startUserTransformation(const QRectF &initial_selection_rect) override;
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override; void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
QDomElement toXml(QDomDocument &dom_doc) const override; const QDomElement toXml(QDomDocument &dom_doc) const override;
bool fromXml(const QDomElement &dom_elmt) override; void fromXml(const QDomElement &dom_elmt) override;
void fromTextFieldXml(const QDomElement &dom_element); void fromTextFieldXml(const QDomElement &dom_element);
static bool valideXml(QDomElement& dom_elmt);
DynamicElementTextItem::TextFrom textFrom() const; DynamicElementTextItem::TextFrom textFrom() const;
void setTextFrom (DynamicElementTextItem::TextFrom text_from); void setTextFrom (DynamicElementTextItem::TextFrom text_from);
@@ -117,7 +116,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
m_info_name, m_info_name,
m_composite_text; m_composite_text;
DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText; DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText;
QUuid m_uuid{QUuid::createUuid()}; QUuid m_uuid;
bool m_frame = false, bool m_frame = false,
m_first_add = true, m_first_add = true,
m_block_alignment = false; m_block_alignment = false;

View File

@@ -76,26 +76,26 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
* @param xml_document : Xml document to use for create the xml element. * @param xml_document : Xml document to use for create the xml element.
* @return : an xml element that describe this ellipse * @return : an xml element that describe this ellipse
*/ */
QDomElement PartEllipse::toXml(QDomDocument &xml_document) const const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element; QDomElement xml_element;
if (qFuzzyCompare(rect().width(), rect().height())) if (qFuzzyCompare(rect().width(), rect().height()))
{ {
xml_element = xml_document.createElement("circle"); xml_element = xml_document.createElement("circle");
xml_element.appendChild(createXmlProperty(xml_document, "diameter", rect().width())); xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
} }
else else
{ {
xml_element = xml_document.createElement("ellipse"); xml_element = xml_document.createElement("ellipse");
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); xml_element.setAttribute("width", QString("%1").arg(rect().width()));
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); xml_element.setAttribute("height", QString("%1").arg(rect().height()));
} }
QPointF top_left(sceneTopLeft()); QPointF top_left(sceneTopLeft());
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
stylesToXml(xml_document, xml_element); stylesToXml(xml_element);
return(xml_element); return(xml_element);
} }
@@ -105,51 +105,22 @@ QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
* Import the properties of this ellipse from a xml element. * Import the properties of this ellipse from a xml element.
* @param qde : Xml document to use. * @param qde : Xml document to use.
*/ */
bool PartEllipse::fromXml(const QDomElement &qde) void PartEllipse::fromXml(const QDomElement &qde)
{ {
stylesFromXml(qde); stylesFromXml(qde);
double x=0, y=0, width=0, height=0; qreal width, height;
if (qde.tagName() == "ellipse") if (qde.tagName() == "ellipse")
{ {
if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion || width = qde.attribute("width", "0").toDouble();
propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion) height = qde.attribute("height", "0").toDouble();
return false;
} }
else { else
if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion) width = height = qde.attribute("diameter", "0").toDouble();
return false;
height = width;
}
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || qde.attribute("y", "0").toDouble()),
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion) QSizeF(width, height));
return false;
m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height));
return true;
}
bool PartEllipse::valideXml(QDomElement& element) {
if (element.tagName() == "ellipse")
{
if (propertyDouble(element, "width") & PropertyFlags::NoValidConversion ||
propertyDouble(element, "height") & PropertyFlags::NoValidConversion)
return false;
}
else {
if (propertyDouble(element, "diameter") & PropertyFlags::NoValidConversion)
return false;
}
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) ||
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion))
return false;
return true;
} }
/** /**

View File

@@ -52,9 +52,8 @@ class PartEllipse : public AbstractPartEllipse
//Name and XML //Name and XML
QString name() const override { return(QObject::tr("ellipse", "element part name")); } QString name() const override { return(QObject::tr("ellipse", "element part name")); }
QString xmlName() const override { return(QString("ellipse")); } QString xmlName() const override { return(QString("ellipse")); }
QDomElement toXml (QDomDocument &) const override; const QDomElement toXml (QDomDocument &) const override;
bool fromXml (const QDomElement &) override; void fromXml (const QDomElement &) override;
static bool valideXml(QDomElement& element);
QPainterPath shape() const override; QPainterPath shape() const override;
QPainterPath shadowShape() const override; QPainterPath shadowShape() const override;
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();} void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}

View File

@@ -102,24 +102,22 @@ void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
* @param xml_document : Xml document to use for create the xml element. * @param xml_document : Xml document to use for create the xml element.
* @return an xml element that describe this line * @return an xml element that describe this line
*/ */
QDomElement PartLine::toXml(QDomDocument &xml_document) const const QDomElement PartLine::toXml(QDomDocument &xml_document) const
{ {
QPointF p1(sceneP1()); QPointF p1(sceneP1());
QPointF p2(sceneP2()); QPointF p2(sceneP2());
QDomElement xml_element = xml_document.createElement("line"); QDomElement xml_element = xml_document.createElement("line");
xml_element.setAttribute("x1", QString("%1").arg(p1.x()));
xml_element.appendChild(createXmlProperty(xml_document, "x1", p1.x())); xml_element.setAttribute("y1", QString("%1").arg(p1.y()));
xml_element.appendChild(createXmlProperty(xml_document, "y1", p1.y())); xml_element.setAttribute("x2", QString("%1").arg(p2.x()));
xml_element.appendChild(createXmlProperty(xml_document, "x2", p2.x())); xml_element.setAttribute("y2", QString("%1").arg(p2.y()));
xml_element.appendChild(createXmlProperty(xml_document, "y2", p2.y())); xml_element.setAttribute("end1", Qet::endTypeToString(first_end));
xml_element.setAttribute("length1", QString("%1").arg(first_length));
xml_element.appendChild(createXmlProperty(xml_document, "end1", Qet::endTypeToString(first_end))); xml_element.setAttribute("end2", Qet::endTypeToString(second_end));
xml_element.appendChild(createXmlProperty(xml_document, "length1", first_length)); xml_element.setAttribute("length2", QString("%1").arg(second_length));
xml_element.appendChild(createXmlProperty(xml_document, "end2", Qet::endTypeToString(second_end)));
xml_element.appendChild(createXmlProperty(xml_document, "length2", second_length));
stylesToXml(xml_document, xml_element); stylesToXml(xml_element);
return(xml_element); return(xml_element);
} }
@@ -128,48 +126,17 @@ QDomElement PartLine::toXml(QDomDocument &xml_document) const
* Import the properties of this line from a xml element. * Import the properties of this line from a xml element.
* @param qde : Xml document to use * @param qde : Xml document to use
*/ */
bool PartLine::fromXml(const QDomElement &qde) { void PartLine::fromXml(const QDomElement &qde) {
stylesFromXml(qde); stylesFromXml(qde);
m_line = QLineF(mapFromScene(qde.attribute("x1", "0").toDouble(),
qde.attribute("y1", "0").toDouble()),
mapFromScene(qde.attribute("x2", "0").toDouble(),
qde.attribute("y2", "0").toDouble()));
double x1 = 0, y1 = 0, x2 = 0, y2 = 0; first_end = Qet::endTypeFromString(qde.attribute("end1"));
if (propertyDouble(qde, "x1", &x1) == PropertyFlags::NoValidConversion || first_length = qde.attribute("length1", "1.5").toDouble();
propertyDouble(qde, "y1", &y1) == PropertyFlags::NoValidConversion || second_end = Qet::endTypeFromString(qde.attribute("end2"));
propertyDouble(qde, "x2", &x2) == PropertyFlags::NoValidConversion || second_length = qde.attribute("length2", "1.5").toDouble();
propertyDouble(qde, "y2", &y2) == PropertyFlags::NoValidConversion)
return false;
m_line = QLineF(mapFromScene(x1, y1),
mapFromScene(x2, y2));
QString s;
if (propertyString(qde, "end1", &s) != PropertyFlags::Success)
return false;
first_end = Qet::endTypeFromString(s);
if (propertyString(qde, "end2", &s) != PropertyFlags::Success)
return false;
first_end = Qet::endTypeFromString(s);
if (propertyDouble(qde, "length1", &first_length) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "length2", &second_length) == PropertyFlags::NoValidConversion)
return false;
return true;
}
bool PartLine::valideXml(QDomElement& element) const {
if (propertyDouble(element, "x1") ||
propertyDouble(element, "y1") ||
propertyDouble(element, "x2") ||
propertyDouble(element, "y2") ||
propertyString(element, "end1") ||
propertyString(element, "end2") ||
propertyDouble(element, "length1") ||
propertyDouble(element, "length2") )
return false;
return true;
} }
/** /**

View File

@@ -70,9 +70,8 @@ class PartLine : public CustomElementGraphicPart
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
QString name() const override { return(QObject::tr("ligne", "element part name")); } QString name() const override { return(QObject::tr("ligne", "element part name")); }
QString xmlName() const override { return(QString("line")); } QString xmlName() const override { return(QString("line")); }
QDomElement toXml(QDomDocument &) const override; const QDomElement toXml(QDomDocument &) const override;
bool fromXml(const QDomElement &) override; void fromXml(const QDomElement &) override;
bool valideXml(QDomElement& element) const;
virtual QPointF sceneP1() const; virtual QPointF sceneP1() const;
virtual QPointF sceneP2() const; virtual QPointF sceneP2() const;
QPainterPath shape() const override; QPainterPath shape() const override;
@@ -118,10 +117,10 @@ class PartLine : public CustomElementGraphicPart
/*****************/ /*****************/
Qet::EndType first_end; Qet::EndType first_end;
qreal first_length{1.5}; qreal first_length;
Qet::EndType second_end; Qet::EndType second_end;
qreal second_length{1.5}; qreal second_length;
QList<QPointF> saved_points_; QList<QPointF> saved_points_;
QLineF m_line; QLineF m_line;
int m_vector_index = -1; int m_vector_index = -1;

View File

@@ -82,37 +82,29 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
* Import the properties of this polygon from a xml element * Import the properties of this polygon from a xml element
* @param qde : Xml document to use * @param qde : Xml document to use
*/ */
bool PartPolygon::fromXml(const QDomElement &qde) void PartPolygon::fromXml(const QDomElement &qde)
{ {
stylesFromXml(qde); stylesFromXml(qde);
int error_counter = 0;
int i = 1; int i = 1;
while(true) while(true)
{ {
if (propertyDouble(qde, QString("x%1").arg(i)) == PropertyFlags::Success && if (QET::attributeIsAReal(qde, QString("x%1").arg(i)) &&\
propertyDouble(qde, QString("y%1").arg(i)) == PropertyFlags::Success) QET::attributeIsAReal(qde, QString("y%1").arg(i)))
i++; ++ i;
else break; else break;
} }
QPolygonF temp_polygon; QPolygonF temp_polygon;
double x, y;
for (int j = 1 ; j < i ; ++ j) for (int j = 1 ; j < i ; ++ j)
{ {
error_counter += propertyDouble(qde, QString("x%1").arg(j), &x); temp_polygon << QPointF(qde.attribute(QString("x%1").arg(j)).toDouble(),
error_counter += propertyDouble(qde, QString("y%1").arg(j), &y); qde.attribute(QString("y%1").arg(j)).toDouble());
if (error_counter)
return false;
temp_polygon << QPointF(x, y);
} }
m_polygon = temp_polygon; m_polygon = temp_polygon;
if (propertyBool(qde, "closed", &m_closed) != PropertyFlags::Success) m_closed = qde.attribute("closed") != "false";
return false;
return true;
} }
/** /**
@@ -121,28 +113,21 @@ bool PartPolygon::fromXml(const QDomElement &qde)
* @param xml_document : Xml document to use for create the xml element * @param xml_document : Xml document to use for create the xml element
* @return an xml element that describe this polygon * @return an xml element that describe this polygon
*/ */
QDomElement PartPolygon::toXml(QDomDocument &xml_document) const const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element = xml_document.createElement("polygon"); QDomElement xml_element = xml_document.createElement("polygon");
int i = 1; int i = 1;
foreach(QPointF point, m_polygon) { foreach(QPointF point, m_polygon) {
point = mapToScene(point); point = mapToScene(point);
xml_element.appendChild(createXmlProperty(xml_document, QString("x%1").arg(i), point.x())); xml_element.setAttribute(QString("x%1").arg(i), QString("%1").arg(point.x()));
xml_element.appendChild(createXmlProperty(xml_document, QString("y%1").arg(i), point.y())); xml_element.setAttribute(QString("y%1").arg(i), QString("%1").arg(point.y()));
++ i; ++ i;
} }
if (!m_closed) xml_element.setAttribute("closed", "false");
xml_element.appendChild(createXmlProperty(xml_document, "closed", m_closed)); stylesToXml(xml_element);
stylesToXml(xml_document, xml_element);
return(xml_element); return(xml_element);
} }
bool PartPolygon::valideXml(QDomElement& element) {
// TODO: implement
return true;
}
/** /**
* @brief PartPolygon::isUseless * @brief PartPolygon::isUseless
* @return true if this part is irrelevant and does not deserve to be Retained / registered. * @return true if this part is irrelevant and does not deserve to be Retained / registered.

View File

@@ -61,10 +61,8 @@ class PartPolygon : public CustomElementGraphicPart
QString name() const override { return(QObject::tr("polygone", "element part name")); } QString name() const override { return(QObject::tr("polygone", "element part name")); }
QString xmlName() const override { return(QString("polygon")); } QString xmlName() const override { return(QString("polygon")); }
bool fromXml(const QDomElement &) override; void fromXml(const QDomElement &) override;
QDomElement toXml(QDomDocument &) const override; const QDomElement toXml(QDomDocument &) const override;
static bool valideXml(QDomElement& element);
QPainterPath shape () const override; QPainterPath shape () const override;
QPainterPath shadowShape() const override; QPainterPath shadowShape() const override;

View File

@@ -77,15 +77,14 @@ void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
* @param xml_document : Xml document to use for create the xml element. * @param xml_document : Xml document to use for create the xml element.
* @return an xml element that describe this ellipse * @return an xml element that describe this ellipse
*/ */
QDomElement PartRectangle::toXml(QDomDocument &xml_document) const const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element = xml_document.createElement("rect"); QDomElement xml_element = xml_document.createElement("rect");
QPointF top_left(sceneTopLeft()); QPointF top_left(sceneTopLeft());
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); xml_element.setAttribute("width", QString("%1").arg(m_rect.width()));
xml_element.appendChild(createXmlProperty(xml_document, "width", m_rect.width())); xml_element.setAttribute("height", QString("%1").arg(m_rect.height()));
xml_element.appendChild(createXmlProperty(xml_document, "height", m_rect.height()));
QRectF rect = m_rect.normalized(); QRectF rect = m_rect.normalized();
qreal x = m_xRadius; qreal x = m_xRadius;
@@ -99,11 +98,8 @@ QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
xml_element.setAttribute("rx", QString::number(m_xRadius)); xml_element.setAttribute("rx", QString::number(m_xRadius));
xml_element.setAttribute("ry", QString::number(m_yRadius)); xml_element.setAttribute("ry", QString::number(m_yRadius));
xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius));
xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius));
stylesToXml(xml_document, xml_element); stylesToXml(xml_element);
return(xml_element); return(xml_element);
} }
@@ -112,45 +108,18 @@ QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
* Import the properties of this rectangle from a xml element. * Import the properties of this rectangle from a xml element.
* @param qde : Xml document to use. * @param qde : Xml document to use.
*/ */
bool PartRectangle::fromXml(const QDomElement &qde) void PartRectangle::fromXml(const QDomElement &qde)
{ {
stylesFromXml(qde); stylesFromXml(qde);
setPos(mapFromScene(qde.attribute("x", "0").toDouble(),
qde.attribute("y", "0").toDouble()));
double x=0, y=0, w=0, h=0, rx=0, ry=0; QRectF rect(QPointF(0,0), QSizeF(qde.attribute("width", "0").toDouble(),
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || qde.attribute("height", "0").toDouble()));
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
return false;
setPos(mapFromScene(x, y));
if (propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "width", &h) == PropertyFlags::NoValidConversion)
return false;
QRectF rect(QPointF(x,y), QSizeF(w, h));
setRect(rect.normalized()); setRect(rect.normalized());
setXRadius(qde.attribute("rx", "0").toDouble());
if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion || setYRadius(qde.attribute("ry", "0").toDouble());
propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion)
return false;
setXRadius(rx);
setYRadius(ry);
return true;
}
bool PartRectangle::valideXml(QDomElement& element) {
// parameters have default values so no value is not a non valid xml element
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) |
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion) |
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
(propertyDouble(element, "rx") & PropertyFlags::NoValidConversion) |
(propertyDouble(element, "ry") & PropertyFlags::NoValidConversion))
return false;
return true;
} }
/** /**

View File

@@ -60,9 +60,8 @@ class PartRectangle : public CustomElementGraphicPart
QString name () const override { return(QObject::tr("rectangle", "element part name")); } QString name () const override { return(QObject::tr("rectangle", "element part name")); }
QString xmlName () const override { return(QString("rect")); } QString xmlName () const override { return(QString("rect")); }
QDomElement toXml (QDomDocument &) const override; const QDomElement toXml (QDomDocument &) const override;
bool fromXml (const QDomElement &) override; void fromXml (const QDomElement &) override;
static bool valideXml(QDomElement& element);
QRectF rect() const; QRectF rect() const;
void setRect(const QRectF &rect); void setRect(const QRectF &rect);

View File

@@ -28,7 +28,6 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent) CustomElementGraphicPart(editor, parent)
{ {
d = new TerminalData(this); d = new TerminalData(this);
d->m_name = tr("terminal");
d->m_orientation = Qet::North; d->m_orientation = Qet::North;
d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
updateSecondPoint(); updateSecondPoint();
@@ -43,21 +42,10 @@ PartTerminal::~PartTerminal() {
Importe les proprietes d'une borne depuis un element XML Importe les proprietes d'une borne depuis un element XML
@param xml_elmt Element XML a lire @param xml_elmt Element XML a lire
*/ */
bool PartTerminal::fromXml(const QDomElement &xml_elmt) { void PartTerminal::fromXml(const QDomElement &xml_elmt) {
d->fromXml(xml_elmt);
QUuid uuid;
// update part and add uuid, which is used in the new version to connect terminals together
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
// to identify terminals
propertyUuid(xml_elmt, "uuid", &d->m_uuid);
if (!d->fromXml(xml_elmt))
return false;
setPos(d->m_pos); setPos(d->m_pos);
updateSecondPoint(); updateSecondPoint();
return true;
} }
/** /**
@@ -65,25 +53,8 @@ bool PartTerminal::fromXml(const QDomElement &xml_elmt) {
@param xml_document Document XML a utiliser pour creer l'element XML @param xml_document Document XML a utiliser pour creer l'element XML
@return un element XML decrivant la borne @return un element XML decrivant la borne
*/ */
QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
return d->toXml(xml_document);
QDomElement qdo = xml_document.createElement("terminal");
qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid));
d->m_pos = pos();
// Do not store terminal data in its own child
QDomElement terminalDataElement = d->toXml(xml_document);
for (int i=0; i < terminalDataElement.childNodes().length(); i++) {
qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made
}
return qdo;
}
bool PartTerminal::valideXml(QDomElement& element) {
return TerminalData::valideXml(element);
} }
/** /**

View File

@@ -57,10 +57,8 @@ class PartTerminal : public CustomElementGraphicPart
int type() const override { return Type; } int type() const override { return Type; }
QString name() const override { return d->m_name; } QString name() const override { return d->m_name; }
QString xmlName() const override { return(QString("terminal")); } QString xmlName() const override { return(QString("terminal")); }
bool fromXml(const QDomElement &) override; void fromXml(const QDomElement &) override;
QDomElement toXml(QDomDocument &) const override; const QDomElement toXml(QDomDocument &) const override;
static bool valideXml(QDomElement& element);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
QPainterPath shape() const override; QPainterPath shape() const override;

View File

@@ -55,49 +55,32 @@ PartText::~PartText() {
Importe les proprietes d'un texte statique depuis un element XML Importe les proprietes d'un texte statique depuis un element XML
@param xml_element Element XML a lire @param xml_element Element XML a lire
*/ */
bool PartText::fromXml(const QDomElement &xml_element) void PartText::fromXml(const QDomElement &xml_element)
{ {
int size; bool ok;
QString font;
if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound) if (xml_element.hasAttribute("size"))
{ {
if (size < 1) { int font_size = xml_element.attribute("size").toInt(&ok);
size = 20; if (!ok || font_size < 1) {
font_size = 20;
} }
QFont font_ = this->font(); QFont font_ = this->font();
font_.setPointSize(size); font_.setPointSize(font_size);
setFont(font_); setFont(font_);
} }
else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound) else if (xml_element.hasAttribute("font"))
{ {
QFont font_; QFont font_;
font_.fromString(font); font_.fromString(xml_element.attribute("font"));
setFont(font_); setFont(font_);
} else { }
return false;
}
QColor color; setDefaultTextColor(QColor(xml_element.attribute("color", "#000000")));
QString text; setPlainText(xml_element.attribute("text"));
propertyColor(xml_element, "color", &color); setPos(xml_element.attribute("x").toDouble(),
setDefaultTextColor(color); xml_element.attribute("y").toDouble());
setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble());
propertyString(xml_element, "text", &text);
setPlainText(text);
double x=0, y=0, rot=0;
if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion ||
propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion)
return false;
setPos(x, y);
if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion)
return false;
setRotation(rot);
return true;
} }
/** /**
@@ -105,44 +88,20 @@ bool PartText::fromXml(const QDomElement &xml_element)
@param xml_document Document XML a utiliser pour creer l'element XML @param xml_document Document XML a utiliser pour creer l'element XML
@return un element XML decrivant le texte statique @return un element XML decrivant le texte statique
*/ */
QDomElement PartText::toXml(QDomDocument &xml_document) const const QDomElement PartText::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element = xml_document.createElement(xmlName()); QDomElement xml_element = xml_document.createElement(xmlName());
xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x())); xml_element.setAttribute("x", QString::number(pos().x()));
xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y())); xml_element.setAttribute("y", QString::number(pos().y()));
xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText())); xml_element.setAttribute("text", toPlainText());
xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString())); xml_element.setAttribute("font", font().toString());
xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation())); xml_element.setAttribute("rotation", QString::number(rotation()));
xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name())); xml_element.setAttribute("color", defaultTextColor().name());
return(xml_element); return(xml_element);
} }
bool PartText::valideXml(QDomElement& element) {
if (propertyInteger(element, "size") == PropertyFlags::NotFound ||
propertyString(element, "font") == PropertyFlags::NotFound) {
return false;
}
if (propertyString(element, "color") == PropertyFlags::NoValidConversion)
return false;
if (propertyString(element, "text"))
return false;
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion)
return false;
if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion)
return false;
return true;
}
/** /**
@return Les coordonnees du point situe en bas a gauche du texte. @return Les coordonnees du point situe en bas a gauche du texte.
*/ */

View File

@@ -59,9 +59,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart
int type() const override { return Type; } int type() const override { return Type; }
QString name() const override { return(QObject::tr("texte", "element part name")); } QString name() const override { return(QObject::tr("texte", "element part name")); }
QString xmlName() const override { return(QString("text")); } QString xmlName() const override { return(QString("text")); }
bool fromXml(const QDomElement &) override; void fromXml(const QDomElement &) override;
static bool valideXml(QDomElement& element); const QDomElement toXml(QDomDocument &) const override;
QDomElement toXml(QDomDocument &) const override;
void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));} void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
bool isUseless() const override; bool isUseless() const override;
QRectF sceneGeometricRect() const override; QRectF sceneGeometricRect() const override;

View File

@@ -51,8 +51,9 @@ ElementsCollectionCache::ElementsCollectionCache(const QString &database_path, Q
cache_db_.exec("PRAGMA locking_mode = EXCLUSIVE"); cache_db_.exec("PRAGMA locking_mode = EXCLUSIVE");
cache_db_.exec("PRAGMA synchronous = OFF"); cache_db_.exec("PRAGMA synchronous = OFF");
//TODO This code remove old table with mtime for create table with uuid, created at version 0,5 //TODO This code remove old table with mtime for create table with uuid, created at version 0,5
//see to remove this code at version 0,6 or 0,7 when all users will table with uuid. //see to remove this code at version 0,6 or 0,7 when all users will table with uuid.
#pragma message("@TODO remove this code for qet 0.6 or later")
QSqlQuery table_name(cache_db_); QSqlQuery table_name(cache_db_);
if (table_name.exec("PRAGMA table_info(names)")) if (table_name.exec("PRAGMA table_info(names)"))
{ {

View File

@@ -108,7 +108,8 @@ QDomDocument ExportElementTextPattern::xmlConf() const
root.setAttribute("name", m_name); root.setAttribute("name", m_name);
doc.appendChild(root); doc.appendChild(root);
QDomElement elmt = m_element->toXml(doc); QHash<Terminal *, int> H;
QDomElement elmt = m_element->toXml(doc, H);
QDomElement texts = elmt.firstChildElement("dynamic_texts"); QDomElement texts = elmt.firstChildElement("dynamic_texts");
QDomElement groups = elmt.firstChildElement("texts_groups"); QDomElement groups = elmt.firstChildElement("texts_groups");

View File

@@ -559,6 +559,7 @@ void ElementPictureFactory::setPainterStyle(const QDomElement &dom, QPainter &pa
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
const QStringList styles = dom.attribute("style").split(";", QString::SkipEmptyParts); const QStringList styles = dom.attribute("style").split(";", QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
const QStringList styles = dom.attribute("style").split(";", Qt::SkipEmptyParts); const QStringList styles = dom.attribute("style").split(";", Qt::SkipEmptyParts);
#endif #endif
QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$"); QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$");

85
sources/machine_info.cpp Normal file
View File

@@ -0,0 +1,85 @@
/*
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 "machine_info.h"
#include <QScreen>
#include <QApplication>
/**
@brief Machine_info::Machine_info
@param parent
*/
Machine_info::Machine_info(QObject *parent) : QObject(parent)
{
init_get_Screen_info();
}
/**
@brief Machine_info::init_get_Screen_info
Finds the largest screen and saves the values
*/
void Machine_info::init_get_Screen_info()
{
const auto screens = qApp->screens();
for (int ii = 0; ii < screens.count(); ++ii)
{
if(
Max_screen_width
<
screens[ii]->geometry().width()
*
screens[ii]->devicePixelRatio()
)
{
Max_screen_width =
screens[ii]->geometry().width()
*
screens[ii]->devicePixelRatio();
}
if(
Max_screen_height
<
screens[ii]->geometry().height()
*
screens[ii]->devicePixelRatio()
)
{
Max_screen_height =
screens[ii]->geometry().height()
*
screens[ii]->devicePixelRatio();
}
}
}
/**
@brief Machine_info::get_max_screen_width
@return max screen width
*/
int32_t Machine_info::get_max_screen_width()
{
return Max_screen_width;
}
/**
@brief Machine_info::get_max_screen_height
@return max screen height
*/
int32_t Machine_info::get_max_screen_height()
{
return Max_screen_height;
}

45
sources/machine_info.h Normal file
View File

@@ -0,0 +1,45 @@
/*
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 MACHINE_INFO_H
#define MACHINE_INFO_H
#include <QObject>
/**
@brief The Machine_info class
This class hold information from your PC.
*/
class Machine_info : public QObject
{
Q_OBJECT
public:
explicit Machine_info(QObject *parent = nullptr);
int32_t get_max_screen_width();
int32_t get_max_screen_height();
signals:
private:
void init_get_Screen_info();
int32_t Max_screen_width;
int32_t Max_screen_height;
};
#endif // MACHINE_INFO_H

View File

@@ -22,29 +22,32 @@
#include <QStyleFactory> #include <QStyleFactory>
/** /**
* @brief main @brief main
* Main function of QElectroTech Main function of QElectroTech
* @param argc : number of paramètres @param argc : number of parameters
* @param argv : paramètres \~French number of paramètres
* @return \~ @param argv : parameters
*/ \~French paramètres
\~ @return exit code
*/
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
//Some setup, notably to use with QSetting. //Some setup, notably to use with QSetting.
QCoreApplication::setOrganizationName("QElectroTech"); QCoreApplication::setOrganizationName("QElectroTech");
QCoreApplication::setOrganizationDomain("qelectrotech.org"); QCoreApplication::setOrganizationDomain("qelectrotech.org");
QCoreApplication::setApplicationName("QElectroTech"); QCoreApplication::setApplicationName("QElectroTech");
//Creation and execution of the application //Creation and execution of the application
//HighDPI //HighDPI
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #pragma message("@TODO remove code for QT 5.6 or later")
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#else #else
qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("auto")); qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("auto"));
#endif #endif
SingleApplication app(argc, argv, true); SingleApplication app(argc, argv, true);
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
//Handle the opening of QET when user double click on a .qet .elmt .tbt file //Handle the opening of QET when user double click on a .qet .elmt .tbt file
//or drop these same files to the QET icon of the dock //or drop these same files to the QET icon of the dock
MacOSXOpenEvent open_event; MacOSXOpenEvent open_event;
app.installEventFilter(&open_event); app.installEventFilter(&open_event);
app.setStyle(QStyleFactory::create("Fusion")); app.setStyle(QStyleFactory::create("Fusion"));
@@ -53,17 +56,19 @@ int main(int argc, char **argv)
if (app.isSecondary()) if (app.isSecondary())
{ {
QStringList arg_list = app.arguments(); QStringList arg_list = app.arguments();
//Remove the first argument, it's the binary file //Remove the first argument, it's the binary file
arg_list.takeFirst(); arg_list.takeFirst();
QETArguments qetarg(arg_list); QETArguments qetarg(arg_list);
QString message = "launched-with-args: " + QET::joinWithSpaces(QStringList(qetarg.arguments())); QString message = "launched-with-args: " + QET::joinWithSpaces(
QStringList(qetarg.arguments()));
app.sendMessage(message.toUtf8()); app.sendMessage(message.toUtf8());
return 0; return 0;
} }
QETApp qetapp; QETApp qetapp;
QETApp::instance()->installEventFilter(&qetapp); QETApp::instance()->installEventFilter(&qetapp);
QObject::connect(&app, &SingleApplication::receivedMessage, &qetapp, &QETApp::receiveMessage); QObject::connect(&app, &SingleApplication::receivedMessage,
&qetapp, &QETApp::receiveMessage);
return app.exec(); return app.exec();
} }

View File

@@ -69,6 +69,7 @@ bool nomenclature::saveToCSVFile()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
stream << getNomenclature() << endl; stream << getNomenclature() << endl;
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
stream << getNomenclature() << &Qt::endl(stream); stream << getNomenclature() << &Qt::endl(stream);
#endif #endif
} }

View File

@@ -17,313 +17,16 @@
*/ */
#include "propertiesinterface.h" #include "propertiesinterface.h"
#include <QDebug> /**
@brief PropertiesInterface::PropertiesInterface
/*! */
* Available property types
*/
namespace {
const QString integerS = "int";
const QString doubleS = "double";
const QString boolS = "bool";
const QString stringS = "string";
const QString uuidS = "uuid";
const QString colorS = "color";
}
PropertiesInterface::PropertiesInterface() PropertiesInterface::PropertiesInterface()
{ {
} }
bool PropertiesInterface::valideXml(QDomElement& element) {
qDebug(QString("ValideXml() is not implemented. File: %1, Line: %2").arg(__FILE__).arg(__LINE__).toStdString().data());
return false;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", stringS);
p.setAttribute("value", value);
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", stringS);
p.setAttribute("value", value);
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", integerS);
p.setAttribute("value", QString::number(value));
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", doubleS);
p.setAttribute("value", QString::number(value));
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", boolS);
p.setAttribute("value", QString::number(value));
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", uuidS);
p.setAttribute("value", value.toString());
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", colorS);
p.setAttribute("value", value.name());
return p;
}
QDomElement PropertiesInterface::property(const QDomElement& e, const QString& name) {
for (int i=0; i < e.childNodes().count(); i++) {
QDomElement child = e.childNodes().at(i).toElement();
if (!validXmlProperty(child))
continue; // there might also non property childs
if (child.attribute("name") == name)
return child;
}
return QDomElement();
}
/*!
* \brief PropertiesInterface::attribute
* Returns the property with the name \p attribute_name and type \p type
* \param e Xml element which contains the property
* \param attribute_name
* \param type Type of the property
* \param attr
* \return
*/
bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr) {
QDomElement p = property(e, attribute_name);
if (p.isNull()) {
// check if legacy property is available,
// where the property is inside the element as attribute
if (!e.hasAttribute(attribute_name)) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available";
return false;
}
*attr = e.attribute(attribute_name);
} else {
if (p.attribute("type") != type) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type;
return false;
}
*attr = p.attribute("value");
}
return true;
}
/*!
* \brief PropertiesInterface::propertyInteger
* Reads an interger from the XML element.
* \param e DomElement which contains the property attribute
* \param attribute_name Name of the attribute
* \param entier Return value if success
* \return True if reading an integer was successful, else False. If the attribute was not found,
* \p entier is not valid and the return value is False
*/
PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) {
QString attr;
if (!attribute(e, attribute_name, integerS, &attr)) {
return PropertyFlags::NotFound;
}
// verifie la validite de l'attribut
bool ok;
int tmp = attr.toInt(&ok);
if (!ok) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
if (entier != nullptr)
*entier = tmp;
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) {
QString attr;
if (!attribute(e, attribute_name, doubleS, &attr)) {
return PropertyFlags::NotFound;
}
// verifie la validite de l'attribut
bool ok;
double tmp = attr.toDouble(&ok);
if (!ok) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << doubleS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
if (reel != nullptr)
*reel = tmp;
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) {
QString attr;
if (!attribute(e, attribute_name, boolS, &attr)) {
return PropertyFlags::NotFound;
}
// verifie la validite de l'attribut
bool ok;
bool tmp = attr.toInt(&ok);
if (!ok) {
if (attr == "true" || attr == "1")
tmp = true;
else if (attr == "false" || attr == "0")
tmp = false;
else {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
}
if (boolean != nullptr)
*boolean = tmp;
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) {
QString attr;
if (!attribute(e, attribute_name, colorS, &attr)) {
return PropertyFlags::NotFound;
}
// verifie la validite de l'attribut
QColor tmp = QColor(attr);
if (!tmp.isValid()) {
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << colorS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
if (color != nullptr)
*color = tmp;
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) {
QString attr;
if (!attribute(e, attribute_name, uuidS, &attr)) {
return PropertyFlags::NotFound;
}
if (QUuid(attr).isNull()){
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << uuidS << ". value: " << attr;
return PropertyFlags::NoValidConversion;
}
if (uuid != nullptr)
*uuid = QUuid(attr);
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) {
QString attr;
if (!attribute(e, attribute_name, stringS, &attr)) {
return PropertyFlags::NotFound;
}
// verifie la validite de l'attribut
if (string != nullptr)
*string = attr;
return PropertyFlags::Success;
}
/*!
* \brief PropertiesInterface::validXmlProperty
* Check if the Xml element contains the needed fields
* \param e Xml Property
* \return True if name, type, value attribute are available, else false
*/
bool PropertiesInterface::validXmlProperty(const QDomElement& e) {
if (!e.hasAttribute("name"))
return false;
if (!e.hasAttribute("type"))
return false;
if (!e.hasAttribute("value"))
return false;
return true;
}
/** /**
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") @brief PropertiesInterface::~PropertiesInterface
en orientation. Si la chaine fait plusieurs caracteres, seul le
premier est pris en compte. En cas d'incoherence, Qet::North est
retourne.
@param s Chaine de caractere cense representer une orientation
@return l'orientation designee par la chaine de caractere
*/ */
Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) { PropertiesInterface::~PropertiesInterface()
QChar c = s[0]; {
// in some cases/ old projects? (affuteuse_250h.qet) numbers instead of characters are
// used for the orientation
if (c == 'e' || c == '1') return(Qet::East);
else if (c == 's' || c == '2') return(Qet::South);
else if (c == 'w' || c == '3') return (Qet::West);
else return(Qet::North); // c == '0'
}
/**
@param o une orientation
@return une chaine de caractere representant l'orientation
*/
QString PropertiesInterface::orientationToString(Qet::Orientation o) {
QString ret;
switch(o) {
case Qet::North: ret = "n"; break;
case Qet::East : ret = "e"; break;
case Qet::South: ret = "s"; break;
case Qet::West : ret = "w"; break;
}
return(ret);
} }

View File

@@ -20,79 +20,48 @@
#include <QString> #include <QString>
#include <QSettings> #include <QSettings>
#include <QColor>
#include <QDomElement> #include <QDomElement>
#include <limits>
#include "qet.h"
#include <QUuid>
/** /**
* @brief The PropertiesInterface class @brief The PropertiesInterface class
* This class is an interface for have common way to use properties in QElectroTech This class is an interface for have common way
*/ to use properties in QElectroTech
*/
class PropertiesInterface class PropertiesInterface
{ {
public: public:
PropertiesInterface(); PropertiesInterface();
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre virtual ~PropertiesInterface();
virtual void toSettings (QSettings &settings, const QString& = QString()) const {Q_UNUSED(settings)}; /**
virtual void fromSettings (const QSettings &settings, const QString& = QString()) {Q_UNUSED(settings)}; @brief toSettings
// Save/load properties to xml element Save properties to setting file.
virtual QDomElement toXml (QDomDocument &xml_document) const =0; @param settings : is use for prefix a word
virtual bool fromXml (const QDomElement &xml_element) =0; befor the name of each paramètre
static bool valideXml(QDomElement& element); */
virtual void toSettings (QSettings &settings,
/*! const QString = QString()) const =0;
* Use this functions to add properties to the xml document /**
*/ @brief fromSettings
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value); load properties to setting file.
static QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value); @param settings : is use for prefix a word
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value); befor the name of each paramètre
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value); */
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value); virtual void fromSettings (const QSettings &settings,
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value); const QString = QString()) =0;
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value); /**
@brief toXml
static QDomElement property(const QDomElement& e, const QString& name); Save properties to xml element
static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); @param xml_document
@return QDomElement
enum PropertyFlags { */
Success = 0, virtual QDomElement toXml (QDomDocument &xml_document) const =0;
NotFound = 1, /**
NoValidConversion = 2, @brief fromXml
// = 4 load properties to xml element
}; @param xml_element
@return true / false
/*! */
* Try not using the default Value feature. It is better to initialize the class members in the class definition! virtual bool fromXml (const QDomElement &xml_element) =0;
*/
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr);
static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr);
static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr);
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr);
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr);
static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr);
static bool validXmlProperty(const QDomElement& e);
QVariant XmlProperty(const QDomElement& element);
/**
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
en orientation. Si la chaine fait plusieurs caracteres, seul le
premier est pris en compte. En cas d'incoherence, Qet::North est
retourne.
@param s Chaine de caractere cense representer une orientation
@return l'orientation designee par la chaine de caractere
*/
static Qet::Orientation orientationFromString(const QString &s);
/**
@param o une orientation
@return une chaine de caractere representant l'orientation
*/
static QString orientationToString(Qet::Orientation o);
}; };
#endif // PROPERTIESINTERFACE_H #endif // PROPERTIESINTERFACE_H

View File

@@ -20,6 +20,9 @@
#include <QString> #include <QString>
/**
@brief The ReportProperties class
*/
class ReportProperties class ReportProperties
{ {
public: public:

View File

@@ -3,16 +3,16 @@
#include <QGraphicsObject> #include <QGraphicsObject>
TerminalData::TerminalData(): TerminalData::TerminalData():
PropertiesInterface() PropertiesInterface()
{ {
init(); init();
} }
TerminalData::TerminalData(QGraphicsObject *parent): TerminalData::TerminalData(QGraphicsObject *parent):
PropertiesInterface(), PropertiesInterface(),
q(parent) q(parent)
{ {
init(); init();
} }
void TerminalData::init() { void TerminalData::init() {
@@ -23,86 +23,114 @@ TerminalData::~TerminalData()
} }
/**
@brief TerminalData::setParent
@param parent
*/
void TerminalData::setParent(QGraphicsObject* parent) void TerminalData::setParent(QGraphicsObject* parent)
{ {
q = parent; q = parent;
} }
void TerminalData::toSettings(QSettings& settings, const QString&) const /**
@brief TerminalData::toSettings
Save properties to setting file.
QString is use for prefix a word befor the name of each paramètre
@param settings UNUSED
*/
void TerminalData::toSettings(QSettings &settings, const QString) const
{ {
Q_UNUSED(settings); Q_UNUSED(settings);
} }
void TerminalData::fromSettings(const QSettings& settings, const QString&) /**
@brief TerminalData::fromSettings
load properties to setting file.
QString is use for prefix a word befor the name of each paramètre
@param settings UNUSED
*/
void TerminalData::fromSettings(const QSettings &settings, const QString)
{ {
Q_UNUSED(settings); Q_UNUSED(settings);
} }
/**
@brief TerminalData::toXml
Save properties to xml element
write the name, number, position and orientation of the terminal
to xml_element
@note This method is only called from the PartTerminal
and should never called from the Terminal class
@param xml_document
@return xml_element : DomElement with
the name, number, position and orientation of the terminal
*/
QDomElement TerminalData::toXml(QDomDocument &xml_document) const QDomElement TerminalData::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element = xml_document.createElement("terminaldata"); QDomElement xml_element = xml_document.createElement("terminal");
// write the position of the terminal
// ecrit la position de la borne
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
// m_pos cannot be stored, because in the partterminal it will not be updated. // Write name and number to XML
// In PartTerminal m_pos is the position of the dock, in Terminal m_pos is the second side of the terminal xml_element.setAttribute("uuid", m_uuid.toString());
// This is hold for legacy compability reason xml_element.setAttribute("name", m_name);
xml_element.appendChild(createXmlProperty(xml_document, "x", m_pos.x()));
xml_element.appendChild(createXmlProperty(xml_document, "y", m_pos.y()));
xml_element.appendChild(createXmlProperty(xml_document, "name", m_name));
xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation)));
return(xml_element); // write the orientation of the terminal
// ecrit l'orientation de la borne
xml_element.setAttribute("orientation",
Qet::orientationToString(m_orientation));
return(xml_element);
} }
bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True /**
@brief TerminalData::fromXml
load properties to xml element
@note This method is only called from the PartTerminal
and should never called from the Terminal class
@param xml_element
@return true if succeeded / false if the attribute is not real
*/
bool TerminalData::fromXml (const QDomElement &xml_element)
{ {
// lit la position de la borne qreal term_x = 0.0;
qreal term_x = 0.0, term_y = 0.0; qreal term_y = 0.0;
if (propertyDouble(xml_element, "x", &term_x)) // reads the position of the terminal
return false; // lit la position de la borne
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
return false;
if (propertyDouble(xml_element, "y", &term_y)) if (!QET::attributeIsAReal(xml_element, "y", &term_y))
return false; return false;
m_pos = QPointF(term_x, term_y); m_pos = QPointF(term_x, term_y);
// emit posFromXML(QPointF(term_x, term_y)); //emit posFromXML(QPointF(term_x, term_y));
// do not write uuid from this class, because only PartTerminal::fromXml need QString uuid = xml_element.attribute("uuid");
// to write it to xml file. Terminal::fromXml does not need. // update part and add uuid, which is used in the new version
// to connect terminals together
// if the attribute not exists, means, the element is created with an
// older version of qet. So use the legacy approach
// to identify terminals
if (!uuid.isEmpty())
m_uuid = QUuid(uuid);
m_name = xml_element.attribute("name");
//if (propertyString(xml_element, "name", &m_name)) // read the orientation of the terminal
// return false; // lit l'orientation de la borne
propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20" m_orientation = Qet::orientationFromString(
xml_element.attribute("orientation"));
QString o; return true;
if (propertyString(xml_element, "orientation", &o))
return false;
// lit l'orientation de la borne
m_orientation = orientationFromString(o);
return true;
}
bool TerminalData::valideXml(const QDomElement& xml_element) {
if (propertyDouble(xml_element, "x"))
return false;
if (propertyDouble(xml_element, "y"))
return false;
// legacy elements do not have an uuid
// if (propertyUuid(xml_element, "uuid"))
// return false;
//if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
// return false;
if (propertyString(xml_element, "orientation"))
return false;
return true;
} }

View File

@@ -18,64 +18,70 @@ class QGraphicsObject;
*/ */
class TerminalData : public PropertiesInterface class TerminalData : public PropertiesInterface
{ {
public: public:
TerminalData(); TerminalData();
TerminalData(QGraphicsObject* parent); TerminalData(QGraphicsObject* parent);
~TerminalData(); ~TerminalData();
void init(); void init();
void setParent(QGraphicsObject* parent); void setParent(QGraphicsObject* parent);
void toSettings(QSettings &settings,
const QString = QString()) const override;
void fromSettings(const QSettings &settings,
const QString = QString()) override;
QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override;
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre // must be public, because this class is a private member
void toSettings(QSettings &settings, const QString& = QString()) const override; // of PartTerminal/Terminal and they must access this data
void fromSettings(const QSettings &settings, const QString& = QString()) override; public:
// Save/load properties to xml element /**
// This method is only called from the PartTerminal and should never called from the Terminal class @brief m_orientation
QDomElement toXml(QDomDocument &xml_element) const override; Orientation of the terminal
bool fromXml(const QDomElement &xml_element) override; */
Qet::Orientation m_orientation;
/**
@brief second_point
Position of the second point of the terminal
in scene coordinates
*/
QPointF second_point;
/**
@brief m_uuid
Uuid of the terminal.
static bool valideXml(const QDomElement &xml_element); In elementscene.cpp an element gets a new uuid when
saving the element. In the current state
each connection is made by using the local position
of the terminal and a dynamic id. In the new
case, each terminal should have it's own uuid to
identify it uniquely. When changing each time this
uuid, the conductor after updating the part is anymore
valid. So if in the loaded document a uuid exists,
use this one and don't create a new one.
*/
QUuid m_uuid;
/**
@brief m_name
Name of the element.
It can be used to create wiring harness tables
*/
QString m_name;
// must be public, because this class is a private member of PartTerminal/Terminal and they must /**
// access this data @brief m_pos
public: Position of the terminal. The second point is calculated
/*! from this position and the orientation
* \brief m_orientation @note
* Orientation of the terminal Important: this variable is only updated during read
*/ from xml and not during mouse move!
Qet::Orientation m_orientation{Qet::Orientation::North}; It is used to store the initial position so that
/*! PartTerminal and Terminal have access to it.
* \brief second_point */
* Position of the second point of the terminal in scene coordinates QPointF m_pos;
*/ private:
QPointF second_point{0,0}; QGraphicsObject* q{nullptr};
/*!
* \brief m_uuid
* Uuid of the terminal.
*
* In elementscene.cpp an element gets a new uuid when saving the element. In the current state
* each connection is made by using the local position of the terminal and a dynamic id. In the new
* case, each terminal should have it's own uuid to identify it uniquely. When changing each time this
* uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists,
* use this one and don't create a new one.
*/
QUuid m_uuid; // default is an invalid uuid.
/*!
* \brief m_name
* Name of the element. It can be used to create wiring harness tables
*/
QString m_name;
/*!
* \brief m_pos
* Position of the terminal. The second point is calculated from this position and the orientation
* Important: this variable is only updated during read from xml and not during mouse move!
* It is used to store the initial position so that PartTerminal and Terminal have access to it.
*/
QPointF m_pos{0,0};
private:
QGraphicsObject* q{nullptr};
}; };
#endif // TERMINALDATA_H #endif // TERMINALDATA_H

View File

@@ -25,6 +25,14 @@
*/ */
XRefProperties::XRefProperties() XRefProperties::XRefProperties()
{ {
m_show_power_ctc = true;
m_display = Cross;
m_snap_to = Bottom;
m_prefix_keys << "power" << "delay" << "switch";
m_master_label = "%f-%l%c";
m_slave_label = "(%f-%l%c)";
m_offset = 0;
m_xref_pos = Qt::AlignBottom;
} }
/** /**
@@ -33,7 +41,7 @@ XRefProperties::XRefProperties()
* @param settings: QSettings to use * @param settings: QSettings to use
* @param prefix: prefix before properties name * @param prefix: prefix before properties name
*/ */
void XRefProperties::toSettings(QSettings &settings, const QString &prefix) const { void XRefProperties::toSettings(QSettings &settings, const QString prefix) const {
settings.setValue(prefix + "showpowerctc", m_show_power_ctc); settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
QString display = m_display == Cross? "cross" : "contacts"; QString display = m_display == Cross? "cross" : "contacts";
settings.setValue(prefix + "displayhas", display); settings.setValue(prefix + "displayhas", display);
@@ -61,7 +69,7 @@ void XRefProperties::toSettings(QSettings &settings, const QString &prefix) cons
* @param settings: QSettings to use * @param settings: QSettings to use
* @param prefix: prefix before properties name * @param prefix: prefix before properties name
*/ */
void XRefProperties::fromSettings(const QSettings &settings, const QString &prefix) void XRefProperties::fromSettings(const QSettings &settings, const QString prefix)
{ {
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool(); m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
QString display = settings.value(prefix + "displayhas", "cross").toString(); QString display = settings.value(prefix + "displayhas", "cross").toString();
@@ -88,60 +96,58 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString &pref
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const { QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
QDomElement xml_element = xml_document.createElement("xref"); QDomElement xml_element = xml_document.createElement("xref");
xml_element.setAttribute("type", m_key);
xml_element.appendChild(createXmlProperty(xml_document, "type", m_key)); xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc)); QString display = m_display == Cross? "cross" : "contacts";
xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts")); xml_element.setAttribute("displayhas", display);
xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label")); QString snap = m_snap_to == Bottom? "bottom" : "label";
xml_element.setAttribute("snapto", snap);
QString xrefpos;
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos));
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>(); int offset = m_offset;
xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos))); xml_element.setAttribute("offset", QString::number(offset));
xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset)); QString master_label = m_master_label;
xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label)); xml_element.setAttribute("master_label", master_label);
xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label)); QString slave_label = m_slave_label;
xml_element.setAttribute("slave_label", slave_label);
foreach (QString key, m_prefix.keys()) { foreach (QString key, m_prefix.keys()) {
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key))); xml_element.setAttribute(key + "prefix", m_prefix.value(key));
} }
return xml_element; return xml_element;
} }
/** RETURNS True /**
* @brief XRefProperties::fromXml * @brief XRefProperties::fromXml
* Load from xml * Load from xml
* @param xml_element: QDomElement to use for load * @param xml_element: QDomElement to use for load
*/ */
bool XRefProperties::fromXml(const QDomElement &xml_element) { bool XRefProperties::fromXml(const QDomElement &xml_element) {
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
QString display = xml_element.attribute("displayhas", "cross");
display == "cross"? m_display = Cross : m_display = Contacts;
QString snap = xml_element.attribute("snapto", "label");
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) QString xrefpos = xml_element.attribute("xrefpos","Left");
return false;
QString display; QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
display == "cross"? m_display = Cross : m_display = Contacts;
}
if(xml_element.hasAttribute("xrefpos"))
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xml_element.attribute("xrefpos").toStdString().data()));
else
m_xref_pos = Qt::AlignBottom;
QString snap; m_offset = xml_element.attribute("offset", "0").toInt();
if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) { m_master_label = xml_element.attribute("master_label", "%f-%l%c");
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
}
QString xrefpos;
if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) {
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data()));
}
// TODO: why it compiles without this true??
propertyInteger(xml_element, "offset", &m_offset);
propertyString(xml_element, "master_label", &m_master_label);
propertyString(xml_element, "slave_label", &m_slave_label);
QString value;
foreach (QString key, m_prefix_keys) { foreach (QString key, m_prefix_keys) {
if (!propertyString(xml_element, key + "prefix", &value)); m_prefix.insert(key, xml_element.attribute(key + "prefix"));
m_prefix.insert(key, value);
} }
return true; return true;
} }

View File

@@ -40,8 +40,8 @@ class XRefProperties : public PropertiesInterface
Label Label
}; };
void toSettings (QSettings &settings, const QString& = QString()) const override; void toSettings (QSettings &settings, const QString = QString()) const override;
void fromSettings (const QSettings &settings, const QString& = QString()) override; void fromSettings (const QSettings &settings, const QString = QString()) override;
QDomElement toXml (QDomDocument &xml_document) const override; QDomElement toXml (QDomDocument &xml_document) const override;
bool fromXml(const QDomElement &xml_element) override; bool fromXml(const QDomElement &xml_element) override;
@@ -76,15 +76,15 @@ class XRefProperties : public PropertiesInterface
void setKey(QString& key) {m_key = key;} void setKey(QString& key) {m_key = key;}
private: private:
bool m_show_power_ctc{true}; bool m_show_power_ctc;
DisplayHas m_display{Cross}; DisplayHas m_display;
SnapTo m_snap_to{Bottom}; SnapTo m_snap_to;
Qt::AlignmentFlag m_xref_pos{Qt::AlignBottom}; Qt::AlignmentFlag m_xref_pos;
QHash <QString, QString> m_prefix; QHash <QString, QString> m_prefix;
QStringList m_prefix_keys{"power","delay","switch"}; QStringList m_prefix_keys;
QString m_master_label{"%f-%l%c"}; QString m_master_label;
QString m_slave_label{"(%f-%l%c)"}; QString m_slave_label;
int m_offset{0}; int m_offset;
QString m_key; QString m_key;
}; };

View File

@@ -25,6 +25,37 @@
#include <QSaveFile> #include <QSaveFile>
#include <QTextStream> #include <QTextStream>
/**
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
en orientation. Si la chaine fait plusieurs caracteres, seul le
premier est pris en compte. En cas d'incoherence, Qet::North est
retourne.
@param s Chaine de caractere cense representer une orientation
@return l'orientation designee par la chaine de caractere
*/
Qet::Orientation Qet::orientationFromString(const QString &s) {
QChar c = s[0];
if (c == 'e') return(Qet::East);
else if (c == 's') return(Qet::South);
else if (c == 'w') return (Qet::West);
else return(Qet::North);
}
/**
@param o une orientation
@return une chaine de caractere representant l'orientation
*/
QString Qet::orientationToString(Qet::Orientation o) {
QString ret;
switch(o) {
case Qet::North: ret = "n"; break;
case Qet::East : ret = "e"; break;
case Qet::South: ret = "s"; break;
case Qet::West : ret = "w"; break;
}
return(ret);
}
/** /**
Indique si deux orientations de Borne sont sur le meme axe (Vertical / Horizontal). Indique si deux orientations de Borne sont sur le meme axe (Vertical / Horizontal).
@param a La premiere orientation de Borne @param a La premiere orientation de Borne
@@ -145,6 +176,7 @@ bool QET::orthogonalProjection(const QPointF &point, const QLineF &line, QPointF
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QLineF::IntersectType it = line.intersect(perpendicular_line, &intersection_point); // ### Qt 6: remove QLineF::IntersectType it = line.intersect(perpendicular_line, &intersection_point); // ### Qt 6: remove
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
QLineF::IntersectType it = line.intersects(perpendicular_line, &intersection_point); QLineF::IntersectType it = line.intersects(perpendicular_line, &intersection_point);
#endif #endif
@@ -419,6 +451,7 @@ QStringList QET::splitWithSpaces(const QString &string) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), QString::SkipEmptyParts); QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), Qt::SkipEmptyParts); QStringList escaped_strings = string.split(QRegExp("[^\\]?(?:\\\\)* "), Qt::SkipEmptyParts);
#endif #endif

View File

@@ -2220,19 +2220,19 @@ void QETDiagramEditor::generateTerminalBlock()
success = process->startDetached("qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached("qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached("qet_tb_generator"); success = process->startDetached("qet_tb_generator", {("")});
} }
if (openedProjects().count()){ if (openedProjects().count()){
success = process->startDetached(QDir::homePath() + "/Application Data/qet/qet_tb_generator.exe", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached(QDir::homePath() + "/Application Data/qet/qet_tb_generator.exe", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached(QDir::homePath() + "/Application Data/qet/qet_tb_generator.exe"); success = process->startDetached(QDir::homePath() + "/Application Data/qet/qet_tb_generator.exe", {("")});
} }
if (openedProjects().count()){ if (openedProjects().count()){
success = process->startDetached(QDir::homePath() + "/qet_tb_generator.exe", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached(QDir::homePath() + "/qet_tb_generator.exe", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached(QDir::homePath() + "/qet_tb_generator.exe"); success = process->startDetached(QDir::homePath() + "/qet_tb_generator.exe", {("")});
} }
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
@@ -2240,13 +2240,13 @@ void QETDiagramEditor::generateTerminalBlock()
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.8/bin/qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.8/bin/qet_tb_generator"); success = process->startDetached("/Library/Frameworks/Python.framework/Versions/3.8/bin/qet_tb_generator", {("")});
} }
if (openedProjects().count()){ if (openedProjects().count()){
success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator.app", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator.app", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator.app"); success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator.app", {("")});
} }
#else #else
@@ -2254,13 +2254,13 @@ void QETDiagramEditor::generateTerminalBlock()
success = process->startDetached("qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached("qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached("qet_tb_generator"); success = process->startDetached("qet_tb_generator", {("")});
} }
if (openedProjects().count()){ if (openedProjects().count()){
success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())}); success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator", {(QETDiagramEditor::currentProjectView()->project()->filePath())});
} }
else { else {
success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator"); success = process->startDetached(QDir::homePath() + "/.qet/qet_tb_generator", {("")});
} }
#endif #endif

View File

@@ -309,8 +309,6 @@ void ProjectDBModel::dataBaseUpdated()
auto new_record = m_record; auto new_record = m_record;
m_record = original_record; m_record = original_record;
//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()) if (new_record.size() != m_record.size())
{ {
emit beginResetModel(); emit beginResetModel();

View File

@@ -61,6 +61,56 @@ void QetGraphicsTableItem::adjustTableToFolio(QetGraphicsTableItem *table, QMarg
table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok
} }
/**
* @brief QetGraphicsTableItem::checkInsufficientRowsCount
* Check if the number of rows of @table + linked table is enough to display all
* content of the model, if not open a dialog to advise user what to do.
* @param table
*/
void QetGraphicsTableItem::checkInsufficientRowsCount(QetGraphicsTableItem *table)
{
if (!table->diagram() || !table->model()) {
return;
}
auto first_table = table;
while (first_table->previousTable())
first_table = first_table->previousTable();
if (first_table->displayNRow() <= 0) //displayed rows is unlimited
return;
int count_ = first_table->displayNRow();
bool several_table = false;
while (first_table->nextTable())
{
several_table = true;
first_table = first_table->nextTable();
if (first_table->displayNRow() <= 0) { //displayed rows is unlimited
return;
} else {
count_ += first_table->displayNRow();
first_table->displayNRowOffset();
}
}
if (count_ < first_table->model()->rowCount())
{
QWidget *parent = first_table->diagram()->views().first() ? first_table->diagram()->views().first() : nullptr;
QString text;
if (several_table) {
text = tr("Les information à afficher sont supérieurs à la quantité maximal pouvant être affiché par les tableaux.\n"
"Veuillez ajouter un nouveau tableau ou regler les tableaux existant afin d'afficher l'integralité des informations.");
} else {
text = tr("Les information à afficher sont supérieurs à la quantité maximal pouvant être affiché par le tableau.\n"
"Veuillez ajouter un nouveau tableau ou regler le tableau existant afin d'afficher l'integralité des informations.");
}
QMessageBox::information(parent, tr("Limitation de tableau"), text);
}
}
/** /**
* @brief QetGraphicsTableItem::QetGraphicsTableItem * @brief QetGraphicsTableItem::QetGraphicsTableItem
* Default constructor * Default constructor
@@ -601,6 +651,10 @@ QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange chan
void QetGraphicsTableItem::modelReseted() { void QetGraphicsTableItem::modelReseted() {
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>()); dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
setToMinimumHeight(); setToMinimumHeight();
if (!previousTable()) { //this is the head table
checkInsufficientRowsCount(this);
}
} }
/** /**

View File

@@ -48,6 +48,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
public : public :
static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0)); static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0));
static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table);
public: public:
QetGraphicsTableItem(QGraphicsItem *parent= nullptr); QetGraphicsTableItem(QGraphicsItem *parent= nullptr);

View File

@@ -52,6 +52,8 @@ GraphicsTablePropertiesEditor::GraphicsTablePropertiesEditor(QetGraphicsTableIte
if (table) { if (table) {
setTable(table); setTable(table);
} }
ui->m_info_label->setStyleSheet("QLabel {color : red; }");
} }
/** /**
@@ -281,6 +283,8 @@ void GraphicsTablePropertiesEditor::updateUi()
} }
} }
updateInfoLabel();
auto margin = QETUtils::marginsFromString(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString()); auto margin = QETUtils::marginsFromString(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
ui->m_header_top_margin ->setValue(margin.top()); ui->m_header_top_margin ->setValue(margin.top());
ui->m_header_left_margin ->setValue(margin.left()); ui->m_header_left_margin ->setValue(margin.left());
@@ -306,6 +310,38 @@ void GraphicsTablePropertiesEditor::updateUi()
setUpEditConnection(); setUpEditConnection();
} }
void GraphicsTablePropertiesEditor::updateInfoLabel()
{
auto table_ = m_table_item;
while (table_->previousTable()) { table_ = table_->previousTable();}
int count_ = 0;
bool infinite = false;
if (table_->displayNRow() <= 0) {
infinite = true;
} else {
count_ = table_->displayNRow();
}
while (table_->nextTable())
{
table_ = table_->nextTable();
if (table_->displayNRow() <= 0) {
infinite = true;
} else {
count_ += table_->displayNRow();
}
}
auto value = m_table_item->model()->rowCount() - count_;
if (value > 0 && !infinite) {
ui->m_info_label->setText(tr("<center>ATTENTION :</center>\n il manque %1 lignes afin d'afficher l'intégralité des informations").arg(value));
ui->m_info_label->show();
} else {
ui->m_info_label->hide();
}
}
/** /**
* @brief GraphicsTablePropertiesEditor::setUpEditConnection * @brief GraphicsTablePropertiesEditor::setUpEditConnection
*/ */
@@ -333,10 +369,12 @@ void GraphicsTablePropertiesEditor::setUpEditConnection()
m_edit_connection << connect(m_table_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), 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(m_header_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply);
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
m_edit_connection << connect(m_table_button_group, QOverload<int>::of(&QButtonGroup::idClicked), this, &GraphicsTablePropertiesEditor::apply); m_edit_connection << connect(m_table_button_group, QOverload<int>::of(&QButtonGroup::idClicked), this, &GraphicsTablePropertiesEditor::apply);
m_edit_connection << connect(m_header_button_group, QOverload<int>::of(&QButtonGroup::idClicked), this, &GraphicsTablePropertiesEditor::apply); m_edit_connection << connect(m_header_button_group, QOverload<int>::of(&QButtonGroup::idClicked), this, &GraphicsTablePropertiesEditor::apply);
#endif #endif
m_edit_connection << connect(ui->m_display_n_row_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply); m_edit_connection << connect(ui->m_display_n_row_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply);
m_edit_connection << connect(ui->m_display_n_row_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::updateInfoLabel);
} }
} }

View File

@@ -52,6 +52,7 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
void on_m_header_font_pb_clicked(); void on_m_header_font_pb_clicked();
void on_m_table_font_pb_clicked(); void on_m_table_font_pb_clicked();
virtual void updateUi() override; virtual void updateUi() override;
void updateInfoLabel();
void on_m_table_name_le_textEdited(const QString &arg1); void on_m_table_name_le_textEdited(const QString &arg1);
void on_m_previous_table_cb_activated(int index); void on_m_previous_table_cb_activated(int index);
void on_m_previous_pb_clicked(); void on_m_previous_pb_clicked();

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>524</width> <width>524</width>
<height>600</height> <height>623</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -40,40 +40,17 @@
<string>Géometrie et lignes</string> <string>Géometrie et lignes</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0,0,0,0,0"> <layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0,0,0,0,0">
<item row="0" column="6">
<widget class="QPushButton" name="m_apply_geometry_to_linked_table_pb">
<property name="toolTip">
<string>Appliquer la géometrie à tous les tableaux liée à celui-ci</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/22x22/all_pages.png</normaloff>:/ico/22x22/all_pages.png</iconset>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="4"> <item row="1" column="4">
<widget class="QComboBox" name="m_previous_table_cb"> <widget class="QSpinBox" name="m_display_n_row_sb">
<property name="insertPolicy"> <property name="specialValueText">
<enum>QComboBox::InsertAtBottom</enum> <string>Toutes</string>
</property>
<property name="maximum">
<number>999</number>
</property> </property>
<item>
<property name="text">
<string>Aucun</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="1" column="6"> <item row="2" column="6">
<widget class="QPushButton" name="m_next_pb"> <widget class="QPushButton" name="m_next_pb">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@@ -93,14 +70,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="2" column="4">
<widget class="QSpinBox" name="m_x_pos"> <widget class="QComboBox" name="m_previous_table_cb">
<property name="maximum"> <property name="insertPolicy">
<number>10000</number> <enum>QComboBox::InsertAtBottom</enum>
</property> </property>
<item>
<property name="text">
<string>Aucun</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@@ -113,20 +95,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="7"> <item row="1" column="5">
<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="0" column="5">
<widget class="QPushButton" name="m_auto_geometry_pb"> <widget class="QPushButton" name="m_auto_geometry_pb">
<property name="toolTip"> <property name="toolTip">
<string>Ajuster le tableau au folio</string> <string>Ajuster le tableau au folio</string>
@@ -140,7 +109,47 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1" colspan="6"> <item row="2" column="7">
<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="2" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" 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="1" column="2">
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="4" column="1" colspan="6">
<widget class="QWidget" name="widget_3" native="true"> <widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin"> <property name="leftMargin">
@@ -158,47 +167,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="2" 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 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="4">
<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="1" column="3">
<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>
<item row="1" column="5">
<widget class="QPushButton" name="m_previous_pb"> <widget class="QPushButton" name="m_previous_pb">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@@ -218,16 +187,60 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="2">
<widget class="QLabel" name="label_7"> <widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QPushButton" name="m_apply_geometry_to_linked_table_pb">
<property name="toolTip">
<string>Appliquer la géometrie à tous les tableaux liée à celui-ci</string>
</property>
<property name="text"> <property name="text">
<string>Y :</string> <string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/22x22/all_pages.png</normaloff>:/ico/22x22/all_pages.png</iconset>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tableau précédent :</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="3">
<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 row="3" column="1" colspan="6">
<widget class="QLabel" name="m_info_label">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@@ -76,7 +76,14 @@ class ConductorXmlRetroCompatibility
*/ */
Conductor::Conductor(Terminal *p1, Terminal* p2) : Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1), terminal1(p1),
terminal2(p2) terminal2(p2),
m_mouse_over(false),
m_text_item(nullptr),
segments(nullptr),
m_moving_segment(false),
modified_path(false),
has_to_save_profile(false),
must_highlight_(Conductor::None)
{ {
//set Zvalue at 11 to be upper than the DiagramImageItem and element //set Zvalue at 11 to be upper than the DiagramImageItem and element
setZValue(11); setZValue(11);
@@ -566,16 +573,36 @@ ConductorTextItem *Conductor::textItem() const {
@return true si l'element XML represente bien un Conducteur ; false sinon @return true si l'element XML represente bien un Conducteur ; false sinon
*/ */
bool Conductor::valideXml(QDomElement &e){ bool Conductor::valideXml(QDomElement &e){
// verifie le nom du tag
// // TODO: seems to short! (see fromXML) if (e.tagName() != "conductor") return(false);
// if (propertyDouble(e, "x") ||
// propertyDouble(e, "y")) // verifie la presence des attributs minimaux
// return false; if (!e.hasAttribute("terminal1")) return(false);
if (!e.hasAttribute("terminal2")) return(false);
// if (propertyBool(e, "freezeLabel"))
// return false; bool conv_ok;
// parse l'abscisse
return true; if (e.hasAttribute("element1")) {
if (QUuid(e.attribute("element1")).isNull())
return false;
if (QUuid(e.attribute("terminal1")).isNull())
return false;
} else {
e.attribute("terminal1").toInt(&conv_ok);
if (!conv_ok) return(false);
}
// parse l'ordonnee
if (e.hasAttribute("element2")) {
if (QUuid(e.attribute("element2")).isNull())
return false;
if (QUuid(e.attribute("terminal2")).isNull())
return false;
} else {
e.attribute("terminal2").toInt(&conv_ok);
if (!conv_ok) return(false);
}
return(true);
} }
/** /**
@@ -946,13 +973,10 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
* @param e * @param e
* @return true is loading success else return false * @return true is loading success else return false
*/ */
bool Conductor::fromXml(const QDomElement &dom_element) bool Conductor::fromXml(QDomElement &dom_element)
{ {
// TODO: seems to short! setPos(dom_element.attribute("x", nullptr).toDouble(),
double x=0, y=0; dom_element.attribute("y", nullptr).toDouble());
propertyDouble(dom_element, "x", &x);
propertyDouble(dom_element, "y", &y);
setPos(x, y);
bool return_ = pathFromXml(dom_element); bool return_ = pathFromXml(dom_element);
@@ -966,77 +990,13 @@ bool Conductor::fromXml(const QDomElement &dom_element)
else else
m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers")); m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers"));
propertyBool(dom_element, "freezeLabel", &m_freeze_label); m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false;
setProperties(pr); setProperties(pr);
return return_; return return_;
} }
// does not support legacy method
// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
QDomElement Conductor::toXml(QDomDocument & doc) const {
QDomElement dom_element = doc.createElement("conductor");
dom_element.appendChild(createXmlProperty(doc, "x", pos().x()));
dom_element.appendChild(createXmlProperty(doc, "y", pos().y()));
// Terminal is uniquely identified by the uuid of the terminal and the element
QUuid terminal = terminal1->uuid();
QUuid terminalParent = terminal1->parentElement()->uuid();
if (terminalParent.isNull() || terminal.isNull()) {
// legacy when the terminal does not have a valid uuid
// do not store element1 information, because this is used to determine in the fromXml
// process that legacy file format
dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->ID()));
} else {
dom_element.appendChild(createXmlProperty(doc, "element1", terminalParent));
dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal));
}
terminal = terminal2->uuid();
terminalParent = terminal2->parentElement()->uuid();
if (terminalParent.isNull() || terminal.isNull()) {
// legacy when the terminal does not have a valid uuid
// do not store element1 information, because this is used to determine in the fromXml
// process that legacy file format
dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->ID()));
} else {
dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid()));
dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid()));
}
dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label));
// on n'exporte les segments du conducteur que si ceux-ci ont
// ete modifies par l'utilisateur
if (modified_path)
{
// parcours et export des segments
QDomElement current_segment;
foreach(ConductorSegment *segment, segmentsList())
{
current_segment = doc.createElement("segment");
current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal() ? "horizontal": "vertical"));
current_segment.appendChild(createXmlProperty(doc, "length", segment -> length()));
dom_element.appendChild(current_segment);
}
}
QDomElement dom_seq = m_autoNum_seq.toXml(doc); // swquentialNumbers tag
dom_element.appendChild(dom_seq);
// Export the properties and text
QDomElement conductorProperties = m_properties.toXml(doc);
for (int i=0; i < conductorProperties.childNodes().count(); i++) {
QDomNode node = conductorProperties.childNodes().at(i).cloneNode(); // cloneNode() is important!
dom_element.appendChild(node);
}
m_text_item->toXml(doc, dom_element);
return(dom_element);
}
/** /**
Exporte les caracteristiques du conducteur sous forme d'une element XML. Exporte les caracteristiques du conducteur sous forme d'une element XML.
@param d Le document XML a utiliser pour creer l'element XML @param d Le document XML a utiliser pour creer l'element XML
@@ -1044,61 +1004,61 @@ QDomElement Conductor::toXml(QDomDocument & doc) const {
bornes dans le document XML et leur adresse en memoire bornes dans le document XML et leur adresse en memoire
@return Un element XML representant le conducteur @return Un element XML representant le conducteur
*/ */
//QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int> &table_adr_id) const QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int> &table_adr_id) const
//{ {
// QDomElement dom_element = dom_document.createElement("conductor"); QDomElement dom_element = dom_document.createElement("conductor");
// dom_element.setAttribute("x", QString::number(pos().x())); dom_element.setAttribute("x", QString::number(pos().x()));
// dom_element.setAttribute("y", QString::number(pos().y())); dom_element.setAttribute("y", QString::number(pos().y()));
// // Terminal is uniquely identified by the uuid of the terminal and the element // Terminal is uniquely identified by the uuid of the terminal and the element
// if (terminal1->uuid().isNull()) { if (terminal1->uuid().isNull()) {
// // legacy method to identify the terminal // legacy method to identify the terminal
// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
// } else { } else {
// dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString()); dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
// dom_element.setAttribute("terminal1", terminal1->uuid().toString()); dom_element.setAttribute("terminal1", terminal1->uuid().toString());
// } }
// if (terminal2->uuid().isNull()) { if (terminal2->uuid().isNull()) {
// // legacy method to identify the terminal // legacy method to identify the terminal
// dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
// } else { } else {
// dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString()); dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
// dom_element.setAttribute("terminal2", terminal2->uuid().toString()); dom_element.setAttribute("terminal2", terminal2->uuid().toString());
// } }
// dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false"); dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
// // on n'exporte les segments du conducteur que si ceux-ci ont // on n'exporte les segments du conducteur que si ceux-ci ont
// // ete modifies par l'utilisateur // ete modifies par l'utilisateur
// if (modified_path) if (modified_path)
// { {
// // parcours et export des segments // parcours et export des segments
// QDomElement current_segment; QDomElement current_segment;
// foreach(ConductorSegment *segment, segmentsList()) foreach(ConductorSegment *segment, segmentsList())
// { {
// current_segment = dom_document.createElement("segment"); current_segment = dom_document.createElement("segment");
// current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical"); current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
// current_segment.setAttribute("length", QString("%1").arg(segment -> length())); current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
// dom_element.appendChild(current_segment); dom_element.appendChild(current_segment);
// } }
// } }
// QDomElement dom_seq = m_autoNum_seq.toXml(dom_document); QDomElement dom_seq = m_autoNum_seq.toXml(dom_document);
// dom_element.appendChild(dom_seq); dom_element.appendChild(dom_seq);
// // Export the properties and text // Export the properties and text
// m_properties.toXml(dom_document); m_properties. toXml(dom_element);
// if(m_text_item->wasMovedByUser()) if(m_text_item->wasMovedByUser())
// { {
// dom_element.setAttribute("userx", QString::number(m_text_item->pos().x())); dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));
// dom_element.setAttribute("usery", QString::number(m_text_item->pos().y())); dom_element.setAttribute("usery", QString::number(m_text_item->pos().y()));
// } }
// if(m_text_item->wasRotateByUser()) if(m_text_item->wasRotateByUser())
// dom_element.setAttribute("rotation", QString::number(m_text_item->rotation())); dom_element.setAttribute("rotation", QString::number(m_text_item->rotation()));
// return(dom_element); return(dom_element);
//} }
/** /**
* @brief Conductor::pathFromXml * @brief Conductor::pathFromXml
@@ -1117,21 +1077,14 @@ bool Conductor::pathFromXml(const QDomElement &e) {
if (current_segment.isNull() || current_segment.tagName() != "segment") continue; if (current_segment.isNull() || current_segment.tagName() != "segment") continue;
// le segment doit avoir une longueur // le segment doit avoir une longueur
qreal segment_length; if (!current_segment.hasAttribute("length")) continue;
if (propertyDouble(current_segment, "length", & segment_length))
continue;
bool isHorizontal = false; // cette longueur doit etre un reel
QString orientation; bool ok;
if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) { qreal segment_length = current_segment.attribute("length").toDouble(&ok);
if (orientation == "horizontal") if (!ok) continue;
isHorizontal = true;
} else {
qDebug() << "PathFromXML failed";
return false;
}
if (isHorizontal) { if (current_segment.attribute("orientation") == "horizontal") {
segments_x << segment_length; segments_x << segment_length;
segments_y << 0.0; segments_y << 0.0;
} else { } else {
@@ -1722,6 +1675,7 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(const bool all_diagram,
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
other_conductors += other_conductors_list_t.toSet(); other_conductors += other_conductors_list_t.toSet();
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
other_conductors += QSet<Conductor*>(other_conductors_list_t.begin(),other_conductors_list_t.end()); other_conductors += QSet<Conductor*>(other_conductors_list_t.begin(),other_conductors_list_t.end());
#endif #endif
} }

View File

@@ -19,7 +19,6 @@
#define CONDUCTOR_H #define CONDUCTOR_H
#include "conductorproperties.h" #include "conductorproperties.h"
#include "propertiesinterface.h"
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
#include "assignvariables.h" #include "assignvariables.h"
@@ -40,7 +39,7 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
This class represents a conductor, i.e. a wire between two element This class represents a conductor, i.e. a wire between two element
terminals. terminals.
*/ */
class Conductor : public QGraphicsObject, public PropertiesInterface class Conductor : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
@@ -96,9 +95,8 @@ class Conductor : public QGraphicsObject, public PropertiesInterface
public: public:
static bool valideXml (QDomElement &); static bool valideXml (QDomElement &);
bool fromXml (const QDomElement &) override; bool fromXml (QDomElement &);
//QDomElement toXml (QDomDocument &, QHash<Terminal *, int> &) const; QDomElement toXml (QDomDocument &, QHash<Terminal *, int> &) const;
QDomElement toXml (QDomDocument &doc) const override;
private: private:
bool pathFromXml(const QDomElement &); bool pathFromXml(const QDomElement &);
@@ -156,28 +154,28 @@ class Conductor : public QGraphicsObject, public PropertiesInterface
QVector<QetGraphicsHandlerItem *> m_handler_vector; QVector<QetGraphicsHandlerItem *> m_handler_vector;
int m_vector_index = -1; int m_vector_index = -1;
bool m_mouse_over{false}; bool m_mouse_over;
/// Functional properties /// Functional properties
ConductorProperties m_properties; ConductorProperties m_properties;
/// Text input for non simple, non-singleline conductors /// Text input for non simple, non-singleline conductors
ConductorTextItem *m_text_item{nullptr}; ConductorTextItem *m_text_item;
/// Segments composing the conductor /// Segments composing the conductor
ConductorSegment *segments{nullptr}; ConductorSegment *segments;
/// Attributs related to mouse interaction /// Attributs related to mouse interaction
bool m_moving_segment{false}; bool m_moving_segment;
int moved_point; int moved_point;
qreal m_previous_z_value; qreal m_previous_z_value;
ConductorSegment *m_moved_segment; ConductorSegment *m_moved_segment;
QPointF before_mov_text_pos_; QPointF before_mov_text_pos_;
/// Whether the conductor was manually modified by users /// Whether the conductor was manually modified by users
bool modified_path{false}; bool modified_path;
/// Whether the current profile should be saved as soon as possible /// Whether the current profile should be saved as soon as possible
bool has_to_save_profile{false}; bool has_to_save_profile;
/// conductor profile: "photography" of what the conductor is supposed to look /// conductor profile: "photography" of what the conductor is supposed to look
/// like - there is one profile per kind of traject /// like - there is one profile per kind of traject
ConductorProfilesGroup conductor_profiles; ConductorProfilesGroup conductor_profiles;
/// Define whether and how the conductor should be highlighted /// Define whether and how the conductor should be highlighted
Highlight must_highlight_{Conductor::None}; Highlight must_highlight_;
bool m_valid; bool m_valid;
bool m_freeze_label = false; bool m_freeze_label = false;

View File

@@ -27,7 +27,9 @@
*/ */
ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) : ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
DiagramTextItem(parent_conductor), DiagramTextItem(parent_conductor),
parent_conductor_(parent_conductor) parent_conductor_(parent_conductor),
moved_by_user_(false),
rotate_by_user_(false)
{ {
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
} }
@@ -59,36 +61,21 @@ Conductor *ConductorTextItem::parentConductor() const {
return(parent_conductor_); return(parent_conductor_);
} }
void ConductorTextItem::toXml(QDomDocument& doc, QDomElement& e) {
if(moved_by_user_)
{
e.appendChild(PropertiesInterface::createXmlProperty(doc, "userx", pos().x()));
e.appendChild(PropertiesInterface::createXmlProperty(doc, "usery", pos().y()));
}
if(rotate_by_user_)
e.appendChild(PropertiesInterface::createXmlProperty(doc, "rotation", rotation()));
}
/** /**
* @brief ConductorTextItem::fromXml * @brief ConductorTextItem::fromXml
* Read the properties stored in the xml element given in parameter * Read the properties stored in the xml element given in parameter
* @param e * @param e
*/ */
void ConductorTextItem::fromXml(const QDomElement &e) { void ConductorTextItem::fromXml(const QDomElement &e) {
if (e.hasAttribute("userx")) {
double userx=0, usery=0; setPos(e.attribute("userx").toDouble(),
if (PropertiesInterface::propertyDouble(e, "userx", &userx) == PropertiesInterface::PropertyFlags::Success && e.attribute("usery").toDouble());
PropertiesInterface::propertyDouble(e, "usery", &usery) == PropertiesInterface::PropertyFlags::Success) { moved_by_user_ = true;
setPos(userx, usery); }
moved_by_user_ = true; if (e.hasAttribute("rotation")) {
} setRotation(e.attribute("rotation").toDouble());
rotate_by_user_ = true;
double rotation; }
if (PropertiesInterface::propertyDouble(e, "rotation", &rotation) == PropertiesInterface::PropertyFlags::Success) {
setRotation(rotation);
rotate_by_user_ = true;
}
} }
/** /**

View File

@@ -42,7 +42,6 @@ class ConductorTextItem : public DiagramTextItem
enum { Type = UserType + 1006 }; enum { Type = UserType + 1006 };
Conductor *parentConductor() const; Conductor *parentConductor() const;
void fromXml(const QDomElement &) override; void fromXml(const QDomElement &) override;
void toXml(QDomDocument& doc, QDomElement& e);
int type() const override { return Type; } int type() const override { return Type; }
virtual bool wasMovedByUser() const; virtual bool wasMovedByUser() const;
virtual bool wasRotateByUser() const; virtual bool wasRotateByUser() const;
@@ -62,8 +61,8 @@ class ConductorTextItem : public DiagramTextItem
// attributes // attributes
private: private:
Conductor *parent_conductor_; Conductor *parent_conductor_;
bool moved_by_user_{false}; bool moved_by_user_;
bool rotate_by_user_{false}; bool rotate_by_user_;
QPointF before_mov_pos_; QPointF before_mov_pos_;
}; };
#endif #endif

View File

@@ -20,8 +20,6 @@
#include "qetapp.h" #include "qetapp.h"
#include "richtext/richtexteditor_p.h" #include "richtext/richtexteditor_p.h"
#include "diagram.h" #include "diagram.h"
#include "dynamicelementtextitem.h"
/** /**
* @brief DiagramTextItem::DiagramTextItem * @brief DiagramTextItem::DiagramTextItem
@@ -213,24 +211,12 @@ QRectF DiagramTextItem::frameRect() const
void DiagramTextItem::setHtml(const QString &text) void DiagramTextItem::setHtml(const QString &text)
{ {
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
}
}
QGraphicsTextItem::setHtml(text); QGraphicsTextItem::setHtml(text);
m_is_html = true; m_is_html = true;
} }
void DiagramTextItem::setPlainText(const QString &text) void DiagramTextItem::setPlainText(const QString &text)
{ {
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
}
}
QGraphicsTextItem::setPlainText(text); QGraphicsTextItem::setPlainText(text);
m_is_html = false; m_is_html = false;
} }
@@ -249,16 +235,6 @@ bool DiagramTextItem::isHtml() const {
*/ */
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
DynamicElementTextItem* abc = dynamic_cast<DynamicElementTextItem*>(this);
if (abc) {
if (abc->searchedElement) {
int stop = 1;
QString text = toPlainText();
qDebug() << text;
}
}
painter -> setRenderHint(QPainter::Antialiasing, false); painter -> setRenderHint(QPainter::Antialiasing, false);
QGraphicsTextItem::paint(painter, option, widget); QGraphicsTextItem::paint(painter, option, widget);

View File

@@ -212,7 +212,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
setColor(QColor(dom_color.text())); setColor(QColor(dom_color.text()));
//Force the update of the displayed text //Force the update of the displayed text
setTextFrom(m_text_from); // TODO: does not update because there is a retrun inside if the textfrom argument is the same as m_text_from setTextFrom(m_text_from);
QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(), QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(),
dom_elmt.attribute("y", QString::number(0)).toDouble()); dom_elmt.attribute("y", QString::number(0)).toDouble());
@@ -323,12 +323,9 @@ DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const {
*/ */
void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_from) void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_from)
{ {
if (searchedElement)
int stop = true;
if(m_text_from == text_from) if(m_text_from == text_from)
return; return;
setNoEditable(text_from == UserText? false : true); setNoEditable(text_from == UserText? false : true);
clearFormulaConnection(); clearFormulaConnection();
@@ -389,9 +386,6 @@ QString DynamicElementTextItem::text() const {
*/ */
void DynamicElementTextItem::setText(const QString &text) void DynamicElementTextItem::setText(const QString &text)
{ {
if (m_text == "14" && text == "")
int a = 54;
m_text_old = m_text;
m_text = text; m_text = text;
if(m_text_from == DynamicElementTextItem::UserText) if(m_text_from == DynamicElementTextItem::UserText)
setPlainText(m_text); setPlainText(m_text);
@@ -408,9 +402,6 @@ void DynamicElementTextItem::setInfoName(const QString &info_name)
QString old_info_name = m_info_name; QString old_info_name = m_info_name;
m_info_name = info_name; m_info_name = info_name;
if (searchedElement)
int stop = true;
if(old_info_name == "label") if(old_info_name == "label")
{ {
@@ -1330,17 +1321,6 @@ void DynamicElementTextItem::updateXref()
void DynamicElementTextItem::setPlainText(const QString &text) void DynamicElementTextItem::setPlainText(const QString &text)
{ {
DynamicElementTextItem* abc = this;
int abcedwer;
abcedwer += 5;
if (text == "14")
searchedElement = true;
if (text == "")
int a = 5;
if (m_text_old == "14" && m_text == "")
int a = 5;
if (toPlainText() == text) if (toPlainText() == text)
return; return;

View File

@@ -103,7 +103,6 @@ class DynamicElementTextItem : public DiagramTextItem
void setPlainText(const QString &text); void setPlainText(const QString &text);
void setTextWidth(qreal width); void setTextWidth(qreal width);
void setXref_item(Qt::AlignmentFlag m_exHrefPos); void setXref_item(Qt::AlignmentFlag m_exHrefPos);
bool searchedElement{false};
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
@@ -142,7 +141,6 @@ class DynamicElementTextItem : public DiagramTextItem
m_other_report; m_other_report;
QPointer <Conductor> m_watched_conductor; QPointer <Conductor> m_watched_conductor;
QString m_text, QString m_text,
m_text_old,
m_info_name, m_info_name,
m_composite_text, m_composite_text,
m_report_formula, m_report_formula,
@@ -152,7 +150,7 @@ class DynamicElementTextItem : public DiagramTextItem
QMetaObject::Connection m_report_formula_con; QMetaObject::Connection m_report_formula_con;
QList<QMetaObject::Connection> m_formula_connection, QList<QMetaObject::Connection> m_formula_connection,
m_update_slave_Xref_connection; m_update_slave_Xref_connection;
QColor m_user_color{QColor()}; QColor m_user_color;
bool m_frame = false, bool m_frame = false,
m_first_scene_change = true; m_first_scene_change = true;
CrossRefItem *m_Xref_item = nullptr; CrossRefItem *m_Xref_item = nullptr;

View File

@@ -65,13 +65,12 @@ class ElementXmlRetroCompatibility
/** /**
* @brief Element::Element * @brief Element::Element
* New element from xml
* @param location, location of this element * @param location, location of this element
* @param parent, parent graphics item * @param parent, parent graphics item
* @param state, state of the instanciation * @param state, state of the instanciation
*/ */
Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) : Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) :
QetGraphicsItem(parent), QetGraphicsItem(parent),
m_link_type (link_type), m_link_type (link_type),
m_location (location) m_location (location)
{ {
@@ -84,8 +83,7 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s
} }
} }
int elmt_state; int elmt_state;
qDebug() << "\tCollection Path: " << location.collectionPath(); buildFromXml(location.xml(), &elmt_state);
buildFromXml(location.xml(), &elmt_state); // build from the collection definition
if (state) { if (state) {
*state = elmt_state; *state = elmt_state;
} }
@@ -338,7 +336,7 @@ void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *o
/** /**
* @brief Element::buildFromXml * @brief Element::buildFromXml
* Build this element from an xml description (from the collection) * Build this element from an xml description
* @param xml_def_elmt * @param xml_def_elmt
* @param state * @param state
* Optional pointer which define the status of build * Optional pointer which define the status of build
@@ -419,8 +417,7 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (elmts.tagName() == "description") if (elmts.tagName() == "description")
{ {
//Minor workaround to find if there is a "input" tagg as label. //Minor workaround to find if there is a "input" tagg as label.
//If not, we set the tagg "label" to the first "input. Why one must have a tagg label? //If not, we set the tagg "label" to the first "input.
// is label a required field?
QList <QDomElement> input_field; QList <QDomElement> input_field;
bool have_label = false; bool have_label = false;
for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input")) for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input"))
@@ -441,16 +438,12 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
QDomElement qde = n.toElement(); QDomElement qde = n.toElement();
if (qde.isNull()) if (qde.isNull())
continue; continue;
qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName();
if (parseElement(qde)) { // TODO: why lines are not parsed here? if (parseElement(qde)) {
qDebug() << "\t\t\tParsing Element success";
++ parsed_elements_count; ++ parsed_elements_count;
} }
else else
{ {
qDebug() << "\t\t\tParsing Element no success";
if (state) if (state)
*state = 7; *state = 7;
m_state = QET::GIOK; m_state = QET::GIOK;
@@ -474,11 +467,13 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_state = QET::GIOK; m_state = QET::GIOK;
return(false); return(false);
} }
else
if (state) {
*state = 0; if (state)
m_state = QET::GIOK; *state = 0;
return(true); m_state = QET::GIOK;
return(true);
}
} }
/** /**
@@ -575,11 +570,13 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
Terminal *Element::parseTerminal(const QDomElement &dom_element) Terminal *Element::parseTerminal(const QDomElement &dom_element)
{ {
if (!Terminal::valideXml(dom_element)) TerminalData* data = new TerminalData();
if (!data->fromXml(dom_element)) {
delete data;
return nullptr; return nullptr;
}
Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); // does not matter which values are typed in here, because they get overwritten by the fromXML() function Terminal *new_terminal = new Terminal(data, this);
new_terminal->fromXml(dom_element);
m_terminals << new_terminal; m_terminals << new_terminal;
//Sort from top to bottom and left to rigth //Sort from top to bottom and left to rigth
@@ -591,7 +588,7 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
return (a->dockConductor().y() < b->dockConductor().y()); return (a->dockConductor().y() < b->dockConductor().y());
}); });
return(new_terminal); // TODO: makes not sense return(new_terminal);
} }
/** /**
@@ -639,41 +636,24 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
ce recensement servira lors de la mise en place des fils ce recensement servira lors de la mise en place des fils
*/ */
QList<QDomElement> liste_terminals; // terminals in the element in the diagram QList<QDomElement> liste_terminals;
foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) { foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) {
if (Terminal::valideXml(qde)) liste_terminals << qde; if (Terminal::valideXml(qde)) liste_terminals << qde;
} }
QHash<int, Terminal *> priv_id_adr; QHash<int, Terminal *> priv_id_adr;
int terminals_non_trouvees = 0; int terminals_non_trouvees = 0;
// The added childs from the collection now must match with the terminals from the diagram. Iterate through foreach(QGraphicsItem *qgi, childItems()) {
// all Terminals in the collection and in the diagram to link them together
for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs?
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) { if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
bool terminal_trouvee = false; bool terminal_trouvee = false;
for(QDomElement qde: liste_terminals) { foreach(QDomElement qde, liste_terminals) {
// The position in the collection element definition is the origin position (originPos). if (p -> fromXml(qde)) {
// The position in the diagram element definition is the position where the conductor is connected (dock position)
// Therefore a simple operator overloading is not possible.
Terminal diagramTerminal(0,0, Qet::Orientation::East);
diagramTerminal.fromXml(qde);
QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram)
QPointF dockPos2 = p->dockPos();
if (qFuzzyCompare(dockPos1.x(), dockPos2.x()) &&
qFuzzyCompare(dockPos1.y(), dockPos2.y()) &&
p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored
qDebug() << "Matching Terminal found.";
// store id for legacy purpose, because when opening a old project in the collection the terminal does not have an uuid. Therefore the id must be used
if (p->uuid().isNull()) {
p->setID(qde.attribute("id").toInt());
}
priv_id_adr.insert(qde.attribute("id").toInt(), p); priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true; terminal_trouvee = true;
// We used to break here, because we did not expect // We used to break here, because we did not expect
// several terminals to share the same position. // several terminals to share the same position.
// Of course, it finally happened. // Of course, it finally happened.
} }
} }
if (!terminal_trouvee) ++ terminals_non_trouvees; if (!terminal_trouvee) ++ terminals_non_trouvees;
} }
@@ -681,7 +661,6 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
if (terminals_non_trouvees > 0) if (terminals_non_trouvees > 0)
{ {
qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees;
m_state = QET::GIOK; m_state = QET::GIOK;
return(false); return(false);
} }
@@ -716,8 +695,6 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
QString fl = e.attribute("freezeLabel", "false"); QString fl = e.attribute("freezeLabel", "false");
m_freeze_label = fl == "false"? false : true; m_freeze_label = fl == "false"? false : true;
// TODO: why element information is not read?
//Load Sequential Values //Load Sequential Values
if (e.hasAttribute("sequ_1") || e.hasAttribute("sequf_1") || e.hasAttribute("seqt_1") || e.hasAttribute("seqtf_1") || e.hasAttribute("seqh_1") || e.hasAttribute("sequf_1")) if (e.hasAttribute("sequ_1") || e.hasAttribute("sequf_1") || e.hasAttribute("seqt_1") || e.hasAttribute("seqtf_1") || e.hasAttribute("seqh_1") || e.hasAttribute("sequf_1"))
ElementXmlRetroCompatibility::loadSequential(e, this); ElementXmlRetroCompatibility::loadSequential(e, this);
@@ -748,9 +725,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
//************************// //************************//
//***Dynamic texts item***// //***Dynamic texts item***//
//************************// //************************//
// read from the diagram section
// this is not done in the older versions, because there only inputs are available.
for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName())) for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName()))
{ {
DynamicElementTextItem *deti = new DynamicElementTextItem(this); DynamicElementTextItem *deti = new DynamicElementTextItem(this);
@@ -762,22 +737,20 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
//************************// //************************//
//***Element texts item***// //***Element texts item***//
//************************// //************************//
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); // inputs in diagram section QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
//First case, we check for the text item converted to dynamic text item //First case, we check for the text item converted to dynamic text item
const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys(); const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys();
QList <DynamicElementTextItem *> successfully_converted; QList <DynamicElementTextItem *> successfully_converted;
const QList <QDomElement> dom_inputs = inputs; const QList <QDomElement> dom_inputs = inputs;
// TODO: Legacy (0.7 and prior)
for (DynamicElementTextItem *deti : conv_deti_list) // elements read from the element collection definition for (DynamicElementTextItem *deti : conv_deti_list)
{ {
for(const QDomElement& dom_input : dom_inputs) // elements in the diagram section for(const QDomElement& dom_input : dom_inputs)
{ {
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored. //we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element //The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
//that mean this is the good text //that mean this is the good text
// This is only used when in the diagram description the text elements are stored in the "inputs" section. In 0.8 and higher,
// texts are stored in directly in the "dynamic_elmt_text" section
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) && if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) &&
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y())) qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y()))
{ {
@@ -853,6 +826,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
* this mean the label was made before commit 4791 (0.51 dev). So we swap the value stored in "label" to "formula" as expected. * this mean the label was made before commit 4791 (0.51 dev). So we swap the value stored in "label" to "formula" as expected.
* @TODO remove this code at version 0.7 or more (probably useless). * @TODO remove this code at version 0.7 or more (probably useless).
*/ */
#pragma message("@TODO remove this code for qet 0.7 or later")
if (dc["label"].toString().contains("%") && dc["formula"].toString().isNull()) if (dc["label"].toString().contains("%") && dc["formula"].toString().isNull())
{ {
dc.addValue("formula", dc["label"]); dc.addValue("formula", dc["label"]);
@@ -1030,7 +1004,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
methode methode
@return L'element XML representant cet element electrique @return L'element XML representant cet element electrique
*/ */
QDomElement Element::toXml(QDomDocument &document) const QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table_adr_id) const
{ {
QDomElement element = document.createElement("element"); QDomElement element = document.createElement("element");
@@ -1057,16 +1031,25 @@ QDomElement Element::toXml(QDomDocument &document) const
element.setAttribute("z", QString::number(this->zValue())); element.setAttribute("z", QString::number(this->zValue()));
element.setAttribute("orientation", QString::number(orientation())); element.setAttribute("orientation", QString::number(orientation()));
/* recupere le premier id a utiliser pour les bornes de cet element */
int id_terminal = 0;
if (!table_adr_id.isEmpty()) {
// trouve le plus grand id
int max_id_t = -1;
foreach (int id_t, table_adr_id.values()) {
if (id_t > max_id_t) max_id_t = id_t;
}
id_terminal = max_id_t + 1;
}
// enregistrement des bornes de l'appareil // enregistrement des bornes de l'appareil
QDomElement xml_terminals = document.createElement("terminals"); QDomElement xml_terminals = document.createElement("terminals");
// pour chaque enfant de l'element // pour chaque enfant de l'element
foreach(Terminal *t, terminals()) { foreach(Terminal *t, terminals()) {
// alors on enregistre la borne // alors on enregistre la borne
QDomElement terminal = t -> toXml(document); QDomElement terminal = t -> toXml(document);
if (t->ID() > 0) { terminal.setAttribute("id", id_terminal); // for backward compatibility
// for backward compatibility table_adr_id.insert(t, id_terminal ++);
terminal.setAttribute("id", t->ID()); // for backward compatibility
}
xml_terminals.appendChild(terminal); xml_terminals.appendChild(terminal);
} }
element.appendChild(xml_terminals); element.appendChild(xml_terminals);

View File

@@ -37,7 +37,7 @@ class ElementTextItemGroup;
/** /**
This is the base class for electrical elements. This is the base class for electrical elements.
*/ */
class Element : public QetGraphicsItem // TODO: derive from propertiesInterface! class Element : public QetGraphicsItem
{ {
friend class DiagramEventAddElement; friend class DiagramEventAddElement;
@@ -55,7 +55,7 @@ class Element : public QetGraphicsItem // TODO: derive from propertiesInterface!
Slave = 16, Slave = 16,
Terminale = 32}; Terminale = 32};
Element(const ElementsLocation &location, QGraphicsItem * parent= nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple);
~Element() override; ~Element() override;
private: private:
Element(const Element &); Element(const Element &);
@@ -113,7 +113,7 @@ class Element : public QetGraphicsItem // TODO: derive from propertiesInterface!
void editProperty() override; void editProperty() override;
static bool valideXml(QDomElement &); static bool valideXml(QDomElement &);
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false); virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
virtual QDomElement toXml(QDomDocument &) const; virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
QUuid uuid() const; QUuid uuid() const;
int orientation() const; int orientation() const;

View File

@@ -384,7 +384,6 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
return dom_element; return dom_element;
} }
// TOOD: inherit from propertiesinterface
/** /**
* @brief ElementTextItemGroup::fromXml * @brief ElementTextItemGroup::fromXml
* Import data of this group from xml * Import data of this group from xml

View File

@@ -32,7 +32,7 @@ class CrossRefItem;
* This class represent a group of element text * This class represent a group of element text
* Texts in the group can be aligned left / center /right * Texts in the group can be aligned left / center /right
*/ */
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO: derive from PropertiesInterface class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
{ {
Q_OBJECT Q_OBJECT
@@ -108,7 +108,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO:
m_hold_to_bottom_of_page = false, m_hold_to_bottom_of_page = false,
m_block_alignment_update = false, m_block_alignment_update = false,
m_frame = false; m_frame = false;
QPointF m_initial_position{QPointF(0,0)}; QPointF m_initial_position;
int m_vertical_adjustment = 0; int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr; CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr; Element *m_parent_element = nullptr;

View File

@@ -49,7 +49,6 @@ IndependentTextItem::IndependentTextItem(const QString &text) :
IndependentTextItem::~IndependentTextItem() { IndependentTextItem::~IndependentTextItem() {
} }
// TODO: inherit from PropertiesInterface
/** /**
Permet de lire le texte a mettre dans le champ a partir d'un element XML. Permet de lire le texte a mettre dans le champ a partir d'un element XML.
Cette methode se base sur la position du champ pour assigner ou non la Cette methode se base sur la position du champ pour assigner ou non la

View File

@@ -25,7 +25,10 @@
* @param parent, Parent Item * @param parent, Parent Item
*/ */
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent): QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent) QGraphicsObject(parent),
is_movable_(true),
m_first_move(true),
snap_to_grid_(true)
{} {}
QetGraphicsItem::~QetGraphicsItem() QetGraphicsItem::~QetGraphicsItem()

View File

@@ -53,10 +53,10 @@ class QetGraphicsItem : public QGraphicsObject
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected: protected:
bool is_movable_{true}; bool is_movable_;
bool m_first_move{true}; bool m_first_move;
bool snap_to_grid_{true}; bool snap_to_grid_;
QPointF m_mouse_to_origin_movement{QPointF(0,0)}; QPointF m_mouse_to_origin_movement;
QET::GraphicsItemState m_state = QET:: GIOK; QET::GraphicsItemState m_state = QET:: GIOK;
}; };

View File

@@ -830,7 +830,6 @@ void QetShapeItem::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraph
} }
} }
// TODO: inherit from Propertiesinterface!
/** /**
* @brief QetShapeItem::fromXml * @brief QetShapeItem::fromXml
* Build this item from the xml description * Build this item from the xml description

View File

@@ -29,10 +29,10 @@
* @param s parent diagram * @param s parent diagram
* @param state int used to know if the creation of element have error * @param state int used to know if the creation of element have error
*/ */
SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *parent, int *state) : SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
Element(location, parent, state, Element::Slave) Element(location, qgi, state, Element::Slave)
{ {
m_xref_item = nullptr;
} }
/** /**

View File

@@ -25,14 +25,14 @@ class SlaveElement : public Element
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SlaveElement (const ElementsLocation &, QGraphicsItem * parent= nullptr, int * = nullptr); explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
~SlaveElement() override; ~SlaveElement() override;
void linkToElement(Element *elmt) override; void linkToElement(Element *elmt) override;
void unlinkAllElements() override; void unlinkAllElements() override;
void unlinkElement(Element *elmt) override; void unlinkElement(Element *elmt) override;
private: private:
QGraphicsTextItem *m_xref_item{nullptr}; QGraphicsTextItem *m_xref_item;
}; };
#endif // SLAVEELEMENT_H #endif // SLAVEELEMENT_H

View File

@@ -30,7 +30,7 @@ QColor Terminal::neutralColor = QColor(Qt::blue);
QColor Terminal::allowedColor = QColor(Qt::darkGreen); QColor Terminal::allowedColor = QColor(Qt::darkGreen);
QColor Terminal::warningColor = QColor("#ff8000"); QColor Terminal::warningColor = QColor("#ff8000");
QColor Terminal::forbiddenColor = QColor(Qt::red); QColor Terminal::forbiddenColor = QColor(Qt::red);
const qreal Terminal::terminalSize = 4.0; // TODO: store terminalSize in terminaldata, because in PartTerminal there is the same parameter. So only one is needed const qreal Terminal::terminalSize = 4.0;
const qreal Terminal::Z = 1000; const qreal Terminal::Z = 1000;
/** /**
@@ -41,6 +41,8 @@ const qreal Terminal::Z = 1000;
@param name of terminal @param name of terminal
*/ */
void Terminal::init(QString number, QString name, bool hiddenName) { void Terminal::init(QString number, QString name, bool hiddenName) {
hovered_color_ = Terminal::neutralColor;
// calcul de la position du point d'amarrage a l'element // calcul de la position du point d'amarrage a l'element
dock_elmt_ = d->m_pos; dock_elmt_ = d->m_pos;
@@ -54,15 +56,17 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
// Number of terminal // Number of terminal
number_terminal_ = std::move(number); number_terminal_ = std::move(number);
// Name of terminal // Name of terminal
d->m_name = std::move(name); name_terminal_ = std::move(name);
name_terminal_hidden = hiddenName; name_terminal_hidden = hiddenName;
// par defaut : pas de conducteur // par defaut : pas de conducteur
// QRectF null // QRectF null
br_ = new QRectF(); br_ = new QRectF();
previous_terminal_ = nullptr;
// divers // divers
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
hovered_ = false;
setToolTip(QObject::tr("Borne", "tooltip")); setToolTip(QObject::tr("Borne", "tooltip"));
setZValue(Z); setZValue(Z);
} }
@@ -193,18 +197,10 @@ void Terminal::setNumber(QString number) {
@param name @param name
*/ */
void Terminal::setName(QString name, bool hiddenName) { void Terminal::setName(QString name, bool hiddenName) {
d->m_name = std::move(name); name_terminal_ = std::move(name);
name_terminal_hidden = hiddenName; name_terminal_hidden = hiddenName;
} }
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const {
return(d->m_name);
}
/** /**
@brief Terminal::addConductor @brief Terminal::addConductor
Add a conductor to this terminal Add a conductor to this terminal
@@ -706,10 +702,6 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
return true; return true;
} }
void Terminal::setID(int id) {
m_id = id;
}
/** /**
@brief Terminal::conductors @brief Terminal::conductors
@return La liste des conducteurs lies a cette borne @return La liste des conducteurs lies a cette borne
@@ -727,24 +719,15 @@ QList<Conductor *> Terminal::conductors() const {
QDomElement Terminal::toXml(QDomDocument &doc) const { QDomElement Terminal::toXml(QDomDocument &doc) const {
QDomElement qdo = doc.createElement("terminal"); QDomElement qdo = doc.createElement("terminal");
qdo.appendChild(createXmlProperty(doc, "number", number_terminal_)); // for backward compatibility
qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden)); qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
// store terminal data too! // end for backward compatibility
// Do not store terminal data in its own child
// Bad hack. The problem is that in the diagrams the terminal is described by the position and in the Collection by the dock.
QPointF tempPos = d->m_pos;
d->m_pos = dock_elmt_;
QDomElement terminalDataElement = d->toXml(doc);
d->m_pos = tempPos;
int childsCount = terminalDataElement.childNodes().count();
for (int i=0; i < childsCount; i++) {
QDomNode node = terminalDataElement.childNodes().at(i).cloneNode(); // cloneNode() is important, otherwise no deep clone is made
qdo.appendChild(node);
}
qdo.setAttribute("orientation", d->m_orientation);
qdo.setAttribute("number", number_terminal_);
qdo.setAttribute("name", name_terminal_);
qdo.setAttribute("nameHidden", name_terminal_hidden);
return(qdo); return(qdo);
} }
@@ -754,24 +737,41 @@ QDomElement Terminal::toXml(QDomDocument &doc) const {
@param terminal Le QDomElement a analyser @param terminal Le QDomElement a analyser
@return true si le QDomElement passe en parametre est une borne, false sinon @return true si le QDomElement passe en parametre est une borne, false sinon
*/ */
bool Terminal::valideXml(const QDomElement &terminal) { bool Terminal::valideXml(QDomElement &terminal) {
// verifie le nom du tag
if (terminal.tagName() != "terminal") return(false); if (terminal.tagName() != "terminal") return(false);
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (propertyString(terminal, "number"))
// return false;
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (propertyBool(terminal, "nameHidden"))
// return false;
if (!TerminalData::valideXml(terminal))
return false;
// a ce stade, la borne est syntaxiquement correcte // verifie la presence des attributs minimaux
return true; if (!terminal.hasAttribute("x")) return(false);
if (!terminal.hasAttribute("y")) return(false);
if (!terminal.hasAttribute("orientation")) return(false);
bool conv_ok;
// parse l'abscisse
terminal.attribute("x").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'ordonnee
terminal.attribute("y").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'id
terminal.attribute("id").toInt(&conv_ok);
if (!conv_ok) return(false);
// parse l'orientation
int terminal_or = terminal.attribute("orientation").toInt(&conv_ok);
if (!conv_ok) return(false);
if (terminal_or != Qet::North
&& terminal_or != Qet::South
&& terminal_or != Qet::East
&& terminal_or != Qet::West) return(false);
// a ce stade, la borne est syntaxiquement correcte
return(true);
} }
/** RETURNS True /**
@brief Terminal::fromXml @brief Terminal::fromXml
Permet de savoir si un element XML represente cette borne. Attention, Permet de savoir si un element XML represente cette borne. Attention,
l'element XML n'est pas verifie l'element XML n'est pas verifie
@@ -779,17 +779,16 @@ bool Terminal::valideXml(const QDomElement &terminal) {
@return true si la borne "se reconnait" @return true si la borne "se reconnait"
(memes coordonnes, meme orientation), false sinon (memes coordonnes, meme orientation), false sinon
*/ */
bool Terminal::fromXml(const QDomElement &terminal) { bool Terminal::fromXml(QDomElement &terminal) {
propertyString(terminal, "number", &number_terminal_); number_terminal_ = terminal.attribute("number");
name_terminal_ = terminal.attribute("name");
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
propertyBool(terminal, "nameHidden", &name_terminal_hidden); return (
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
if(!d->fromXml(terminal)) qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
return false; (terminal.attribute("orientation").toInt() == d->m_orientation)
);
init(number_terminal_, d->m_name, name_terminal_hidden); // initialize dock_elmt_. This must be done after Terminal data is initialized
return true;
} }
/** /**
@@ -822,18 +821,6 @@ QUuid Terminal::uuid() const {
return d->m_uuid; return d->m_uuid;
} }
int Terminal::ID() const {
return m_id;
}
QPointF Terminal::dockPos() {
return dock_elmt_;
}
QPointF Terminal::originPos() {
return d->m_pos;
}
/** /**
@brief Conductor::relatedPotentialTerminal @brief Conductor::relatedPotentialTerminal
Return terminal at the same potential from the same Return terminal at the same potential from the same

View File

@@ -20,8 +20,6 @@
#include <QtWidgets> #include <QtWidgets>
#include <QtXml> #include <QtXml>
#include "qet.h" #include "qet.h"
#include "propertiesinterface.h"
class Conductor; class Conductor;
class Diagram; class Diagram;
class Element; class Element;
@@ -33,7 +31,7 @@ class TerminalData;
plug point for conductors. plug point for conductors.
This class handles all mouse events for connecting conductors This class handles all mouse events for connecting conductors
*/ */
class Terminal : public QGraphicsObject, public PropertiesInterface class Terminal : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
@@ -77,9 +75,6 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
Diagram *diagram () const; Diagram *diagram () const;
Element *parentElement () const; Element *parentElement () const;
QUuid uuid () const; QUuid uuid () const;
int ID() const;
QPointF dockPos();
QPointF originPos();
QList<Conductor *> conductors() const; QList<Conductor *> conductors() const;
Qet::Orientation orientation() const; Qet::Orientation orientation() const;
@@ -91,12 +86,11 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
void updateConductor(); void updateConductor();
bool isLinkedTo(Terminal *); bool isLinkedTo(Terminal *);
bool canBeLinkedTo(Terminal *); bool canBeLinkedTo(Terminal *);
void setID(int id);
// methods related to XML import/export // methods related to XML import/export
static bool valideXml(const QDomElement &); static bool valideXml(QDomElement &);
bool fromXml (const QDomElement &) override; bool fromXml (QDomElement &);
QDomElement toXml (QDomDocument &) const override; QDomElement toXml (QDomDocument &) const;
protected: protected:
// methods related to events management // methods related to events management
@@ -113,10 +107,9 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
static const qreal terminalSize; static const qreal terminalSize;
static const qreal Z; static const qreal Z;
// Various static colors used for hover effects. // Various static colors used for hover effects
// The assignement is in the cpp file
/// default color /// default color
static QColor neutralColor; static QColor neutralColor;
/// color for legal actions /// color for legal actions
static QColor allowedColor; static QColor allowedColor;
/// color for allowed but fuzzy or not recommended actions /// color for allowed but fuzzy or not recommended actions
@@ -145,17 +138,16 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
*/ */
QRectF *br_{nullptr}; QRectF *br_{nullptr};
/// Last terminal seen through an attached conductor /// Last terminal seen through an attached conductor
Terminal *previous_terminal_{nullptr}; Terminal *previous_terminal_;
/// Whether the mouse pointer is hovering the terminal /// Whether the mouse pointer is hovering the terminal
bool hovered_{false}; bool hovered_;
/// Color used for the hover effect /// Color used for the hover effect
QColor hovered_color_{Terminal::hovered_color_}; QColor hovered_color_;
/// Number of Terminal /// Number of Terminal
QString number_terminal_; QString number_terminal_;
bool name_terminal_hidden{true}; /// Name of Terminal
QString name_terminal_;
/// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead. bool name_terminal_hidden;
int m_id{-1};
private: private:
void init(QString number, QString name, bool hiddenName); void init(QString number, QString name, bool hiddenName);
@@ -179,6 +171,14 @@ inline QString Terminal::number() const {
return(number_terminal_); return(number_terminal_);
} }
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const {
return(name_terminal_);
}
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
const bool all_diagram = true); const bool all_diagram = true);

View File

@@ -1425,11 +1425,7 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
{ {
XRefProperties xrp; XRefProperties xrp;
xrp.fromXml(elmt); xrp.fromXml(elmt);
QString type; m_default_xref_properties.insert(elmt.attribute("type"), xrp);
if (PropertiesInterface::propertyString(elmt, "type", &type) == PropertiesInterface::PropertyFlags::Success)
m_default_xref_properties.insert(type, xrp);
else
qDebug() << "xref Property was not added to m_default_xref_properties.";
} }
} }
if (!conds_autonums.isNull()) if (!conds_autonums.isNull())
@@ -1487,13 +1483,19 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element)
QDomDocument xml_document = xml_element.ownerDocument(); QDomDocument xml_document = xml_element.ownerDocument();
// export size of border // export size of border
xml_element.appendChild(default_border_properties_.toXml(xml_document)); QDomElement border_elmt = xml_document.createElement("border");
default_border_properties_.toXml(border_elmt);
xml_element.appendChild(border_elmt);
// export content of titleblock // export content of titleblock
xml_element.appendChild(default_titleblock_properties_.toXml(xml_document)); QDomElement titleblock_elmt = xml_document.createElement("inset");
default_titleblock_properties_.toXml(titleblock_elmt);
xml_element.appendChild(titleblock_elmt);
// exporte default conductor // exporte default conductor
xml_element.appendChild(default_conductor_properties_.toXml(xml_document)); QDomElement conductor_elmt = xml_document.createElement("conductors");
default_conductor_properties_.toXml(conductor_elmt);
xml_element.appendChild(conductor_elmt);
// export default report properties // export default report properties
QDomElement report_elmt = xml_document.createElement("report"); QDomElement report_elmt = xml_document.createElement("report");

View File

@@ -23,12 +23,13 @@
#include <QFont> #include <QFont>
/** /**
* @brief QETXML::penToXml @brief QETXML::penToXml
* Write attribute of a QPen in xml element Write attribute of a QPen in xml element
* @param parent_document : parent document for create the QDomElement @param parent_document : parent document for create the QDomElement
* @param pen : the pen to store @param pen : the pen to store
* @return : A QDomElement with the attribute stored. The tagName of QDomeElement is "pen". @return : A QDomElement with the attribute stored.
*/ The tagName of QDomeElement is "pen".
*/
QDomElement QETXML::penToXml(QDomDocument &parent_document,const QPen& pen) QDomElement QETXML::penToXml(QDomDocument &parent_document,const QPen& pen)
{ {
QDomElement element = parent_document.createElement("pen"); QDomElement element = parent_document.createElement("pen");
@@ -48,19 +49,19 @@ QDomElement QETXML::penToXml(QDomDocument &parent_document,const QPen& pen)
element.setAttribute("style", style); element.setAttribute("style", style);
element.setAttribute("color", pen.color().name()); element.setAttribute("color", pen.color().name());
element.setAttribute("widthF", QString::number(pen.widthF())); element.setAttribute("widthF", QString::number(pen.widthF()));
return element; return element;
} }
/** /**
* @brief QETXML::penFromXml @brief QETXML::penFromXml
* Build a QPen from a xml description Build a QPen from a xml description
* @param element, The QDomElement that describe the pen @param element, The QDomElement that describe the pen
* @return the created pen. If @element is null or tagName isn't "pen" @return the created pen. If @element is null or tagName isn't "pen"
* return a default constructed QPen return a default constructed QPen
*/ */
QPen QETXML::penFromXml(const QDomElement &element) QPen QETXML::penFromXml(const QDomElement &element)
{ {
QPen pen; QPen pen;
if (!(!element.isNull() && element.tagName() == "pen")) if (!(!element.isNull() && element.tagName() == "pen"))
{ {
@@ -82,17 +83,19 @@ QPen QETXML::penFromXml(const QDomElement &element)
pen.setColor(QColor(element.attribute("color", "#000000"))); pen.setColor(QColor(element.attribute("color", "#000000")));
pen.setWidthF(element.attribute("widthF", "1").toDouble()); pen.setWidthF(element.attribute("widthF", "1").toDouble());
return pen; return pen;
} }
/** /**
* @brief QETXML::brushToXml @brief QETXML::brushToXml
* Write attribute of a QBrush in xml element Write attribute of a QBrush in xml element
* @param parent_document : parent document for create the QDomElement @param parent_document : parent document for create the QDomElement
* @param brush : the brush to store @param brush : the brush to store
* @return A QDomElement with the attribute stored. The tagName of QDomeElement is "brush". @return A QDomElement with the attribute stored.
*/ The tagName of QDomeElement is "brush".
QDomElement QETXML::brushToXml(QDomDocument &parent_document, const QBrush& brush) */
QDomElement QETXML::brushToXml(QDomDocument &parent_document,
const QBrush& brush)
{ {
QDomElement element = parent_document.createElement("brush"); QDomElement element = parent_document.createElement("brush");
@@ -114,7 +117,7 @@ QDomElement QETXML::brushToXml(QDomDocument &parent_document, const QBrush& brus
case Qt::BDiagPattern : style = "BDiagPattern"; break; case Qt::BDiagPattern : style = "BDiagPattern"; break;
case Qt::FDiagPattern : style = "FDiagPattern"; break; case Qt::FDiagPattern : style = "FDiagPattern"; break;
case Qt::DiagCrossPattern : style = "DiagCrossPattern"; break; case Qt::DiagCrossPattern : style = "DiagCrossPattern"; break;
default : style = "Unknown"; break; default : style = "Unknown"; break;
} }
element.setAttribute("style", style); element.setAttribute("style", style);
@@ -123,12 +126,12 @@ QDomElement QETXML::brushToXml(QDomDocument &parent_document, const QBrush& brus
} }
/** /**
* @brief QETXML::brushFromXml @brief QETXML::brushFromXml
* Build a QBrush from a xml description Build a QBrush from a xml description
* @param element, the QDomElement that describe the pen @param element, the QDomElement that describe the pen
* @return the created brush. If @element is null or tagName isn't "brush" @return the created brush. If @element is null or tagName isn't "brush"
* return a default constructed QBrush return a default constructed QBrush
*/ */
QBrush QETXML::brushFromXml(const QDomElement &element) QBrush QETXML::brushFromXml(const QDomElement &element)
{ {
QBrush brush; QBrush brush;
@@ -158,15 +161,20 @@ QBrush QETXML::brushFromXml(const QDomElement &element)
} }
/** /**
* @brief QETXML::fileSystemDirToXmlCollectionDir @brief QETXML::fileSystemDirToXmlCollectionDir
* @param document : owner document of returned QDomElement, use to create the QDomElement. @param document : owner document of returned QDomElement,
* @param dir : file system direcory to convert to QDomElement directory use to create the QDomElement.
* @param rename : by default the attribute "name" of the returned QDomElement is the same name of @dir @param dir : file system direcory to convert to QDomElement directory
* but we can override itwith @rename @param rename : by default the attribute "name" of the returned
* @return A file system directory converted to a QDomElement directory ready to be inserted into a XmlElementCollection. QDomElement is the same name of @dir
* If the QDomElement can't be created, return a null QDomElement. but we can override itwith @rename
*/ @return A file system directory converted to a QDomElement directory
QDomElement QETXML::fileSystemDirToXmlCollectionDir(QDomDocument &document, const QDir &dir, const QString& rename) ready to be inserted into a XmlElementCollection.
If the QDomElement can't be created, return a null QDomElement.
*/
QDomElement QETXML::fileSystemDirToXmlCollectionDir(QDomDocument &document,
const QDir &dir,
const QString& rename)
{ {
if (!dir.exists()) return QDomElement(); if (!dir.exists()) return QDomElement();
@@ -175,7 +183,9 @@ QDomElement QETXML::fileSystemDirToXmlCollectionDir(QDomDocument &document, cons
//Get the traduction of this directory //Get the traduction of this directory
QFile qet_dir(dir.filePath("qet_directory")); QFile qet_dir(dir.filePath("qet_directory"));
if (qet_dir.exists() && qet_dir.open(QIODevice::ReadOnly | QIODevice::Text)) if (qet_dir.exists() && qet_dir.open(
QIODevice::ReadOnly
| QIODevice::Text))
{ {
//Get the content of the file //Get the content of the file
QDomDocument trad_document; QDomDocument trad_document;
@@ -196,15 +206,21 @@ QDomElement QETXML::fileSystemDirToXmlCollectionDir(QDomDocument &document, cons
} }
/** /**
* @brief QETXML::fileSystemElementToXmlCollectionElement @brief QETXML::fileSystemElementToXmlCollectionElement
* @param document : owner document of returned QDomElement, use to create the QDomElement. @param document : owner document of returned QDomElement,
* @param file : file system element file to convert to QDomElement; use to create the QDomElement.
* @param rename : by default the attribute "name" of the returned QDomElement is the same name of @file @param file : file system element file to convert to QDomElement;
* but we can override itwith @rename @param rename : by default the attribute "name" of
* @return A file system element converted to a QDomElement ready to be inserted into a XmlElementCollection the returned QDomElement is the same name of @file
* If the QDomElement can't be created, return a null QDomElement but we can override itwith @rename
*/ @return A file system element converted to a QDomElement
QDomElement QETXML::fileSystemElementToXmlCollectionElement(QDomDocument &document, QFile &file, const QString& rename) ready to be inserted into a XmlElementCollection
If the QDomElement can't be created, return a null QDomElement
*/
QDomElement QETXML::fileSystemElementToXmlCollectionElement(
QDomDocument &document,
QFile &file,
const QString& rename)
{ {
if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
@@ -229,26 +245,32 @@ QDomElement QETXML::fileSystemElementToXmlCollectionElement(QDomDocument &docume
} }
/** /**
* @brief QETXML::writeXmlFile @brief QETXML::writeXmlFile
* Export an XML document to an UTF-8 text file indented with 4 spaces, with LF end of lines and no BOM. Export an XML document to an UTF-8 text file indented with 4 spaces,
* @param xml_document : An XML document to be exported with LF end of lines and no BOM.
* @param file_path : Path to the file to be written @param xml_document : An XML document to be exported
* @param error_message : If non-zero, will contain an error message explaining what happened when this function returns false. @param file_path : Path to the file to be written
* @return false if an error occurred, true otherwise @param error_message : If non-zero, will contain an error message
*/ explaining what happened when this function returns false.
bool QETXML::writeXmlFile(const QDomDocument &xml_document, const QString &file_path, QString *error_message) @return false if an error occurred, true otherwise
*/
bool QETXML::writeXmlFile(const QDomDocument &xml_document,
const QString &file_path,
QString *error_message)
{ {
QFile file(file_path); QFile file(file_path);
// Note: we do not set QIODevice::Text to avoid generating CRLF end of lines // Note: we do not set QIODevice::Text to avoid generating CRLF end of lines
bool file_opening = file.open(QIODevice::WriteOnly); bool file_opening = file.open(QIODevice::WriteOnly);
if (!file_opening) if (!file_opening)
{ {
if (error_message) if (error_message)
{ {
*error_message = QString(QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.", *error_message = QString(
"error message when attempting to write an XML file") QObject::tr(
).arg(file_path).arg(file.error()); "Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.",
"error message when attempting to write an XML file")
).arg(file_path).arg(file.error());
} }
return(false); return(false);
} }
@@ -263,14 +285,17 @@ bool QETXML::writeXmlFile(const QDomDocument &xml_document, const QString &file_
} }
/** /**
* @brief QETXML::textToDomElement @brief QETXML::textToDomElement
* Return a QDomElement, created from @document, with tag name @tag_name and text @value. Return a QDomElement, created from @document,
* @param document with tag name @tag_name and text @value.
* @param tag_name @param document
* @param value @param tag_name
* @return @param value
*/ @return a QDomElement, created from @document
QDomElement QETXML::textToDomElement(QDomDocument &document, const QString& tag_name, const QString& value) */
QDomElement QETXML::textToDomElement(QDomDocument &document,
const QString& tag_name,
const QString& value)
{ {
QDomElement element = document.createElement(tag_name); QDomElement element = document.createElement(tag_name);
QDomText text = document.createTextNode(value); QDomText text = document.createTextNode(value);
@@ -280,15 +305,19 @@ QDomElement QETXML::textToDomElement(QDomDocument &document, const QString& tag_
} }
/** /**
* @brief QETXML::directChild @brief QETXML::directChild
* @param element @param element
* @param tag_name @param tag_name
* @return All direct child of @element with the tag name @tag_name @return All direct child of @element with the tag name @tag_name
*/ */
QVector<QDomElement> QETXML::directChild(const QDomElement &element, const QString &tag_name) QVector<QDomElement> QETXML::directChild(const QDomElement &element,
const QString &tag_name)
{ {
QVector<QDomElement> return_list; QVector<QDomElement> return_list;
for (QDomNode node = element.firstChild() ; !node.isNull() ; node = node.nextSibling()) for (
QDomNode node = element.firstChild() ;
!node.isNull() ;
node = node.nextSibling())
{ {
if (!node.isElement()) continue; if (!node.isElement()) continue;
QDomElement element = node.toElement(); QDomElement element = node.toElement();
@@ -300,25 +329,34 @@ QVector<QDomElement> QETXML::directChild(const QDomElement &element, const QStri
} }
/** /**
* @brief QETXML::subChild @brief QETXML::subChild
* @param element @param element
* @param parent_tag_name @param parent_tag_name
* @param children_tag_name @param children_tag_name
* @return When given an xml dom element @element, @return When given an xml dom element @element,
* returns a vector of all children dom_elements tagged @children_tag_name returns a vector of all children dom_elements tagged @children_tag_name
* nested in the parent dom elements tagged parent_tag_name, themselves children of the dom element @element. nested in the parent dom elements tagged parent_tag_name,
*/ themselves children of the dom element @element.
QVector<QDomElement> QETXML::subChild(const QDomElement &element, const QString parent_tag_name, const QString &children_tag_name) */
QVector<QDomElement> QETXML::subChild(const QDomElement &element,
const QString parent_tag_name,
const QString &children_tag_name)
{ {
QVector<QDomElement> return_list; QVector<QDomElement> return_list;
for (QDomNode child = element.firstChild() ; !child.isNull() ; child = child.nextSibling()) for (
QDomNode child = element.firstChild() ;
!child.isNull() ;
child = child.nextSibling())
{ {
QDomElement parents = child.toElement(); QDomElement parents = child.toElement();
if (parents.isNull() || parents.tagName() != parent_tag_name) if (parents.isNull() || parents.tagName() != parent_tag_name)
continue; continue;
for (QDomNode node_children = parents.firstChild() ; !node_children.isNull() ; node_children = node_children.nextSibling()) for (
QDomNode node_children = parents.firstChild() ;
!node_children.isNull() ;
node_children = node_children.nextSibling())
{ {
QDomElement n_children = node_children.toElement(); QDomElement n_children = node_children.toElement();
if (!n_children.isNull() && n_children.tagName() == children_tag_name) if (!n_children.isNull() && n_children.tagName() == children_tag_name)
@@ -330,29 +368,34 @@ QVector<QDomElement> QETXML::subChild(const QDomElement &element, const QString
} }
/** /**
* @brief QETXML::marginsToXml @brief QETXML::marginsToXml
* Save a QMargins to xml. the xml tag name is 'margins' Save a QMargins to xml. the xml tag name is 'margins'
* @param parent_document @param parent_document
* @param margins @param margins
* @return @return
*/ */
QDomElement QETXML::marginsToXml(QDomDocument &parent_document, const QMargins &margins) QDomElement QETXML::marginsToXml(QDomDocument &parent_document,
const QMargins &margins)
{ {
auto dom_ = parent_document.createElement("margins"); auto dom_ = parent_document.createElement("margins");
auto text_ = parent_document.createTextNode(QString::number(margins.left()) + QString(";") + auto text_ = parent_document.createTextNode(
QString::number(margins.top()) + QString(";") + QString::number(margins.left())
QString::number(margins.right()) + QString(";") + + QString(";")
QString::number(margins.bottom())); + QString::number(margins.top())
+ QString(";")
+ QString::number(margins.right())
+ QString(";")
+ QString::number(margins.bottom()));
dom_.appendChild(text_); dom_.appendChild(text_);
return dom_; return dom_;
} }
/** /**
* @brief QETXML::marginsFromXml @brief QETXML::marginsFromXml
* @param element @param element
* @return a QMargins from an xml description. @return a QMargins from an xml description.
* The tag name must ne 'margins' The tag name must ne 'margins'
*/ */
QMargins QETXML::marginsFromXml(const QDomElement &element) QMargins QETXML::marginsFromXml(const QDomElement &element)
{ {
if (element.tagName() != "margins") { if (element.tagName() != "margins") {
@@ -361,22 +404,35 @@ QMargins QETXML::marginsFromXml(const QDomElement &element)
auto margins_ = element.text().split(";"); auto margins_ = element.text().split(";");
if (margins_.size() == 4) { if (margins_.size() == 4) {
return QMargins(margins_.at(0).toInt(), margins_.at(1).toInt(), margins_.at(2).toInt(), margins_.at(3).toInt()); return QMargins(
margins_.at(0).toInt(),
margins_.at(1).toInt(),
margins_.at(2).toInt(),
margins_.at(3).toInt());
} else { } else {
return QMargins(); return QMargins();
} }
} }
/** /**
* @brief QETXML::modelHeaderDataToXml @brief QETXML::modelHeaderDataToXml
* Save to xml element all header data specified by @horizontal_section_role and @vertical_section_role Save to xml element all header data specified
* @param parent_document by @horizontal_section_role and @vertical_section_role
* @param model @param parent_document
* @param horizontal_section_role : key as header section and value as list of roles to save in xml @param model
* @param vertical_section_role :key as header section and value as list of roles to save in xml @param horizontal_section_role : key as header section and value
* @return as list of roles to save in xml
*/ @param vertical_section_role :key as header section and value
QDomElement QETXML::modelHeaderDataToXml(QDomDocument &parent_document, const QAbstractItemModel *model, QHash<int, QList<int>> horizontal_section_role, QHash<int, QList<int>> vertical_section_role) as list of roles to save in xml
@return
*/
QDomElement QETXML::modelHeaderDataToXml(
QDomDocument &parent_document,
const QAbstractItemModel *model,
QHash<int,
QList<int>> horizontal_section_role,
QHash<int,
QList<int>> vertical_section_role)
{ {
auto dom_element = parent_document.createElement("header_data"); auto dom_element = parent_document.createElement("header_data");
@@ -401,7 +457,11 @@ QDomElement QETXML::modelHeaderDataToXml(QDomDocument &parent_document, const QA
dom_data.setAttribute("role", meta_enum_role.valueToKey(role)); dom_data.setAttribute("role", meta_enum_role.valueToKey(role));
auto text_node = parent_document.createTextNode(""); auto text_node = parent_document.createTextNode("");
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::ToolTipRole || role == Qt::StatusTipRole || role == Qt::WhatsThisRole) if (role == Qt::DisplayRole
|| role == Qt::EditRole
|| role == Qt::ToolTipRole
|| role == Qt::StatusTipRole
|| role == Qt::WhatsThisRole)
{ {
text_node.setData(variant.toString()); text_node.setData(variant.toString());
} }
@@ -433,12 +493,13 @@ QDomElement QETXML::modelHeaderDataToXml(QDomDocument &parent_document, const QA
} }
/** /**
* @brief QETXML::modelHeaderDataFromXml @brief QETXML::modelHeaderDataFromXml
* Restore from xml modele header data Restore from xml modele header data
* @param element @param element
* @param model @param model
*/ */
void QETXML::modelHeaderDataFromXml(const QDomElement &element, QAbstractItemModel *model) void QETXML::modelHeaderDataFromXml(const QDomElement &element,
QAbstractItemModel *model)
{ {
if (element.tagName() != "header_data") if (element.tagName() != "header_data")
return; return;
@@ -449,12 +510,25 @@ void QETXML::modelHeaderDataFromXml(const QDomElement &element, QAbstractItemMod
for (auto child : QETXML::directChild(element, "data")) for (auto child : QETXML::directChild(element, "data"))
{ {
auto section_ = child.attribute("section", "-1").toInt(); auto section_ = child.attribute("section", "-1").toInt();
auto orientation_ = Qt::Orientation(meta_enum_orientation.keyToValue(child.attribute("orientation", "Horizontal").toStdString().data())); auto orientation_ = Qt::Orientation(
auto role_ = meta_enum_role.keyToValue(child.attribute("role", "DisplayRole").toStdString().data()); meta_enum_orientation.keyToValue(
child.attribute(
"orientation",
"Horizontal"
).toStdString().data()));
auto role_ = meta_enum_role.keyToValue(
child.attribute(
"role",
"DisplayRole"
).toStdString().data());
auto text_ = child.text(); auto text_ = child.text();
QVariant data_; QVariant data_;
if (role_ == Qt::DisplayRole || role_ == Qt::EditRole || role_ == Qt::ToolTipRole || role_ == Qt::StatusTipRole || role_ == Qt::WhatsThisRole) { if (role_ == Qt::DisplayRole
|| role_ == Qt::EditRole
|| role_ == Qt::ToolTipRole
|| role_ == Qt::StatusTipRole
|| role_ == Qt::WhatsThisRole) {
data_ = text_; data_ = text_;
} }
else if (role_ == Qt::FontRole) else if (role_ == Qt::FontRole)

View File

@@ -31,27 +31,48 @@ class QAbstractItemModel;
*/ */
namespace QETXML namespace QETXML
{ {
QDomElement penToXml(QDomDocument &parent_document, const QPen& pen); QDomElement penToXml(QDomDocument &parent_document, const QPen& pen);
QPen penFromXml (const QDomElement &element); QPen penFromXml (const QDomElement &element);
QDomElement brushToXml (QDomDocument &parent_document, const QBrush& brush); QDomElement brushToXml (QDomDocument &parent_document,
const QBrush& brush);
QBrush brushFromXml (const QDomElement &element); QBrush brushFromXml (const QDomElement &element);
QDomElement fileSystemDirToXmlCollectionDir (QDomDocument &document, const QDir &dir, const QString& rename = QString()); QDomElement fileSystemDirToXmlCollectionDir (
QDomElement fileSystemElementToXmlCollectionElement (QDomDocument &document, QFile &file, const QString& rename = QString()); QDomDocument &document,
const QDir &dir,
const QString& rename = QString());
QDomElement fileSystemElementToXmlCollectionElement (
QDomDocument &document,
QFile &file,
const QString& rename = QString());
bool writeXmlFile(const QDomDocument &xml_document, const QString &file_path, QString *error_message = nullptr); bool writeXmlFile(const QDomDocument &xml_document,
const QString &file_path,
QString *error_message = nullptr);
QDomElement textToDomElement (QDomDocument &document, const QString& tag_name, const QString& value); QDomElement textToDomElement (QDomDocument &document,
const QString& tag_name,
const QString& value);
QVector <QDomElement> directChild(const QDomElement &element, const QString &tag_name); QVector <QDomElement> directChild(const QDomElement &element,
QVector <QDomElement> subChild(const QDomElement &element, const QString parent_tag_name, const QString &children_tag_name); const QString &tag_name);
QVector <QDomElement> subChild(const QDomElement &element,
const QString parent_tag_name,
const QString &children_tag_name);
QDomElement marginsToXml (QDomDocument &parent_document, const QMargins &margins); QDomElement marginsToXml (QDomDocument &parent_document,
const QMargins &margins);
QMargins marginsFromXml(const QDomElement &element); QMargins marginsFromXml(const QDomElement &element);
QDomElement modelHeaderDataToXml(QDomDocument &parent_document, const QAbstractItemModel *model, QHash<int, QList<int>> horizontal_section_role, QHash<int, QList<int>> vertical_section_role); QDomElement modelHeaderDataToXml(QDomDocument &parent_document,
void modelHeaderDataFromXml(const QDomElement &element, QAbstractItemModel *model); const QAbstractItemModel *model,
QHash<int,
QList<int>> horizontal_section_role,
QHash<int,
QList<int>> vertical_section_role);
void modelHeaderDataFromXml(const QDomElement &element,
QAbstractItemModel *model);
} }
#endif // QETXML_H #endif // QETXML_H

View File

@@ -739,6 +739,7 @@ QString RichTextEditor::text(Qt::TextFormat format) const
break; break;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
case Qt::MarkdownText: //This enum value was added in Qt 5.14. case Qt::MarkdownText: //This enum value was added in Qt 5.14.
break; break;
#endif #endif

View File

@@ -23,7 +23,12 @@
*/ */
HelperCell::HelperCell(QGraphicsItem *parent) : HelperCell::HelperCell(QGraphicsItem *parent) :
QGraphicsObject(parent), QGraphicsObject(parent),
QGraphicsLayoutItem() QGraphicsLayoutItem(),
background_color(Qt::white),
foreground_color(Qt::black),
label(),
orientation(Qt::Horizontal),
index(-1)
{ {
setGraphicsItem(this); setGraphicsItem(this);
setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsSelectable, false);

View File

@@ -37,11 +37,11 @@ class HelperCell : public QGraphicsObject, public QGraphicsLayoutItem {
// attributes // attributes
public: public:
QColor background_color{Qt::white}; ///< Background color when rendering this cell QColor background_color; ///< Background color when rendering this cell
QColor foreground_color{Qt::black}; ///< Text color when rendering this cell QColor foreground_color; ///< Text color when rendering this cell
QString label; ///< Label displayed in this cell QString label; ///< Label displayed in this cell
Qt::Orientation orientation{Qt::Horizontal}; ///< Orientation of this cell Qt::Orientation orientation; ///< Orientation of this cell
int index{-1}; ///< Index of this cell int index; ///< Index of this cell
// methods // methods
public: public:

View File

@@ -36,7 +36,6 @@ class SplittedHelperCell : public HelperCell {
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
// attributes // attributes
// colors are set in the constructor
QColor split_background_color; ///< Background color on the split side QColor split_background_color; ///< Background color on the split side
QColor split_foreground_color; ///< Text color on the split side QColor split_foreground_color; ///< Text color on the split side
QString split_label; ///< Text displayed on the split side QString split_label; ///< Text displayed on the split side

View File

@@ -23,7 +23,11 @@
Constructeur. Initialise un objet TitleBlockProperties avec tous les champs Constructeur. Initialise un objet TitleBlockProperties avec tous les champs
vides (date vide + useDate a UseDateValue). vides (date vide + useDate a UseDateValue).
*/ */
TitleBlockProperties::TitleBlockProperties() TitleBlockProperties::TitleBlockProperties() :
date(),
useDate(UseDateValue),
display_at(Qt::BottomEdge),
collection (QET::QetCollection::Common)
{ {
} }
@@ -70,67 +74,53 @@ bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) {
@param e Element XML auquel seront ajoutes des attributs @param e Element XML auquel seront ajoutes des attributs
*/ */
void TitleBlockProperties::toXml(QDomElement &e) const { void TitleBlockProperties::toXml(QDomElement &e) const {
e.setAttribute("author", author);
e.setAttribute("author", author); e.setAttribute("title", title);
e.setAttribute("title", title); e.setAttribute("filename", filename);
e.setAttribute("filename", filename); e.setAttribute("plant", plant);
e.setAttribute("plant", plant); e.setAttribute("locmach", locmach);
e.setAttribute("locmach", locmach); e.setAttribute("indexrev",indexrev);
e.setAttribute("indexrev",indexrev); e.setAttribute("version", version);
e.setAttribute("version", version); e.setAttribute("folio", folio);
e.setAttribute("folio", folio); e.setAttribute("auto_page_num", auto_page_num);
e.setAttribute("auto_page_num", auto_page_num); e.setAttribute("date", exportDate());
e.setAttribute("date", exportDate()); e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right"));
e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right")); if (!template_name.isEmpty())
if (!template_name.isEmpty()) {
{ e.setAttribute("titleblocktemplate", template_name);
e.setAttribute("titleblocktemplate", template_name); e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection));
e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection)); }
}
if (context.keys().count()) {
if (context.keys().count()) { QDomElement properties = e.ownerDocument().createElement("properties");
QDomElement properties = e.ownerDocument().createElement("properties"); context.toXml(properties);
context.toXml(properties); e.appendChild(properties);
e.appendChild(properties); }
}
} }
QDomElement TitleBlockProperties::toXml(QDomDocument &d) const { /**
Q_UNUSED(d)
qDebug() << "NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
return QDomElement();
}
/** RETURNS True
Importe le cartouche a partir des attributs XML de l'element e Importe le cartouche a partir des attributs XML de l'element e
@param e Element XML dont les attributs seront lus @param e Element XML dont les attributs seront lus
*/ */
bool TitleBlockProperties::fromXml(const QDomElement &e) { void TitleBlockProperties::fromXml(const QDomElement &e) {
// reads the historical fields
if (e.hasAttribute("author")) author = e.attribute("author");
// reads the historical fields if (e.hasAttribute("title")) title = e.attribute("title");
propertyString(e, "author", &author); if (e.hasAttribute("filename")) filename = e.attribute("filename");
propertyString(e, "title", &title); if (e.hasAttribute("plant")) plant = e.attribute("plant");
propertyString(e, "filename", &filename); if (e.hasAttribute("locmach")) locmach = e.attribute("locmach");
propertyString(e, "plant", &plant); if (e.hasAttribute("indexrev")) indexrev = e.attribute("indexrev");
propertyString(e, "locmach", &locmach); if (e.hasAttribute("version")) version = e.attribute("version");
propertyString(e, "indexrev", &indexrev); if (e.hasAttribute("folio")) folio = e.attribute("folio");
propertyString(e, "version", &version); if (e.hasAttribute("auto_page_num")) auto_page_num = e.attribute("auto_page_num");
propertyString(e, "folio", &folio); if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
propertyString(e, "auto_page_num", &auto_page_num); if (e.hasAttribute("displayAt")) display_at = (e.attribute("displayAt") == "bottom" ? Qt::BottomEdge : Qt::RightEdge);
QString date;
propertyString(e, "date", &date); // reads the template used to render the title block
setDateFromString(date); if (e.hasAttribute("titleblocktemplate"))
{
QString display_at_temp; template_name = e.attribute("titleblocktemplate");
if (propertyString(e, "displayAt", &display_at_temp) == PropertyFlags::Success) collection = QET::qetCollectionFromString(e.attribute("titleblocktemplateCollection"));
display_at = (display_at_temp == "bottom" ? Qt::BottomEdge : Qt::RightEdge); // otherwise it gets default in header file
// reads the template used to render the title block
if (propertyString(e, "titleblocktemplate", &template_name) == PropertyFlags::Success) {
QString tbc;
if (propertyString(e, "titleblocktemplateCollection", &tbc) == PropertyFlags::Success)
collection = QET::qetCollectionFromString(tbc);
} }
// reads the additional fields used to fill the title block // reads the additional fields used to fill the title block
@@ -138,7 +128,6 @@ bool TitleBlockProperties::fromXml(const QDomElement &e) {
foreach (QDomElement e, QET::findInDomElement(e, "properties")) { foreach (QDomElement e, QET::findInDomElement(e, "properties")) {
context.fromXml(e); context.fromXml(e);
} }
return true;
} }
/** /**
@@ -169,7 +158,7 @@ void TitleBlockProperties::toSettings(QSettings &settings, const QString &prefix
@param settings Parametres a lire @param settings Parametres a lire
@param prefix prefixe a ajouter devant les noms des parametres @param prefix prefixe a ajouter devant les noms des parametres
*/ */
void TitleBlockProperties::fromSettings(const QSettings &settings, const QString &prefix) { void TitleBlockProperties::fromSettings(QSettings &settings, const QString &prefix) {
title = settings.value(prefix + "title").toString(); title = settings.value(prefix + "title").toString();
author = settings.value(prefix + "author").toString(); author = settings.value(prefix + "author").toString();
filename = settings.value(prefix + "filename").toString(); filename = settings.value(prefix + "filename").toString();

View File

@@ -21,14 +21,12 @@
#include "diagramcontext.h" #include "diagramcontext.h"
#include "qet.h" #include "qet.h"
#include "propertiesinterface.h"
/** /**
This class provides a container for the properties of a particular title This class provides a container for the properties of a particular title
block, i.e. title, author, date, filename, folio, template, custom block, i.e. title, author, date, filename, folio, template, custom
properties, ... properties, ...
*/ */
class TitleBlockProperties: public PropertiesInterface { class TitleBlockProperties {
public: public:
TitleBlockProperties(); TitleBlockProperties();
virtual ~TitleBlockProperties(); virtual ~TitleBlockProperties();
@@ -41,11 +39,10 @@ class TitleBlockProperties: public PropertiesInterface {
bool operator==(const TitleBlockProperties &); bool operator==(const TitleBlockProperties &);
bool operator!=(const TitleBlockProperties &); bool operator!=(const TitleBlockProperties &);
QDomElement toXml(QDomDocument &e) const override; void toXml(QDomElement &) const;
void toXml(QDomElement &e) const; void fromXml(const QDomElement &);
bool fromXml(const QDomElement &) override; void toSettings(QSettings &, const QString & = QString()) const;
void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString());
void fromSettings(const QSettings &, const QString & = QString()) override;
void setAutoPageNum(QString autonum) {auto_page_num = autonum;} void setAutoPageNum(QString autonum) {auto_page_num = autonum;}
@@ -64,11 +61,11 @@ class TitleBlockProperties: public PropertiesInterface {
QString version; ///< Version (displayed by the default template) QString version; ///< Version (displayed by the default template)
QString folio; ///< Folio information (displayed by the default template) QString folio; ///< Folio information (displayed by the default template)
QString auto_page_num; QString auto_page_num;
DateManagement useDate{UseDateValue}; ///< Wheter to use the date attribute 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" 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 DiagramContext context; ///< Container for the additional, user-defined fields
Qt::Edge display_at{Qt::Edge::BottomEdge}; ///< Edge to display the titleblock Qt::Edge display_at; ///< Edge to display the titleblock
QET::QetCollection collection{QET::QetCollection::Common}; ///<Specify the location of the title block QET::QetCollection collection; ///<Specify the location of the title block
private: private:
QString exportDate() const; QString exportDate() const;

View File

@@ -338,6 +338,7 @@ void TitleBlockTemplate::parseRows(const QString &rows_string) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList rows_descriptions = rows_string.split(QChar(';'), QString::SkipEmptyParts); QStringList rows_descriptions = rows_string.split(QChar(';'), QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
QStringList rows_descriptions = rows_string.split(QChar(';'), Qt::SkipEmptyParts); QStringList rows_descriptions = rows_string.split(QChar(';'), Qt::SkipEmptyParts);
#endif #endif
foreach (QString rows_description, rows_descriptions) { foreach (QString rows_description, rows_descriptions) {
@@ -365,6 +366,7 @@ void TitleBlockTemplate::parseColumns(const QString &cols_string) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList cols_descriptions = cols_string.split(QChar(';'), QString::SkipEmptyParts); QStringList cols_descriptions = cols_string.split(QChar(';'), QString::SkipEmptyParts);
#else #else
#pragma message("@TODO remove code for QT 5.14 or later")
QStringList cols_descriptions = cols_string.split(QChar(';'), Qt::SkipEmptyParts); QStringList cols_descriptions = cols_string.split(QChar(';'), Qt::SkipEmptyParts);
#endif #endif
foreach (QString cols_description, cols_descriptions) { foreach (QString cols_description, cols_descriptions) {

View File

@@ -21,7 +21,13 @@
#include <QThread> #include <QThread>
#include <QDate> #include <QDate>
#include <QScreen>
#include <QProcess>
/**
@brief AboutQETDialog::AboutQETDialog
@param parent
*/
AboutQETDialog::AboutQETDialog(QWidget *parent) : AboutQETDialog::AboutQETDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::AboutQETDialog) ui(new Ui::AboutQETDialog)
@@ -36,11 +42,17 @@ AboutQETDialog::AboutQETDialog(QWidget *parent) :
setLicence(); setLicence();
} }
/**
@brief AboutQETDialog::~AboutQETDialog
*/
AboutQETDialog::~AboutQETDialog() AboutQETDialog::~AboutQETDialog()
{ {
delete ui; delete ui;
} }
/**
@brief AboutQETDialog::setAbout
*/
void AboutQETDialog::setAbout() void AboutQETDialog::setAbout()
{ {
@@ -55,6 +67,9 @@ void AboutQETDialog::setAbout()
ui->m_about_label->setText(str); ui->m_about_label->setText(str);
} }
/**
@brief AboutQETDialog::setAuthors
*/
void AboutQETDialog::setAuthors() void AboutQETDialog::setAuthors()
{ {
addAuthor(ui->m_author_label, "Benoît Ansieau", "benoit@qelectrotech.org", tr("Idée originale")); addAuthor(ui->m_author_label, "Benoît Ansieau", "benoit@qelectrotech.org", tr("Idée originale"));
@@ -66,6 +81,9 @@ void AboutQETDialog::setAuthors()
addAuthor(ui->m_author_label, "Abhishek Bansal", "abhishek@qelectrotech.org", tr("Développement")); addAuthor(ui->m_author_label, "Abhishek Bansal", "abhishek@qelectrotech.org", tr("Développement"));
} }
/**
@brief AboutQETDialog::setTranslators
*/
void AboutQETDialog::setTranslators() void AboutQETDialog::setTranslators()
{ {
addAuthor(ui->m_translators_label, "Alfredo Carreto", "electronicos_mx@yahoo.com.mx", tr("Traduction en espagnol")); addAuthor(ui->m_translators_label, "Alfredo Carreto", "electronicos_mx@yahoo.com.mx", tr("Traduction en espagnol"));
@@ -94,6 +112,9 @@ void AboutQETDialog::setTranslators()
addAuthor(ui->m_translators_label, "Gábor Gubányi", "gubanyig@gmail.com", tr("Traduction en hongrois")); addAuthor(ui->m_translators_label, "Gábor Gubányi", "gubanyig@gmail.com", tr("Traduction en hongrois"));
} }
/**
@brief AboutQETDialog::setContributors
*/
void AboutQETDialog::setContributors() void AboutQETDialog::setContributors()
{ {
addAuthor(ui->m_contrib_label, "Remi Collet", "remi@fedoraproject.org", tr("Paquets Fedora et Red Hat")); addAuthor(ui->m_contrib_label, "Remi Collet", "remi@fedoraproject.org", tr("Paquets Fedora et Red Hat"));
@@ -117,6 +138,9 @@ void AboutQETDialog::setContributors()
addAuthor(ui->m_contrib_label, "Maximilian Federle", "", tr("Paquets Snap")); addAuthor(ui->m_contrib_label, "Maximilian Federle", "", tr("Paquets Snap"));
} }
/**
@brief AboutQETDialog::setVersion
*/
void AboutQETDialog::setVersion() void AboutQETDialog::setVersion()
{ {
QString str = "<span style=\"font-weight:bold;font-size:16pt;\">QElectroTech V " + QET::displayedVersion + "</span>"; QString str = "<span style=\"font-weight:bold;font-size:16pt;\">QElectroTech V " + QET::displayedVersion + "</span>";
@@ -129,6 +153,12 @@ void AboutQETDialog::setVersion()
compilation_info += " : " + QString(__TIME__); compilation_info += " : " + QString(__TIME__);
compilation_info += " <br>Run with Qt "+ QString(qVersion()); compilation_info += " <br>Run with Qt "+ QString(qVersion());
compilation_info += " using" + QString(" %1 thread(s)").arg(QThread::idealThreadCount()); compilation_info += " using" + QString(" %1 thread(s)").arg(QThread::idealThreadCount());
QProcess macoscpuinfo;
macoscpuinfo.start("bash", QStringList() << "-c" << "sysctl -n machdep.cpu.brand_string");
macoscpuinfo.waitForFinished();
QString macosOutput = macoscpuinfo.readAllStandardOutput();
compilation_info += "<br>"" CPU : " + QString(macosOutput.toLocal8Bit().constData());
compilation_info += "<br>" " OS : " + QString(QSysInfo::kernelType()); compilation_info += "<br>" " OS : " + QString(QSysInfo::kernelType());
compilation_info += " - " + QString(QSysInfo::currentCpuArchitecture()); compilation_info += " - " + QString(QSysInfo::currentCpuArchitecture());
compilation_info += " - Version : " + QString(QSysInfo::prettyProductName()); compilation_info += " - Version : " + QString(QSysInfo::prettyProductName());
@@ -140,15 +170,61 @@ void AboutQETDialog::setVersion()
compilation_info += " : " + QString(__TIME__); compilation_info += " : " + QString(__TIME__);
compilation_info += " <br>Run with Qt "+ QString(qVersion()); compilation_info += " <br>Run with Qt "+ QString(qVersion());
compilation_info += " using" + QString(" %1 thread(s)").arg(QThread::idealThreadCount()); compilation_info += " using" + QString(" %1 thread(s)").arg(QThread::idealThreadCount());
QString OSName = QSysInfo::kernelType();
if (OSName == "linux")
{
QProcess linuxcpuinfo;
linuxcpuinfo.start("bash", QStringList() << "-c" << "cat /proc/cpuinfo |grep 'model name' | uniq");
linuxcpuinfo.waitForFinished();
QString linuxOutput = linuxcpuinfo.readAllStandardOutput();
compilation_info += "<br>"" CPU : " + QString(linuxOutput.toLocal8Bit().constData());
QProcess p;
p.start("awk", QStringList() << "/MemTotal/ { print $2 }" << "/proc/meminfo");
p.waitForFinished();
QString memory = p.readAllStandardOutput();
compilation_info += "<br>" + QString("RAM Total : %1 MB").arg(memory.toLong() / 1024);
p.close();
QProcess qp;
qp.start("awk", QStringList() << "/MemAvailable/ {print $2}" << "/proc/meminfo");
qp.waitForFinished();
QString AvailableMemory = qp.readAllStandardOutput();
compilation_info += "<br>" + QString("RAM Available : %1 MB").arg(AvailableMemory.toLong() / 1024);
qp.close();
QProcess linuxgpuinfo;
linuxgpuinfo.start("bash", QStringList() << "-c" << "lspci | grep VGA | cut -d : -f 3");
linuxgpuinfo.waitForFinished();
QString linuxGPUOutput = linuxgpuinfo.readAllStandardOutput();
compilation_info += "<br>"" GPU : " + QString(linuxGPUOutput.toLocal8Bit().constData());
}
compilation_info += "<br>" " OS : " + QString(QSysInfo::kernelType()); compilation_info += "<br>" " OS : " + QString(QSysInfo::kernelType());
compilation_info += " - " + QString(QSysInfo::currentCpuArchitecture()); compilation_info += " - " + QString(QSysInfo::currentCpuArchitecture());
compilation_info += " - Version : " + QString(QSysInfo::prettyProductName()); compilation_info += " - Version : " + QString(QSysInfo::prettyProductName());
compilation_info += "</br>" " - Kernel : " + QString(QSysInfo::kernelVersion()); compilation_info += "</br>" " - Kernel : " + QString(QSysInfo::kernelVersion());
#endif #endif
#endif #endif
compilation_info += "<br> *** Qt screens *** </br>";
const auto screens = qApp->screens();
for (int ii = 0; ii < screens.count(); ++ii) {
compilation_info += "<br> ( "
+ QString::number(ii + 1)
+ " : "
+ QString::number(screens[ii]->geometry().width() * screens[ii]->devicePixelRatio())
+ " x "
+ QString::number(screens[ii]->geometry().height() * screens[ii]->devicePixelRatio())
+ " ) </br>";
}
ui->m_version_label->setText(str + compilation_info); ui->m_version_label->setText(str + compilation_info);
} }
/**
@brief AboutQETDialog::setLibraries
*/
void AboutQETDialog::setLibraries() void AboutQETDialog::setLibraries()
{ {
addLibrary(ui->m_libraries_label, "KDE lib", "https://api.kde.org"); addLibrary(ui->m_libraries_label, "KDE lib", "https://api.kde.org");
@@ -156,19 +232,22 @@ void AboutQETDialog::setLibraries()
addLibrary(ui->m_libraries_label, "pugixml", "https://pugixml.org"); addLibrary(ui->m_libraries_label, "pugixml", "https://pugixml.org");
} }
/**
@brief AboutQETDialog::setLicence
*/
void AboutQETDialog::setLicence() void AboutQETDialog::setLicence()
{ {
ui->m_license_text_edit->setPlainText(QET::license()); ui->m_license_text_edit->setPlainText(QET::license());
} }
/** /**
* @brief AboutQETDialog::addAuthor @brief AboutQETDialog::addAuthor
* Adds a person to the list of authors Adds a person to the list of authors
* @param label : QLabel which will add the person @param label : QLabel which will add the person
* @param name : Name of person @param name : Name of person
* @param email : E-mail address of the person @param email : E-mail address of the person
* @param work : Function / work done by the person @param work : Function / work done by the person
*/ */
void AboutQETDialog::addAuthor(QLabel *label, const QString &name, const QString &email, const QString &work) void AboutQETDialog::addAuthor(QLabel *label, const QString &name, const QString &email, const QString &work)
{ {
QString new_text = label->text(); QString new_text = label->text();
@@ -180,6 +259,12 @@ void AboutQETDialog::addAuthor(QLabel *label, const QString &name, const QString
label->setText(new_text); label->setText(new_text);
} }
/**
@brief AboutQETDialog::addLibrary
@param label
@param name
@param link
*/
void AboutQETDialog::addLibrary(QLabel *label, const QString &name, const QString &link) void AboutQETDialog::addLibrary(QLabel *label, const QString &name, const QString &link)
{ {
QString new_text = label->text(); QString new_text = label->text();

View File

@@ -26,6 +26,9 @@ namespace Ui {
class AboutQETDialog; class AboutQETDialog;
} }
/**
@brief The AboutQETDialog class
*/
class AboutQETDialog : public QDialog class AboutQETDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@@ -42,8 +45,13 @@ class AboutQETDialog : public QDialog
void setVersion(); void setVersion();
void setLibraries(); void setLibraries();
void setLicence(); void setLicence();
void addAuthor(QLabel *label, const QString &name, const QString &email, const QString &work); void addAuthor(QLabel *label,
void addLibrary(QLabel *label, const QString &name, const QString &link); const QString &name,
const QString &email,
const QString &work);
void addLibrary(QLabel *label,
const QString &name,
const QString &link);
private: private:
Ui::AboutQETDialog *ui; Ui::AboutQETDialog *ui;

View File

@@ -61,6 +61,7 @@ BOMExportDialog::BOMExportDialog(QETProject *project, QWidget *parent) :
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), [this](int id) connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), [this](int id)
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idClicked), [this](int id) connect(&m_button_group, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idClicked), [this](int id)
#endif #endif
{ {
@@ -154,6 +155,7 @@ int BOMExportDialog::exec()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
stream << getBom() << endl; stream << getBom() << endl;
#else #else
#pragma message("@TODO remove code for QT 5.15 or later")
stream << getBom() << &Qt::endl(stream); stream << getBom() << &Qt::endl(stream);
#endif #endif
} }

View File

@@ -16,6 +16,7 @@ CompositeTextEditDialog::CompositeTextEditDialog(DynamicElementTextItem *text, Q
m_default_text = m_text->compositeText(); m_default_text = m_text->compositeText();
ui->m_plain_text_edit->setPlainText(m_default_text); ui->m_plain_text_edit->setPlainText(m_default_text);
#if QT_VERSION >= 0x050300 #if QT_VERSION >= 0x050300
#pragma message("@TODO remove code for QT 5.3 or later")
ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible")); ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible"));
#endif #endif
setUpComboBox(); setUpComboBox();
@@ -29,6 +30,7 @@ CompositeTextEditDialog::CompositeTextEditDialog(QString text, QWidget *parent)
m_default_text = std::move(text); m_default_text = std::move(text);
ui->m_plain_text_edit->setPlainText(m_default_text); ui->m_plain_text_edit->setPlainText(m_default_text);
#if QT_VERSION >= 0x050300 #if QT_VERSION >= 0x050300
#pragma message("@TODO remove code for QT 5.3 or later")
ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible")); ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible"));
#endif #endif
setUpComboBox(); setUpComboBox();

View File

@@ -1158,8 +1158,6 @@ void DynamicElementTextModel::enableGroupRotationAndPos(ElementTextItemGroup *gr
void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi) void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
{ {
DynamicElementTextItem *deti = textFromItem(qsi); DynamicElementTextItem *deti = textFromItem(qsi);
if (deti->searchedElement)
int stop = 1;
ElementTextItemGroup *etig = groupFromItem(qsi); ElementTextItemGroup *etig = groupFromItem(qsi);
if (!deti && !etig) if (!deti && !etig)
return; return;
@@ -1299,10 +1297,6 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, ValueType type) void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, ValueType type)
{ {
if (deti->searchedElement)
int stop = 1;
QStandardItem *qsi = m_texts_list.value(deti); QStandardItem *qsi = m_texts_list.value(deti);
if (!qsi) if (!qsi)
return; return;

Some files were not shown because too many files have changed in this diff Show More