[qet] [4577] %seq is not hardcoded anymore. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4577
Author: dfochi
Date: 2016-07-14 19:16:14 +0200 (Thu, 14 Jul 2016)
Log Message:
-----------
%seq is not hardcoded anymore. Autonums with the same formula are not conflicted anymore.
Modified Paths:
--------------
trunk/sources/diagramevent/diagrameventaddelement.cpp
trunk/sources/projectconfigpages.cpp
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/element.h
trunk/sources/qetproject.cpp
trunk/sources/qetproject.h
trunk/sources/ui/autonumberingdockwidget.cpp
trunk/sources/ui/selectautonumw.cpp
trunk/sources/ui/selectautonumw.h
Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -233,6 +233,6 @@
can.numerate();
};
m_diagram -> undoStack().push(undo_object);
- element->assignSeq();
+ element->setSeq();
element->updateLabel();
}
Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/projectconfigpages.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -411,16 +411,19 @@
connect(tab_widget,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int)));
//Conductor Tab
+ connect (m_context_cb_conductor, SIGNAL (currentTextChanged(QString)), m_saw_conductor, SLOT(applyEnableOnContextChanged(QString)));
connect (m_context_cb_conductor, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_conductor(QString)));
connect (m_saw_conductor, SIGNAL (applyPressed()), this, SLOT (saveContext_conductor()));
connect (m_remove_pb_conductor, SIGNAL (clicked()), this, SLOT (removeContext_conductor()));
//Element Tab
+ connect (m_context_cb_element, SIGNAL (currentTextChanged(QString)), m_saw_element, SLOT(applyEnableOnContextChanged(QString)));
connect (m_context_cb_element, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_element(QString)));
connect (m_saw_element, SIGNAL (applyPressed()), this, SLOT (saveContext_element()));
connect (m_remove_pb_element, SIGNAL (clicked()), this, SLOT (removeContext_element()));
//Folio Tab
+ connect (m_context_cb_folio, SIGNAL (currentTextChanged(QString)), m_saw_folio, SLOT(applyEnableOnContextChanged(QString)));
connect (m_context_cb_folio, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext_folio(QString)));
connect (m_saw_folio, SIGNAL (applyPressed()), this, SLOT (saveContext_folio()));
connect (m_remove_pb_folio, SIGNAL (clicked()), this, SLOT (removeContext_folio()));
@@ -516,21 +519,21 @@
if (m_context_cb_element -> currentText() == tr("Nom de la nouvelle numérotation")) {
project_->addElementAutoNum (tr("Sans nom"), m_saw_element -> toNumContext());
project()->addElementAutoNumFormula (tr("Sans nom"), m_saw_element->elementFormula()); //add hash <title, formula>
- project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //add last added element formula to current formula
+ project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(),tr("Sans nom")); //add last added element formula to current formula
m_context_cb_element -> addItem(tr("Sans nom"));
}
// If the text isn't yet to the autonum of the project, add this new item to the combo box.
else if ( !project_ -> elementAutoNum().keys().contains( m_context_cb_element->currentText())) {
project()->addElementAutoNum(m_context_cb_element->currentText(), m_saw_element->toNumContext()); //add hash <title, numcontext>
project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->elementFormula()); //add hash <title, formula>
- project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //add last added element formula to current formula
+ project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(),m_context_cb_element->currentText()); //add last added element formula to current formula
m_context_cb_element -> addItem(m_context_cb_element->currentText());
}
// Else, the text already exist in the autonum of the project, just update the context
else {
project_->addElementAutoNum (m_context_cb_element -> currentText(), m_saw_element -> toNumContext()); //add hash <title, numcontext>
project()->addElementAutoNumFormula (m_context_cb_element->currentText(), m_saw_element->elementFormula()); //add hash <title, formula>
- project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula()); //add last added element formula to current formula
+ project()->setElementAutoNumCurrentFormula (m_saw_element->elementFormula(), m_context_cb_element->currentText()); //add last added element formula to current formula
}
project()->elementAutoNumAdded();
}
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/qetgraphicsitem/element.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -406,11 +406,32 @@
//load prefix
m_prefix = e.attribute("prefix");
+ //Load Unit Sequential Values
+ int i = 0;
+ while (!e.attribute("sequ_" + QString::number(i+1)).isEmpty()) {
+ seq_unit.append(e.attribute("sequ_" + QString::number(i+1)));
+ i++;
+ }
+
+ //Load Ten Sequential Values
+ i = 0;
+ while (!e.attribute("seqt_" + QString::number(i+1)).isEmpty()) {
+ seq_ten.append(e.attribute("seqt_" + QString::number(i+1)));
+ i++;
+ }
+
+ //Load Hundred Sequential Values
+ i = 0;
+ while (!e.attribute("seqh_" + QString::number(i+1)).isEmpty()) {
+ seq_hundred.append(e.attribute("seqh_" + QString::number(i+1)));
+ i++;
+ }
+
//load informations
m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
- //Position and selection.
- //We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
+ //Position and selection.
+ //We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
@@ -443,6 +464,21 @@
element.setAttribute("uuid", uuid().toString());
// prefix
element.setAttribute("prefix", m_prefix);
+
+ //Save Unit Sequential Values
+ for (int i = 0; i < seq_unit.size(); i++) {
+ element.setAttribute("sequ_" + QString::number(i+1),seq_unit.at(i));
+ }
+
+ //Save Ten Sequential Values
+ for (int i = 0; i < seq_ten.size(); i++) {
+ element.setAttribute("seqt_" + QString::number(i+1),seq_ten.at(i));
+ }
+
+ //Save Hundred Sequential Values
+ for (int i = 0; i < seq_hundred.size(); i++) {
+ element.setAttribute("seqh_" + QString::number(i+1),seq_hundred.at(i));
+ }
// position, selection et orientation
element.setAttribute("x", QString("%1").arg(pos().x()));
@@ -684,59 +720,74 @@
label.replace("%prefix", elmt->getPrefix());
if (label.contains("%prefix"))
label.replace("%prefix",this->getPrefix());
+ label = assignSeq(label);
return label;
}
/**
- * @brief Element::assignSeq()
- * Assign sequential values to element label
+ * @brief Element::setSeq()
+ * Set sequential values to element
*/
-void Element::assignSeq() {
+void Element::setSeq() {
DiagramContext &dc = this->rElementInformations();
+ QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
QString formula = diagram()->project()->elementAutoNumFormula();
- QHash <QString,QString> hash = diagram()->project()->elementAutoNum_2();
- QString formula_name = hash.key(formula);
QString label = dc["label"].toString();
- NumerotationContext nc = diagram()->project()->elementAutoNum(formula_name);
+ NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
NumerotationContextCommands ncc (nc);
if (!nc.isEmpty()) {
+ //Unit Format
if (label.contains("%sequ_")) {
- int count = 1;
for (int i = 0; i < nc.size(); i++) {
if (nc.itemAt(i).at(0) == "unit") {
- label.replace("%sequ_" + QString::number(count), QString::number(nc.itemAt(i).at(1).toInt()));
- count++;
+ seq_unit.append(QString::number(nc.itemAt(i).at(1).toInt()));
}
}
}
+ //Ten Format
if (label.contains("%seqt_")) {
- int count = 1;
for (int i = 0; i < nc.size(); i++) {
if (nc.itemAt(i).at(0) == "ten") {
- QString number = QString("%1").arg(nc.itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
- label.replace("%seqt_" + QString::number(count), number);
- count++;
+ QString number = QString ("%1").arg(nc.itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
+ seq_ten.append(number);
}
}
}
+ //Hundred Format
if (label.contains("%seqh_")) {
- int count = 1;
for (int i = 0; i < nc.size(); i++) {
if (nc.itemAt(i).at(0) == "hundred") {
- QString number = QString("%1").arg(nc.itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
- label.replace("%seqh_" + QString::number(count), number);
- count++;
+ QString number = QString ("%1").arg(nc.itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
+ seq_hundred.append(number);
}
}
}
}
- dc.addValue("label",label);
- this->diagram()->project()->addElementAutoNum(formula_name,ncc.next());
- this->setElementInformations(dc);
- this->setTaggedText("label", label);
+ this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next());
}
/**
+ * @brief Element::assignSeq
+ * Replace sequential values to element label
+ * @param label to be replaced
+ * @return replaced label
+ */
+QString Element::assignSeq(QString label) {
+ for (int i = 1; i <= qMax(seq_unit.size(),qMax(seq_hundred.size(),seq_ten.size())); i++) {
+ if (label.contains("%sequ_" + QString::number(i))) {
+ label.replace("%sequ_" + QString::number(i),seq_unit.at(i-1));
+ }
+ if (label.contains("%seqt_" + QString::number(i))) {
+ label.replace("%seqt_" + QString::number(i),seq_ten.at(i-1));
+ }
+ if (label.contains("%seqh_" + QString::number(i))) {
+ label.replace("%seqh_" + QString::number(i),seq_hundred.at(i-1));
+ }
+ }
+ return label;
+}
+
+/**
* @brief ElementTextItem::setTaggedText
* Set text @newstr to the text tagged with @tagg.
* If tagg is found return the text item, else return NULL.
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/qetgraphicsitem/element.h 2016-07-14 17:16:14 UTC (rev 4577)
@@ -134,7 +134,8 @@
//about the herited class like contactelement for know
// kind of contact (simple tempo) or number of contact show by the element.
QString assignVariables (QString, Element *);
- void assignSeq ();
+ QString assignSeq (QString);
+ void setSeq ();
void setPrefix(QString);
QString getPrefix();
@@ -199,6 +200,9 @@
private:
bool m_mouse_over;
QString m_prefix;
+ QStringList seq_unit;
+ QStringList seq_ten;
+ QStringList seq_hundred;
};
Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/qetproject.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -445,6 +445,14 @@
}
/**
+ * @brief QETProject::elementCurrentAutoNum
+ * @return current element autonum title
+ */
+QString QETProject::elementCurrentAutoNum () const {
+ return m_current_element_autonum;
+}
+
+/**
* @brief QETProject::folioAutoNum
* @return All value of folio autonum stored in project
*/
@@ -474,14 +482,15 @@
/**
* @brief QETProject::setElementAutoNumCurrentFormula
- * Add the formula to the current formula
+ * Add the formula and title to the current formula and current autonum
* @param formula
+ * @param title
*/
-void QETProject::setElementAutoNumCurrentFormula(QString formula) {
+void QETProject::setElementAutoNumCurrentFormula(QString formula, QString title) {
m_current_element_formula = formula;
+ m_current_element_autonum = title;
}
-
/**
* @brief QETProject::addElementAutoNum
* Add a new element numerotation context. If key already exist,
@@ -1321,6 +1330,7 @@
}
if (!element_autonums.isNull())
{
+ m_current_element_autonum = element_autonums.attribute("current_autonum");
m_current_element_formula = element_autonums.attribute("current_formula");
foreach (QDomElement elmt, QET::findInDomElement(element_autonums, "element_autonum"))
{
@@ -1402,6 +1412,7 @@
//Export Element Autonums
QDomElement element_autonums = xml_document.createElement("element_autonums");
+ element_autonums.setAttribute("current_autonum", m_current_element_autonum);
element_autonums.setAttribute("current_formula", m_current_element_formula);
foreach (QString key, elementAutoNum().keys()) {
QDomElement element_autonum = elementAutoNum(key).toXml(xml_document, "element_autonum");
Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/qetproject.h 2016-07-14 17:16:14 UTC (rev 4577)
@@ -113,7 +113,7 @@
void addConductorAutoNum (QString key, NumerotationContext context);
void addElementAutoNum (QString key, NumerotationContext context);
void addElementAutoNumFormula (QString key, QString formula);
- void setElementAutoNumCurrentFormula (QString formula);
+ void setElementAutoNumCurrentFormula (QString formula, QString title);
void addFolioAutoNum (QString key, NumerotationContext context);
void removeConductorAutoNum (QString key);
void removeElementAutoNum (QString key);
@@ -123,6 +123,7 @@
NumerotationContext elementAutoNum(const QString &key) const;
QString elementAutoNumFormula(const QString key) const; //returns Formula
QString elementAutoNumFormula() const;
+ QString elementCurrentAutoNum () const;
bool autoConductor () const;
bool autoElement () const;
@@ -244,6 +245,7 @@
QHash <QString, QString> m_element_autonum_formula; //Title and Formula hash
QHash <QString, NumerotationContext> m_element_autonum; //Title and NumContext hash
QString m_current_element_formula;
+ QString m_current_element_autonum;
/// Folio List Sheets quantity for this project.
int folioSheetsQuantity;
bool m_auto_conductor;
Modified: trunk/sources/ui/autonumberingdockwidget.cpp
===================================================================
--- trunk/sources/ui/autonumberingdockwidget.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/ui/autonumberingdockwidget.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -148,6 +148,7 @@
ui->m_conductor_cb->setCurrentIndex(conductor_index);
//Element
+ QString current_element_autonum = project_->elementCurrentAutoNum();
QString element_formula = project_->elementAutoNumFormula();
QString active_element_autonum = project_->elementAutoNum_2().key(element_formula);
int el_index = ui->m_element_cb->findText(active_element_autonum);
@@ -209,9 +210,10 @@
*/
void AutoNumberingDockWidget::on_m_element_cb_activated(int) {
QString current_autonum = ui->m_element_cb->currentText();
- QString current_formula = project_->elementAutoNumFormula(current_autonum);
- if (current_formula!=NULL)
- project_->setElementAutoNumCurrentFormula(current_formula);
+ QString current_formula = project_->elementAutoNumFormula();
+ if (current_formula!=NULL) {
+ project_->setElementAutoNumCurrentFormula(current_formula, current_autonum);
+ }
}
/**
Modified: trunk/sources/ui/selectautonumw.cpp
===================================================================
--- trunk/sources/ui/selectautonumw.cpp 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/ui/selectautonumw.cpp 2016-07-14 17:16:14 UTC (rev 4577)
@@ -202,6 +202,14 @@
}
/**
+ * @brief SelectAutonumW::applyEnableOnContextChanged
+ * enable/disable the apply button after changing the autonum name
+ */
+void SelectAutonumW::applyEnableOnContextChanged(QString) {
+ applyEnable(true);
+}
+
+/**
* @brief SelectAutonumW::applyEnable
* enable/disable the apply button
*/
Modified: trunk/sources/ui/selectautonumw.h
===================================================================
--- trunk/sources/ui/selectautonumw.h 2016-07-14 11:58:56 UTC (rev 4576)
+++ trunk/sources/ui/selectautonumw.h 2016-07-14 17:16:14 UTC (rev 4577)
@@ -48,6 +48,9 @@
void applyPressed();
//SLOT
+ public slots:
+ void applyEnableOnContextChanged(QString);
+
private slots:
void on_add_button_clicked();
void on_remove_button_clicked();