Replace function by another one.

Replace function QETApp::elementInfoKeys() and
QETApp::elementInfoToVar(const QString &info) by function provided by
QETInformation.
This commit is contained in:
Claveau Joshua
2020-11-14 19:09:40 +01:00
parent c87fe8df2f
commit af7d1df5ab
14 changed files with 111 additions and 119 deletions

View File

@@ -24,6 +24,7 @@
#include "independenttextitem.h" #include "independenttextitem.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h" #include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "qetinformation.h"
SearchAndReplaceWorker::SearchAndReplaceWorker() SearchAndReplaceWorker::SearchAndReplaceWorker()
@@ -126,7 +127,7 @@ void SearchAndReplaceWorker::replaceElement(QList<Element *> list)
{ {
DiagramContext old_context; DiagramContext old_context;
DiagramContext new_context = old_context = elmt->elementInformations(); DiagramContext new_context = old_context = elmt->elementInformations();
for (QString key : QETApp::elementInfoKeys()) for (QString key : QETInformation::elementInfoKeys())
{ {
new_context.addValue(key, applyChange(old_context.value(key).toString(), new_context.addValue(key, applyChange(old_context.value(key).toString(),
m_element_context.value(key).toString())); m_element_context.value(key).toString()));

View File

@@ -99,7 +99,7 @@ void replaceAdvancedDialog::fillWhatComboBox(int index)
} }
} }
else if (index == 1) { else if (index == 1) {
for (QString str : QETApp::elementInfoKeys()) { for (QString str : QETInformation::elementInfoKeys()) {
ui->m_what_cb->addItem(QETInformation::translatedInfoKey(str), str); ui->m_what_cb->addItem(QETInformation::translatedInfoKey(str), str);
} }
} }

View File

@@ -73,7 +73,7 @@ void ReplaceElementDialog::buildWidget()
this->done(ui->m_button_box->buttonRole(button_)); this->done(ui->m_button_box->buttonRole(button_));
}); });
for (QString str : QETApp::elementInfoKeys()) for (QString str : QETInformation::elementInfoKeys())
{ {
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETInformation::translatedInfoKey(str), this); ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETInformation::translatedInfoKey(str), this);
eipw->setEraseTextVisible(true); eipw->setEraseTextVisible(true);

View File

