[qet] qet/qet: [5541] Element text pattern dialog : add a check box ' erase existing texts'

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


Revision: 5541
Author:   blacksun
Date:     2018-09-30 19:19:50 +0200 (Sun, 30 Sep 2018)
Log Message:
-----------
Element text pattern dialog : add a check box 'erase existing texts'

Modified Paths:
--------------
    trunk/sources/elementtextpattern.cpp
    trunk/sources/elementtextpattern.h

Added Paths:
-----------
    trunk/sources/ui/importelementtextpatterndialog.cpp
    trunk/sources/ui/importelementtextpatterndialog.h
    trunk/sources/ui/importelementtextpatterndialog.ui

Modified: trunk/sources/elementtextpattern.cpp
===================================================================
--- trunk/sources/elementtextpattern.cpp	2018-09-29 16:01:48 UTC (rev 5540)
+++ trunk/sources/elementtextpattern.cpp	2018-09-30 17:19:50 UTC (rev 5541)
@@ -1,5 +1,5 @@
 /*
-	Copyright 2006-2017 The QElectroTech Team
+	Copyright 2006-2018 The QElectroTech Team
 	This file is part of QElectroTech.
 
 	QElectroTech is free software: you can redistribute it and/or modify
@@ -23,6 +23,8 @@
 #include "elementtextitemgroup.h"
 #include "addelementtextcommand.h"
 #include "diagram.h"
+#include "importelementtextpatterndialog.h"
+#include "deleteqgraphicsitemcommand.h"
 
 #include <QDir>
 #include <QInputDialog>
@@ -122,7 +124,6 @@
 //*******************//
 //******IMPORT*******//
 //*******************//
-
 ImportElementTextPattern::ImportElementTextPattern(Element *elmt):
 	m_element(elmt)
 {
@@ -146,14 +147,15 @@
 	}
 	
 	bool ok=false;
+	bool erase = false;
 		//Remove the .xml extention of the files
 	result.replaceInStrings(".xml", "");
-	QString name = getName(result, ok);
+	QString name = getName(result, &ok, &erase);
 	
 	if(!ok || name.isEmpty())
 		return;
 	else
-		apply(name);
+		apply(name, erase);
 }
 
 /**
@@ -162,15 +164,14 @@
  * @param ok
  * @return 
  */
-QString ImportElementTextPattern::getName(const QStringList& list, bool &ok) const
+QString ImportElementTextPattern::getName(const QStringList& list, bool *ok, bool *erase) const
 {
-	return QInputDialog::getItem(parentWidget(),
-								 QObject::tr("Séléctionner une configuration de textes"),
-								 QObject::tr("Séléctionner la configuration de textes à ajouter à l'élément"),
-								 list,
-								 0,
-								 false,
-								 &ok);
+	return ImportElementTextPatternDialog::getItem(parentWidget(),
+												   QObject::tr("Séléctionner une configuration de textes"),
+												   QObject::tr("Séléctionner la configuration de textes à ajouter à l'élément"),
+												   list,
+												   ok,
+												   erase);
 }
 
 QWidget *ImportElementTextPattern::parentWidget() const
@@ -182,12 +183,14 @@
 	return parent;
 }
 
+
 /**
  * @brief ImportElementTextPattern::apply
  * Apply the user choice
  * @param name : the name of the selected pattern
+ * @param erase : erase the existing texts and groups of element.
  */
