[qet] [3270] Conductor autonum dialog : add remove autonum button.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 3270
Author:   blacksun
Date:     2014-08-12 11:41:33 +0200 (Tue, 12 Aug 2014)
Log Message:
-----------
Conductor autonum dialog : add remove autonum button.

Modified Paths:
--------------
    trunk/sources/conductorautonumerotation.cpp
    trunk/sources/projectconfigpages.cpp
    trunk/sources/projectconfigpages.h
    trunk/sources/qetproject.cpp
    trunk/sources/qetproject.h

Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp	2014-08-11 16:44:16 UTC (rev 3269)
+++ trunk/sources/conductorautonumerotation.cpp	2014-08-12 09:41:33 UTC (rev 3270)
@@ -133,10 +133,12 @@
 void ConductorAutoNumerotation::numerateNewConductor() {
 	if (!conductor_ || m_diagram->conductorsAutonumName().isEmpty()) return;
 
-	QString name = m_diagram -> conductorsAutonumName();
-	NumerotationContextCommands ncc (m_diagram->project()->conductorAutoNum(name), m_diagram);
+	NumerotationContext context = m_diagram->project()->conductorAutoNum(m_diagram -> conductorsAutonumName());
+	if (context.isEmpty()) return;
+
+	NumerotationContextCommands ncc (context, m_diagram);
 	applyText(ncc.toRepresentedString());
-	m_diagram->project()->addConductorAutoNum(name, ncc.next());
+	m_diagram->project()->addConductorAutoNum(m_diagram -> conductorsAutonumName(), ncc.next());
 }
 
 /**

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2014-08-11 16:44:16 UTC (rev 3269)
+++ trunk/sources/projectconfigpages.cpp	2014-08-12 09:41:33 UTC (rev 3270)
@@ -388,11 +388,14 @@
  */
 void ProjectAutoNumConfigPage::initWidgets() {
 	m_label = new QLabel(tr("Num\351rotations disponibles :", "availables numerotations"), this);
+
 	m_context_cb = new QComboBox(this);
-	m_context_cb->addItem(tr("Nouveau"));
-	m_name_le = new QLineEdit(this);
-	m_name_le->setPlaceholderText(tr("Nom de la nouvelle num\351rotation"));
+	m_context_cb->setEditable(true);
+	m_context_cb->addItem(tr("Nom de la nouvelle num\351rotation"));
 
+	m_remove_pb = new QPushButton(QET::Icons::EditDelete, QString(), this);
+	m_remove_pb -> setToolTip(tr("Supprimer la num\351rotation"));
+
 	m_saw = new SelectAutonumW(this);
 }
 
@@ -404,7 +407,7 @@
 	QHBoxLayout *context_layout = new QHBoxLayout();
 	context_layout -> addWidget (m_label);
 	context_layout -> addWidget (m_context_cb);
-	context_layout -> addWidget (m_name_le);
+	context_layout -> addWidget (m_remove_pb);
 
 	QVBoxLayout *main_layout = new QVBoxLayout(this);
 	this        -> setLayout (main_layout);
