mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
The template editor does not enforce anymore the user to write the template name twice.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1138 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -46,7 +46,11 @@ bool TemplateEditor::edit(QETProject *project, const QString &template_name) {
|
|||||||
xml_doc.appendChild(xml_doc.importNode(xml_tb_template, true));
|
xml_doc.appendChild(xml_doc.importNode(xml_tb_template, true));
|
||||||
template_name_edit_ -> setText(template_name);
|
template_name_edit_ -> setText(template_name);
|
||||||
template_name_edit_ -> setReadOnly(true);
|
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
|
// stores the parent project and template name, in order to write/save the template later
|
||||||
template_name_ = template_name;
|
template_name_ = template_name;
|
||||||
@@ -91,7 +95,7 @@ void TemplateEditor::save() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDomDocument xml_doc;
|
QDomDocument xml_doc;
|
||||||
bool parsing = xml_doc.setContent(template_xml_edit_ -> toPlainText());
|
bool parsing = xml_doc.setContent(getXmlString());
|
||||||
if (!parsing) {
|
if (!parsing) {
|
||||||
QMessageBox::critical(
|
QMessageBox::critical(
|
||||||
this,
|
this,
|
||||||
@@ -122,6 +126,9 @@ void TemplateEditor::quit() {
|
|||||||
void TemplateEditor::build() {
|
void TemplateEditor::build() {
|
||||||
parent_project_label_ = new QLabel();
|
parent_project_label_ = new QLabel();
|
||||||
updateProjectLabel();
|
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_name_edit_ = new QLineEdit();
|
||||||
template_xml_edit_ = new QTextEdit();
|
template_xml_edit_ = new QTextEdit();
|
||||||
template_xml_edit_ -> setAcceptRichText(false);
|
template_xml_edit_ -> setAcceptRichText(false);
|
||||||
@@ -141,10 +148,16 @@ void TemplateEditor::build() {
|
|||||||
h_layout0 -> addWidget(save_button_);
|
h_layout0 -> addWidget(save_button_);
|
||||||
h_layout0 -> addWidget(quit_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();
|
QVBoxLayout *v_layout0 = new QVBoxLayout();
|
||||||
v_layout0 -> addWidget(parent_project_label_);
|
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(template_xml_edit_);
|
||||||
|
v_layout0 -> addWidget(static_xml_3_);
|
||||||
v_layout0 -> addLayout(h_layout0);
|
v_layout0 -> addLayout(h_layout0);
|
||||||
|
|
||||||
setLayout(v_layout0);
|
setLayout(v_layout0);
|
||||||
@@ -168,3 +181,12 @@ void TemplateEditor::updateProjectLabel() {
|
|||||||
QString(tr("Projet parent : %1")).arg(parent_project_title)
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,10 +45,14 @@ class TemplateEditor : public QWidget {
|
|||||||
private:
|
private:
|
||||||
void build();
|
void build();
|
||||||
void updateProjectLabel();
|
void updateProjectLabel();
|
||||||
|
QString getXmlString() const;
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
QLabel *parent_project_label_;
|
QLabel *parent_project_label_;
|
||||||
|
QLabel *static_xml_1_;
|
||||||
|
QLabel *static_xml_2_;
|
||||||
|
QLabel *static_xml_3_;
|
||||||
QLineEdit *template_name_edit_;
|
QLineEdit *template_name_edit_;
|
||||||
QTextEdit *template_xml_edit_;
|
QTextEdit *template_xml_edit_;
|
||||||
QPushButton *validate_button_;
|
QPushButton *validate_button_;
|
||||||
|
|||||||
Reference in New Issue
Block a user