mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Element text pattern dialog : add a check box 'erase existing texts'
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5541 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
aaab9b0f15
commit
63fd76231a
@ -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 @@ QDomDocument ExportElementTextPattern::xmlConf() const
|
||||
//*******************//
|
||||
//******IMPORT*******//
|
||||
//*******************//
|
||||
|
||||
ImportElementTextPattern::ImportElementTextPattern(Element *elmt):
|
||||
m_element(elmt)
|
||||
{
|
||||
@ -146,14 +147,15 @@ ImportElementTextPattern::ImportElementTextPattern(Element *elmt):
|
||||
}
|
||||
|
||||
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 @@ ImportElementTextPattern::ImportElementTextPattern(Element *elmt):
|
||||
* @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 @@ QWidget *ImportElementTextPattern::parentWidget() const
|
||||
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 @@ void ImportElementTextPattern::apply(QString name) const
|
||||
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)
|
||||
{
|
||||
|
@ -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 @@ class ImportElementTextPattern
|
||||
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;
|
||||
|
74
sources/ui/importelementtextpatterndialog.cpp
Normal file
74
sources/ui/importelementtextpatterndialog.cpp
Normal file
@ -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();
|
||||
}
|
52
sources/ui/importelementtextpatterndialog.h
Normal file
52
sources/ui/importelementtextpatterndialog.h
Normal file
@ -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
|
81
sources/ui/importelementtextpatterndialog.ui
Normal file
81
sources/ui/importelementtextpatterndialog.ui
Normal file
@ -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>
|
Loading…
x
Reference in New Issue
Block a user