@@ -32,6 +32,7 @@
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
#include "elementtextitemgroup.h" #include "elementtextitemgroup.h"
#include "QWidgetAnimation/qwidgetanimation.h" #include "QWidgetAnimation/qwidgetanimation.h"
#include "qetinformation.h"
#include <QSettings> #include <QSettings>
@@ -798,7 +799,7 @@ QStringList SearchAndReplaceWidget::searchTerms(Element *element)
{ {
QStringList list; QStringList list;
DiagramContext context = element->elementInformations(); DiagramContext context = element->elementInformations();
for (QString key : QETApp::elementInfoKeys()) for (QString key : QETInformation::elementInfoKeys())
{ {
QString str = context.value(key).toString(); QString str = context.value(key).toString();
if (!str.isEmpty()) { if (!str.isEmpty()) {

View File

@@ -160,7 +160,7 @@ void projectDataBase::removeElement(Element *element)
void projectDataBase::elementInfoChanged(Element *element) void projectDataBase::elementInfoChanged(Element *element)
{ {
auto hash = elementInfoToString(element); auto hash = elementInfoToString(element);
for (auto str : QETApp::elementInfoKeys()) { for (auto str : QETInformation::elementInfoKeys()) {
m_update_element_query.bindValue(":" + str, hash.value(str)); m_update_element_query.bindValue(":" + str, hash.value(str));
} }
m_update_element_query.bindValue(":uuid", element->uuid().toString()); m_update_element_query.bindValue(":uuid", element->uuid().toString());
@@ -286,7 +286,7 @@ bool projectDataBase::createDataBase()
//Create the element info table //Create the element info table
QString element_info_table("CREATE TABLE element_info(element_uuid VARCHAR(50) PRIMARY KEY NOT NULL,"); QString element_info_table("CREATE TABLE element_info(element_uuid VARCHAR(50) PRIMARY KEY NOT NULL,");
first_=true; first_=true;
for (auto string : QETApp::elementInfoKeys()) for (auto string : QETInformation::elementInfoKeys())
{ {
if (first_) { if (first_) {
first_ = false; first_ = false;
@@ -506,11 +506,11 @@ void projectDataBase::prepareQuery()
//INSERT ELEMENT INFO //INSERT ELEMENT INFO
QStringList bind_values; QStringList bind_values;
for (auto key : QETApp::elementInfoKeys()) { for (auto key : QETInformation::elementInfoKeys()) {
bind_values << key.prepend(":"); bind_values << key.prepend(":");
} }
QString insert_element_info("INSERT INTO element_info (element_uuid," + QString insert_element_info("INSERT INTO element_info (element_uuid," +
QETApp::elementInfoKeys().join(", ") + QETInformation::elementInfoKeys().join(", ") +
") VALUES (:uuid," + ") VALUES (:uuid," +
bind_values.join(", ") + bind_values.join(", ") +
")"); ")");
@@ -524,7 +524,7 @@ void projectDataBase::prepareQuery()
//UPDATE ELEMENT INFO //UPDATE ELEMENT INFO
QString update_str("UPDATE element_info SET "); QString update_str("UPDATE element_info SET ");
for (auto string : QETApp::elementInfoKeys()) { for (auto string : QETInformation::elementInfoKeys()) {
update_str.append(string + " = :" + string + ", "); update_str.append(string + " = :" + string + ", ");
} }
update_str.remove(update_str.length()-2, 2); //Remove the last ", " update_str.remove(update_str.length()-2, 2); //Remove the last ", "
@@ -541,7 +541,7 @@ void projectDataBase::prepareQuery()
QHash<QString, QString> projectDataBase::elementInfoToString(Element *elmt) QHash<QString, QString> projectDataBase::elementInfoToString(Element *elmt)
{ {
QHash<QString, QString> hash; //Store the value for each columns QHash<QString, QString> hash; //Store the value for each columns
for (auto key : QETApp::elementInfoKeys()) for (auto key : QETInformation::elementInfoKeys())
{ {
if (key == "label") { if (key == "label") {
hash.insert(key, elmt->actualLabel()); hash.insert(key, elmt->actualLabel());

View File

@@ -445,7 +445,7 @@ QStringList ElementQueryWidget::selectedKeys() const
*/ */
void ElementQueryWidget::setUpItems() void ElementQueryWidget::setUpItems()
{ {
for(QString key : QETApp::elementInfoKeys()) for(QString key : QETInformation::elementInfoKeys())
{ {
if (key == "formula") if (key == "formula")
continue; continue;

View File

@@ -209,7 +209,7 @@ void DynamicTextFieldEditor::fillInfoComboBox()
strl = QETInformation::folioReportInfoKeys(); strl = QETInformation::folioReportInfoKeys();
} }
else { else {
strl = QETApp::elementInfoKeys(); strl = QETInformation::elementInfoKeys();
} }
//We use a QMap because the keys of the map are sorted, then no matter the curent local, //We use a QMap because the keys of the map are sorted, then no matter the curent local,
//the value of the combo box are always alphabetically sorted //the value of the combo box are always alphabetically sorted

View File

@@ -386,47 +386,6 @@ ElementsCollectionCache *QETApp::collectionCache()
return(collections_cache_); return(collections_cache_);
} }
/**
@brief QETApp::elementInfoKeys
@return all available key for describe an element
*/
QStringList QETApp::elementInfoKeys()
{
QStringList info_list;
info_list << "formula"
<< "label"
<< "plant"
<< "location"
<< "comment"
<< "function"
<< "auxiliary1"
<< "auxiliary2"
<< "description"
<< "designation"
<< "manufacturer"
<< "manufacturer_reference"
<< "machine_manufacturer_reference"
<< "supplier"
<< "quantity"
<< "unity";
return info_list;
}
/**
@brief QETApp::elementInfoToVar
@param info
@return var in form %{my-var} corresponding to the info,
if there is not available var for the given info
the returned var is %{void}
@see QETApp::elementInfoKeys for list
*/
QString QETApp::elementInfoToVar(const QString &info)
{
if (elementInfoKeys().contains(info))
return QString("%{")+info+QString("}");
return (QString ("%{void}"));
}
/** /**
@brief QETApp::commonTitleBlockTemplatesCollection @brief QETApp::commonTitleBlockTemplatesCollection
@return the common title block templates collection, @return the common title block templates collection,

View File

@@ -73,8 +73,6 @@ class QETApp : public QObject
static void printLicense(); static void printLicense();
static ElementsCollectionCache *collectionCache(); static ElementsCollectionCache *collectionCache();
static QStringList elementInfoKeys();
static QString elementInfoToVar(const QString &info);
static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection();
static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection();

View File

@@ -21,44 +21,44 @@
#include "qetinformation.h" #include "qetinformation.h"
/** Default information related to element **/ /** Default information related to element **/
static QString ELMT_LABEL = "label"; static QString ELMT_LABEL = "label";
static QString ELMT_LABEL_VAR = "%{label}"; static QString ELMT_FORMULA = "formula";
static QString ELMT_COMMENT = "comment";
static QString ELMT_FUNCTION = "function";
static QString ELMT_AUX1 = "auxiliary1";
static QString ELMT_AUX2 = "auxiliary2";
static QString ELMT_DESCRIPTION = "description";
static QString ELMT_DESIGNATION = "designation";
static QString ELMT_MANUFACTURER = "manufacturer";
static QString ELMT_MANUFACTURER_REF = "manufacturer_reference";
static QString ELMT_MACHINE_MANUFACTURER_REF = "machine_manufacturer_reference";
static QString ELMT_SUPPLIER = "supplier";
static QString ELMT_QUANTITY = "quantity";
static QString ELMT_UNITY = "unity";
static QString ELMT_PLANT = "plant";
static QString ELMT_LOCATION = "location";
//Voir la suite dans QETApp::elementInfoKeys()
/** Default information related to conductor **/ /** Default information related to conductor **/
static QString COND_FUNCTION = "function"; static QString COND_FUNCTION = "function";
static QString COND_FUNCTION_VAR = "%{function}";
static QString COND_TENSION_PROTOCOL = "tension/protocol"; static QString COND_TENSION_PROTOCOL = "tension/protocol";
static QString COND_TENSION_PROTOCOL_var = "%{tension/protocol}";
static QString COND_COLOR = "conductor_color"; static QString COND_COLOR = "conductor_color";
static QString COND_COLOR_VAR = "%{conductor_color}";
static QString COND_SECTION = "conductor_section"; static QString COND_SECTION = "conductor_section";
static QString COND_SECTION_var = "%{conductor_section}";
static QString COND_FORMULA = "formula"; static QString COND_FORMULA = "formula";
static QString COND_FORMULA_VAR = "%{formula}";
static QString COND_TEXT = "text"; static QString COND_TEXT = "text";
static QString COND_TEXT_VAR = "%{text}";
/** Default information related to diagram **/ /** Default information related to diagram **/
static QString DIA_AUTHOR = "author"; static QString DIA_AUTHOR = "author";
static QString DIA_AUTHOR_VAR = "%{author}";
static QString DIA_DATE = "date"; static QString DIA_DATE = "date";
static QString DIA_DATE_VAR = "%{date}";
static QString DIA_DISPLAY_FOLIO = "display_folio"; static QString DIA_DISPLAY_FOLIO = "display_folio";
static QString DIA_DISPLAY_FOLIO_VAR = "%{display_folio}";
static QString DIA_FILENAME = "filename"; static QString DIA_FILENAME = "filename";
static QString DIA_FILENAME_VAR = "%{filename}";
static QString DIA_FOLIO = "folio"; static QString DIA_FOLIO = "folio";
static QString DIA_FOLIO_VAR = "%{folio}";
static QString DIA_INDEX_REV = "indexrev"; static QString DIA_INDEX_REV = "indexrev";
static QString DIA_INDEX_REV_VAR = "%{indexrev}";
static QString DIA_LOCMACH = "locmach"; static QString DIA_LOCMACH = "locmach";
static QString DIA_LOCMACH_VAR = "%{locmach}";
static QString DIA_PLANT = "plant"; static QString DIA_PLANT = "plant";
static QString DIA_PLANT_VAR = "%{plant}";
static QString DIA_POS = "pos"; static QString DIA_POS = "pos";
static QString DIA_POS_VAR = "%{pos}";
static QString DIA_TITLE = "title"; static QString DIA_TITLE = "title";
static QString DIA_TITLE_VAR = "%{title}";
/** /**
@brief QETInformation::titleblockInfoKeys @brief QETInformation::titleblockInfoKeys
@@ -101,29 +101,10 @@ QStringList QETInformation::titleblockInfoKeys()
*/ */
QString QETInformation::titleblockInfoKeysToVar(const QString &info) QString QETInformation::titleblockInfoKeysToVar(const QString &info)
{ {
if (info == DIA_AUTHOR) return DIA_AUTHOR_VAR; if (titleblockInfoKeys().contains(info))
else if (info == DIA_DATE) return DIA_DATE_VAR; return infoToVar(info);
else if (info == DIA_TITLE) return DIA_TITLE_VAR; else
else if (info == DIA_FILENAME) return DIA_FILENAME_VAR; return QString("%{void}");
else if (info == DIA_PLANT) return DIA_PLANT_VAR;
else if (info == DIA_LOCMACH) return DIA_LOCMACH_VAR;
else if (info == DIA_INDEX_REV) return DIA_INDEX_REV_VAR;
else if (info == "version") return QString("%{version}");
else if (info == DIA_FOLIO) return DIA_FOLIO_VAR;
else if (info == "folio-id") return QString("%{folio-id}");
else if (info == "folio-total") return QString("%{folio-total}");
else if (info == "previous-folio-num") return QString("%{previous-folio-num}");
else if (info == "next-folio-num") return QString("%{next-folio-num}");
else if (info == "projecttitle") return QString("%{projecttitle}");
else if (info == "projectpath") return QString("%{projectpath}");
else if (info == "projectfilename") return QString("%{projectfilename}");
else if (info == "saveddate") return QString("%{saveddate}");
else if (info == "saveddate-eu") return QString("%{saveddate-eu}");
else if (info == "saveddate-us") return QString("%{saveddate-us}");
else if (info == "savedtime") return QString("%{savedtime}");
else if (info == "savedfilename") return QString("%{savedfilename}");
else if (info == "savedfilepath") return QString("%{savedfilepath}");
else return QString("%{void}");
} }
/** /**
@@ -157,11 +138,11 @@ QStringList QETInformation::folioReportInfoKeys()
QHash<QString, QString> QETInformation::folioReportInfoKeyToVar() QHash<QString, QString> QETInformation::folioReportInfoKeyToVar()
{ {
QHash <QString, QString> H_; QHash <QString, QString> H_;
H_.insert(ELMT_LABEL, ELMT_LABEL_VAR); H_.insert(ELMT_LABEL, infoToVar(ELMT_LABEL));
H_.insert(COND_FUNCTION, COND_FUNCTION_VAR); H_.insert(COND_FUNCTION, infoToVar(COND_FUNCTION));
H_.insert(COND_TENSION_PROTOCOL, COND_TENSION_PROTOCOL_var); H_.insert(COND_TENSION_PROTOCOL, infoToVar(COND_TENSION_PROTOCOL));
H_.insert(COND_COLOR, COND_COLOR_VAR); H_.insert(COND_COLOR, infoToVar(COND_COLOR));
H_.insert(COND_SECTION, COND_SECTION_var); H_.insert(COND_SECTION, infoToVar(COND_SECTION));
return H_; return H_;
} }
@@ -192,6 +173,52 @@ QStringList QETInformation::diagramInfoKeys()
return list; return list;
} }
QStringList QETInformation::elementInfoKeys()
{
QStringList list = { ELMT_FORMULA,
ELMT_LABEL,
ELMT_PLANT,
ELMT_LOCATION,
ELMT_COMMENT,
ELMT_FUNCTION,
ELMT_AUX1,
ELMT_AUX2,
ELMT_DESCRIPTION,
ELMT_DESIGNATION,
ELMT_MANUFACTURER,
ELMT_MANUFACTURER_REF,
ELMT_MACHINE_MANUFACTURER_REF,
ELMT_SUPPLIER,
ELMT_QUANTITY,
ELMT_UNITY};
return list;
}
/**
* @brief QETInformation::elementInfoToVar
* @param info
* @return The info to a variable or %{void} if @info
* is not an element information
*/
QString QETInformation::elementInfoToVar(const QString &info)
{
if (QETInformation::elementInfoKeys().contains(info))
return infoToVar(info);
else
return (QString ("%{void}"));
}
/**
* @brief QETInformation::infoToVar
* @param info
* @return return the string @info prepended by %{ ans appended by }
* exemple : if info is label, the returned string is %{label}
*/
QString QETInformation::infoToVar(const QString &info)
{
return QString("%{")+info+QString("}");
}
/** /**
* @brief QETInformation::translatedInfoKey * @brief QETInformation::translatedInfoKey
* @param info * @param info
@@ -224,20 +251,20 @@ QString QETInformation::translatedInfoKey(const QString &info)
else if (info == "savedtime") return QObject::tr("Heure d'enregistrement du fichier"); else if (info == "savedtime") return QObject::tr("Heure d'enregistrement du fichier");
else if (info == "savedfilename") return QObject::tr("Nom du fichier enregistré"); else if (info == "savedfilename") return QObject::tr("Nom du fichier enregistré");
else if (info == "savedfilepath") return QObject::tr("Chemin du fichier enregistré"); else if (info == "savedfilepath") return QObject::tr("Chemin du fichier enregistré");
else if (info == "formula") return QObject::tr("Formule du label"); else if (info == ELMT_LABEL) return QObject::tr("Formule du label");
else if (info == ELMT_LABEL) return QObject::tr("Label"); else if (info == ELMT_LABEL) return QObject::tr("Label");
else if (info == "comment") return QObject::tr("Commentaire"); else if (info == ELMT_COMMENT) return QObject::tr("Commentaire");
else if (info == "function") return QObject::tr("Fonction"); else if (info == ELMT_FUNCTION) return QObject::tr("Fonction");
else if (info == "auxiliary1") return QObject::tr("Bloc auxiliaire 1"); else if (info == ELMT_AUX1) return QObject::tr("Bloc auxiliaire 1");
else if (info == "auxiliary2") return QObject::tr("Bloc auxiliaire 2"); else if (info == ELMT_AUX2) return QObject::tr("Bloc auxiliaire 2");
else if (info == "description") return QObject::tr("Description textuelle"); else if (info == ELMT_DESCRIPTION) return QObject::tr("Description textuelle");
else if (info == "designation") return QObject::tr("Numéro d'article"); else if (info == ELMT_DESIGNATION) return QObject::tr("Numéro d'article");
else if (info == "manufacturer") return QObject::tr("Fabricant"); else if (info == ELMT_MANUFACTURER) return QObject::tr("Fabricant");
else if (info == "manufacturer_reference") return QObject::tr("Numéro de commande"); else if (info == ELMT_MANUFACTURER_REF) return QObject::tr("Numéro de commande");
else if (info == "machine_manufacturer_reference") return QObject::tr("Numéro interne"); else if (info == ELMT_MACHINE_MANUFACTURER_REF) return QObject::tr("Numéro interne");
else if (info == "supplier") return QObject::tr("Fournisseur"); else if (info == ELMT_SUPPLIER) return QObject::tr("Fournisseur");
else if (info == "quantity") return QObject::tr("Quantité"); else if (info == ELMT_QUANTITY) return QObject::tr("Quantité");
else if (info == "unity") return QObject::tr("Unité"); else if (info == ELMT_UNITY) return QObject::tr("Unité");
else if (info == COND_FUNCTION) return QObject::tr("Fonction"); else if (info == COND_FUNCTION) return QObject::tr("Fonction");
else if (info == COND_TENSION_PROTOCOL) return QObject::tr("Tension / Protocole"); else if (info == COND_TENSION_PROTOCOL) return QObject::tr("Tension / Protocole");
else if (info == COND_COLOR) return QObject::tr("Couleur du fil"); else if (info == COND_COLOR) return QObject::tr("Couleur du fil");

View File

@@ -1,4 +1,4 @@
/* /*
Copyright 2006-2020 The QElectroTech Team Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech. This file is part of QElectroTech.
@@ -35,11 +35,17 @@ namespace QETInformation
QStringList titleblockInfoKeys(); QStringList titleblockInfoKeys();
QString titleblockInfoKeysToVar(const QString &info); QString titleblockInfoKeysToVar(const QString &info);
QHash <QString, QString> titleblockTranslatedKeyHashVar(); QHash <QString, QString> titleblockTranslatedKeyHashVar();
QStringList folioReportInfoKeys(); QStringList folioReportInfoKeys();
QHash <QString, QString> folioReportInfoKeyToVar(); QHash <QString, QString> folioReportInfoKeyToVar();
QStringList conductorInfoKeys(); QStringList conductorInfoKeys();
QStringList diagramInfoKeys(); QStringList diagramInfoKeys();
QStringList elementInfoKeys();
QString elementInfoToVar(const QString &info);
QString infoToVar(const QString &info);
QString translatedInfoKey(const QString &info); QString translatedInfoKey(const QString &info);
} }

View File

@@ -59,7 +59,7 @@ void CompositeTextEditDialog::setUpComboBox()
} }
else else
{ {
qstrl = QETApp::elementInfoKeys(); qstrl = QETInformation::elementInfoKeys();
qstrl.removeAll("formula"); qstrl.removeAll("formula");
} }
@@ -67,7 +67,7 @@ void CompositeTextEditDialog::setUpComboBox()
//the value of the combo box are always alphabetically sorted //the value of the combo box are always alphabetically sorted
QMap <QString, QString> info_map; QMap <QString, QString> info_map;
for(const QString& str : qstrl) { for(const QString& str : qstrl) {
info_map.insert(QETInformation::translatedInfoKey(str), QETApp::elementInfoToVar(str)); info_map.insert(QETInformation::translatedInfoKey(str), QETInformation::elementInfoToVar(str));
} }
for(const QString& key : info_map.keys()) { for(const QString& key : info_map.keys()) {
ui->m_info_cb->addItem(key, info_map.value(key)); ui->m_info_cb->addItem(key, info_map.value(key));

View File

@@ -1912,7 +1912,7 @@ QStringList DynamicTextItemDelegate::availableInfo(
return qstrl; return qstrl;
QStringList info_list = QETApp::elementInfoKeys(); QStringList info_list = QETInformation::elementInfoKeys();
info_list.removeAll("formula"); //No need to have formula info_list.removeAll("formula"); //No need to have formula
DiagramContext dc = elmt->elementInformations(); DiagramContext dc = elmt->elementInformations();

View File

@@ -178,7 +178,7 @@ void ElementInfoWidget::disableLiveEdit()
*/ */
void ElementInfoWidget::buildInterface() void ElementInfoWidget::buildInterface()
{ {
for (auto str : QETApp::elementInfoKeys()) for (auto str : QETInformation::elementInfoKeys())
{ {
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETInformation::translatedInfoKey(str), this); ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETInformation::translatedInfoKey(str), this);
ui->scroll_vlayout->addWidget(eipw); ui->scroll_vlayout->addWidget(eipw);