[qet] [1138] The template editor does not enforce anymore the user to write the template name twice .

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


Revision: 1138
Author:   xavier
Date:     2010-12-28 08:05:31 +0100 (Tue, 28 Dec 2010)
Log Message:
-----------
The template editor does not enforce anymore the user to write the template name twice.

Modified Paths:
--------------
    branches/0.3/sources/templateeditor.cpp
    branches/0.3/sources/templateeditor.h

Modified: branches/0.3/sources/templateeditor.cpp
===================================================================
--- branches/0.3/sources/templateeditor.cpp	2010-12-27 15:00:31 UTC (rev 1137)
+++ branches/0.3/sources/templateeditor.cpp	2010-12-28 07:05:31 UTC (rev 1138)
@@ -46,8 +46,12 @@
 		xml_doc.appendChild(xml_doc.importNode(xml_tb_template, true));
 		template_name_edit_ -> setText(template_name);
 		template_name_edit_ -> setReadOnly(true);
-		template_xml_edit_ -> setPlainText(xml_doc.toString(4));
 		
+		QString xml_str = xml_doc.toString(4);
+		xml_str.replace(QRegExp("^<titleblocktemplate[^>]*>"), "");
+		xml_str.replace(QRegExp("</titleblocktemplate>"), "");
+		template_xml_edit_ -> setPlainText("    " + xml_str.trimmed());
+		
 		// stores the parent project and template name, in order to write/save the template later
 		template_name_ = template_name;
 		return(true);
@@ -91,7 +95,7 @@
 	}
 	
 	QDomDocument xml_doc;
-	bool parsing = xml_doc.setContent(template_xml_edit_ -> toPlainText());
+	bool parsing = xml_doc.setContent(getXmlString());
 	if (!parsing) {
 		QMessageBox::critical(
 			this,
@@ -122,6 +126,9 @@
 void TemplateEditor::build() {
 	parent_project_label_ = new QLabel();
 	updateProjectLabel();
+	static_xml_1_ = new QLabel("<titleblocktemplate name=\"");
+	static_xml_2_ = new QLabel("\">");
+	static_xml_3_ = new QLabel("</titleblocktemplate>");
 	template_name_edit_ = new QLineEdit();
 	template_xml_edit_ = new QTextEdit();
 	template_xml_edit_ -> setAcceptRichText(false);
@@ -141,10 +148,16 @@
 	h_layout0 -> addWidget(save_button_);
 	h_layout0 -> addWidget(quit_button_);
 	
+	QHBoxLayout *h_layout1 = new QHBoxLayout();
+	h_layout1 -> addWidget(static_xml_1_);
+	h_layout1 -> addWidget(template_name_edit_);
+	h_layout1 -> addWidget(static_xml_2_);
+	
 	QVBoxLayout *v_layout0 = new QVBoxLayout();
 	v_layout0 -> addWidget(parent_project_label_);
-	v_layout0 -> addWidget(template_name_edit_);
+	v_layout0 -> addLayout(h_layout1);
 	v_layout0 -> addWidget(template_xml_edit_);
+	v_layout0 -> addWidget(static_xml_3_);
 	v_layout0 -> addLayout(h_layout0);
 	
 	setLayout(v_layout0);
@@ -168,3 +181,12 @@
 		QString(tr("Projet parent : %1")).arg(parent_project_title)
 	);
 }
+
+/**
+	@return the XML description provided by the user, as a string.
+*/
+QString TemplateEditor::getXmlString() const {
+	QString xml_str = QString("<titleblocktemplate name=\"%1\">%2</titleblocktemplate>");
+	xml_str = xml_str.arg(Qt::escape(template_name_edit_ -> text())).arg(template_xml_edit_ -> toPlainText());
+	return(xml_str);
+}

Modified: branches/0.3/sources/templateeditor.h
===================================================================
--- branches/0.3/sources/templateeditor.h	2010-12-27 15:00:31 UTC (rev 1137)
+++ branches/0.3/sources/templateeditor.h	2010-12-28 07:05:31 UTC (rev 1138)
@@ -45,10 +45,14 @@
 	private:
 	void build();
 	void updateProjectLabel();
+	QString getXmlString() const;
 	
 	// attributes
 	private:
 	QLabel *parent_project_label_;
+	QLabel *static_xml_1_;
+	QLabel *static_xml_2_;
+	QLabel *static_xml_3_;
 	QLineEdit *template_name_edit_;
 	QTextEdit *template_xml_edit_;
 	QPushButton *validate_button_;


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