@@ -434,8 +437,9 @@
  * setup some connections
  */
 void ProjectAutoNumConfigPage::buildConnections() {
-	connect(m_context_cb, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext(QString)));
-	connect(m_saw,        SIGNAL (applyPressed()),               this, SLOT (saveContext()));
+	connect (m_context_cb, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext(QString)));
+	connect (m_saw,        SIGNAL (applyPressed()),               this, SLOT (saveContext()));
+	connect (m_remove_pb,  SIGNAL(clicked()),                     this, SLOT(removeContext()));
 }
 
 /**
@@ -444,16 +448,8 @@
  * @param str, key of context stored in project
  */
 void ProjectAutoNumConfigPage::updateContext(QString str) {
-	if (str == tr("Nouveau")) {
-		m_saw -> setContext(NumerotationContext());
-		m_name_le -> setText(QString());
-		m_name_le ->setEnabled(true);
-	}
-	else {
-		m_saw ->setContext(project_->conductorAutoNum(str));
-		m_name_le -> setText(str);
-		m_name_le -> setDisabled(true);
-	}
+	if (str == tr("Nom de la nouvelle num\351rotation")) m_saw -> setContext(NumerotationContext());
+	else m_saw ->setContext(project_->conductorAutoNum(str));
 }
 
 /**
@@ -461,14 +457,30 @@
  * Save the current displayed context in project
  */
 void ProjectAutoNumConfigPage::saveContext() {
-	if (m_context_cb->currentText() == tr("Nouveau")) {
-		if (m_name_le->text().isEmpty()) {
-			m_name_le->setText(tr("Nouvel num\351rotation"));
-		}
-		project_->addConductorAutoNum(m_name_le -> text(), m_saw -> toNumContext());
-		m_context_cb -> addItem(m_name_le -> text());
+	// If the text is the default text "Name of new numerotation" save the edited context
+	// With the the name "No name"
+	if (m_context_cb -> currentText() == tr("Nom de la nouvelle num\351rotation")) {
+		project_->addConductorAutoNum (tr("Sans nom"), m_saw -> toNumContext());
+		m_context_cb -> 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_ -> conductorAutoNum().keys().contains( m_context_cb->currentText())) {
+		project()->addConductorAutoNum(m_context_cb->currentText(), m_saw->toNumContext());
+		m_context_cb -> addItem(m_context_cb->currentText());
+	}
+	// Else, the text already exist in the autonum of the project, just update the context
 	else {
 		project_->addConductorAutoNum (m_context_cb -> currentText(), m_saw -> toNumContext());
 	}
 }
+
+/**
+ * @brief ProjectAutoNumConfigPage::removeContext
+ * Remove from project the current numerotation context
+ */
+void ProjectAutoNumConfigPage::removeContext() {
+	//if default text, return
+	if ( m_context_cb -> currentText() == tr("Nom de la nouvelle num\351rotation") ) return;
+	project_     -> removeConductorAutonum (m_context_cb -> currentText() );
+	m_context_cb -> removeItem             (m_context_cb -> currentIndex() );
+}

Modified: trunk/sources/projectconfigpages.h
===================================================================
--- trunk/sources/projectconfigpages.h	2014-08-11 16:44:16 UTC (rev 3269)
+++ trunk/sources/projectconfigpages.h	2014-08-12 09:41:33 UTC (rev 3270)
@@ -31,6 +31,7 @@
 class XRefPropertiesWidget;
 class SelectAutonumW;
 class QComboBox;
+class QPushButton;
 
 /**
 	This class, derived from ConfigPage, aims at providing the basic skeleton
@@ -175,12 +176,13 @@
 	private slots:
 		void updateContext(QString);
 		void saveContext();
+		void removeContext();
 
 	//Attributes
 	private:
 		QLabel         *m_label;
-		QLineEdit      *m_name_le;
 		QComboBox      *m_context_cb;
+		QPushButton	   *m_remove_pb;
 		SelectAutonumW *m_saw;
 
 };

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2014-08-11 16:44:16 UTC (rev 3269)
+++ trunk/sources/qetproject.cpp	2014-08-12 09:41:33 UTC (rev 3270)
@@ -482,6 +482,15 @@
 }
 
 /**
+ * @brief QETProject::removeConductorAutonum
+ * Remove the Numerotation Context stored with key
+ * @param key
+ */
+void QETProject::removeConductorAutonum(QString key) {
+	m_conductor_autonum.remove(key);
+}
+
+/**
  * @brief QETProject::conductorAutoNum
  * Return the numerotation context stored with @key.
  * If key is not found, return an empty numerotation context

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2014-08-11 16:44:16 UTC (rev 3269)
+++ trunk/sources/qetproject.h	2014-08-12 09:41:33 UTC (rev 3270)
@@ -114,6 +114,7 @@
 
 	QHash <QString, NumerotationContext> conductorAutoNum() const;
 	void addConductorAutoNum (QString key, NumerotationContext context);
+	void removeConductorAutonum (QString key);
 	NumerotationContext conductorAutoNum(const QString &key) const;
 
 	QDomDocument toXml();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/