-void ImportElementTextPattern::apply(QString name) const
+void ImportElementTextPattern::apply(QString name, bool erase) const
 {
 	if(!name.endsWith(".xml"))
 		name.append(".xml");
@@ -235,6 +238,20 @@
 	QUndoStack &undo_stack = m_element->diagram()->undoStack();
 	undo_stack.beginMacro(QObject::tr("Importer la configuration de texte : %1").arg(name.remove(".xml")));
 	
+		//erase existing texts and groups
+	if (erase)
+	{
+		for (ElementTextItemGroup *group : m_element->textGroups()) {
+			undo_stack.push(new RemoveTextsGroupCommand(m_element, group));
+		}
+		for (DynamicElementTextItem *deti : m_element->dynamicTextItems())
+		{
+			DiagramContent dc;
+			dc.m_element_texts << deti;
+			undo_stack.push(new DeleteQGraphicsItemCommand(m_element->diagram(), dc));
+		}
+	}
+	
 		//Add the texts to element
 	for(const QDomElement& text : texts)
 	{

Modified: trunk/sources/elementtextpattern.h
===================================================================
--- trunk/sources/elementtextpattern.h	2018-09-29 16:01:48 UTC (rev 5540)
+++ trunk/sources/elementtextpattern.h	2018-09-30 17:19:50 UTC (rev 5541)
@@ -1,5 +1,5 @@
 /*
-	Copyright 2006-2017 The QElectroTech Team
+	Copyright 2006-2018 The QElectroTech Team
 	This file is part of QElectroTech.
 
 	QElectroTech is free software: you can redistribute it and/or modify
@@ -45,9 +45,9 @@
 		ImportElementTextPattern(Element *elmt);
 		
 	private:
-		QString getName(const QStringList& list, bool &ok) const;
+		QString getName(const QStringList& list, bool *ok, bool *erase) const;
 		QWidget *parentWidget() const;
-		void apply(QString name) const;
+		void apply(QString name, bool erase = false) const;
 		
 	private:
 		Element *m_element = nullptr;

Added: trunk/sources/ui/importelementtextpatterndialog.cpp
===================================================================
--- trunk/sources/ui/importelementtextpatterndialog.cpp	                        (rev 0)
+++ trunk/sources/ui/importelementtextpatterndialog.cpp	2018-09-30 17:19:50 UTC (rev 5541)
@@ -0,0 +1,74 @@
+/*
+	Copyright 2006-2018 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 "importelementtextpatterndialog.h"
+#include "ui_importelementtextpatterndialog.h"
+
+ImportElementTextPatternDialog::ImportElementTextPatternDialog(QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::ImportElementTextPatternDialog) {
+	ui->setupUi(this);
+}
+
+ImportElementTextPatternDialog::~ImportElementTextPatternDialog()
+{
+	delete ui;
+}
+
+/**
+ * @brief ImportElementTextPatternDialog::getItem
+ * For all arguments see QInputDialog::getItem, except for erase, they store the state of the check box.
+ * @param parent
+ * @param title
+ * @param label
+ * @param items
+ * @param ok
+ * @param erase
+ * @return 
+ */
+QString ImportElementTextPatternDialog::getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, bool *ok, bool *erase)
+{
+	QString text(items.value(0));
+   
+   QScopedPointer<ImportElementTextPatternDialog> dialog(new ImportElementTextPatternDialog(parent));
+   dialog->setWindowTitle(title);
+   dialog->setLabelText(label);
+   dialog->setComboBoxItems(items);
+   dialog->setInputMethodHints(Qt::ImhNone);
+   const int ret = dialog->exec();
+   if (ok)
+	   *ok = !!ret;
+   if(erase)
+	   *erase = dialog->ui->m_erase_existing_text->isChecked();
+   if (ret) {
+	   return dialog->textValue();
+   } else {
+	   return text;
+   }
+}
+
+void ImportElementTextPatternDialog::setLabelText(const QString &label) {
+	ui->m_label->setText(label);
+}
+
+void ImportElementTextPatternDialog::setComboBoxItems(const QStringList &items) {
+	ui->m_combo_box->addItems(items);
+}
+
+QString ImportElementTextPatternDialog::textValue() const {
+	return ui->m_combo_box->currentText();
+}

Added: trunk/sources/ui/importelementtextpatterndialog.h
===================================================================
--- trunk/sources/ui/importelementtextpatterndialog.h	                        (rev 0)
+++ trunk/sources/ui/importelementtextpatterndialog.h	2018-09-30 17:19:50 UTC (rev 5541)
@@ -0,0 +1,52 @@
+/*
+	Copyright 2006-2018 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 IMPORTELEMENTTEXTPATTERNDIALOG_H
+#define IMPORTELEMENTTEXTPATTERNDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+	class ImportElementTextPatternDialog;
+}
+
+/**
+ * @brief The ImportElementTextPatternDialog class
+ * A dialog use for ask user to select a element text pattern.
+ * This dialog is highly inspired from QInputDialog::getItem.
+ * In fact this the same + a check box.
+ */
+class ImportElementTextPatternDialog : public QDialog
+{
+	Q_OBJECT
+	
+	public:
+		explicit ImportElementTextPatternDialog (QWidget *parent = nullptr);
+		~ImportElementTextPatternDialog();
+	
+		static QString getItem (QWidget *parent, const QString &title, const QString &label,
+								const QStringList &items, bool *ok = nullptr, bool *erase = nullptr);
+		
+		void setLabelText (const QString &label);
+		void setComboBoxItems (const QStringList &items);
+		QString textValue() const;
+	
+	private:
+		Ui::ImportElementTextPatternDialog *ui;
+};
+
+#endif // IMPORTELEMENTTEXTPATTERNDIALOG_H

Added: trunk/sources/ui/importelementtextpatterndialog.ui
===================================================================
--- trunk/sources/ui/importelementtextpatterndialog.ui	                        (rev 0)
+++ trunk/sources/ui/importelementtextpatterndialog.ui	2018-09-30 17:19:50 UTC (rev 5541)
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ImportElementTextPatternDialog</class>
+ <widget class="QDialog" name="ImportElementTextPatternDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>187</width>
+    <height>116</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="m_label">
+     <property name="text">
+      <string>TextLabel</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QComboBox" name="m_combo_box"/>
+   </item>
+   <item>
+    <widget class="QCheckBox" name="m_erase_existing_text">
+     <property name="text">
+      <string>Écraser les textes existants</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ImportElementTextPatternDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ImportElementTextPatternDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>


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