30 #include <QInputDialog> 31 #include <QGraphicsScene> 32 #include <QMessageBox> 34 #include <QGraphicsView> 35 #include <QStringList> 50 dir.mkdir(
"element_texts_pattern");
51 dir.cd(
"element_texts_pattern");
61 if (QFileInfo::exists(dir.absoluteFilePath(
m_name +
".xml")))
65 QObject::tr(
"Une configuration de textes nommée << %1 >> existe déjà.\n" 66 "Voulez-vous la remplacer ?").arg(
m_name));
85 QObject::tr(
"Entrer le nom de la configuration à créer"),
90 text.replace(
" ",
"_");
97 QWidget *parent =
nullptr;
99 parent =
m_element->scene()->views().first();
107 QDomElement root = doc.createElement(
"Element_texts_pattern");
108 root.setAttribute(
"name",
m_name);
109 doc.appendChild(root);
111 QHash<Terminal *, int> H;
113 QDomElement texts = elmt.firstChildElement(
"dynamic_texts");
114 QDomElement groups = elmt.firstChildElement(
"texts_groups");
116 if(texts.tagName() ==
"dynamic_texts")
117 root.appendChild(texts);
118 if(groups.tagName() ==
"texts_groups")
119 root.appendChild(groups);
136 QStringList entry = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
137 QStringList result = entry.filter(
".xml");
145 QObject::tr(
"Aucune configuration de textes existante."));
152 result.replaceInStrings(
".xml",
"");
153 QString name =
getName(result, &ok, &erase);
155 if(!ok || name.isEmpty())
170 QObject::tr(
"Sélectionner une configuration de textes"),
171 QObject::tr(
"Sélectionner la configuration de textes à ajouter à l'élément"),
179 QWidget *parent =
nullptr;
181 parent =
m_element->scene()->views().first();
195 if(!name.endsWith(
".xml"))
199 if(!conf_file.open(QIODevice::ReadOnly | QIODevice::Text))
203 QDomDocument xml_conf;
204 if(!xml_conf.setContent(&conf_file))
207 QDomElement root = xml_conf.firstChildElement(
"Element_texts_pattern");
215 QHash<QUuid, QUuid> uuid_hash;
216 for(QDomElement text : texts)
218 QUuid original_uuid(text.attribute(
"uuid"));
219 QUuid new_uuid = QUuid::createUuid();
220 text.setAttribute(
"uuid", new_uuid.toString());
222 uuid_hash.insert(original_uuid, new_uuid);
227 for(
const QDomElement& group : groups)
231 QUuid original_uuid(text.attribute(
"uuid"));
232 QUuid new_uuid = uuid_hash.value(original_uuid);
233 if(!new_uuid.isNull())
234 text.setAttribute(
"uuid", new_uuid.toString());
239 undo_stack.beginMacro(
QObject::tr(
"Importer la configuration de texte : %1").arg(name.remove(
".xml")));
256 for(
const QDomElement& text : texts)
263 for(
const QDomElement& xml_group : groups)
266 undo_stack.endMacro();
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
QDomDocument xmlConf() const
QString getName(const QStringList &list, bool *ok, bool *erase) const
ImportElementTextPattern::getName Open a dialog to let user select a conf.
virtual QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
ExportElementTextPattern(Element *elmt)
ExportElementTextPattern::ExportElementTextPattern Constructor.
static QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, bool *ok=nullptr, bool *erase=nullptr)
ImportElementTextPatternDialog::getItem For all arguments see QInputDialog::getItem, except for erase, they store the state of the check box.
void apply(QString name, bool erase=false) const
ImportElementTextPattern::apply Apply the user choice.
QSet< DynamicElementTextItem * > m_element_texts
QWidget * parentWidget() const
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *error_message=nullptr)
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
The RemoveTextsGroupCommand class Manage the removinf of a texts group.
QMessageBox::StandardButton question(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
QString getName(bool &ok) const
ExportElementTextConf::getName Open a dialog to let user set the name of the conf and return it...
void fromXml(const QDomElement &dom_elmt) override
DynamicElementTextItem::fromXml Import this text from xml.
QMessageBox::StandardButton information(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
The AddTextsGroupCommand class Manage the adding of a texts group.
QWidget * parentWidget() const
The AddElementTextCommand class Manage the adding of element text.
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
ImportElementTextPattern(Element *elmt)
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
static QString configDir()