mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-12 20:09:58 +01:00
Dynamic element text item, can have for source of text a composite text, a text composed both by user typed text and element info.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5021 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#define ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H
|
||||
|
||||
#include "PropertiesEditor/propertieseditorwidget.h"
|
||||
#include "QPointer"
|
||||
#include <QPointer>
|
||||
|
||||
class Element;
|
||||
|
||||
|
||||
66
sources/ui/compositetexteditdialog.cpp
Normal file
66
sources/ui/compositetexteditdialog.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "compositetexteditdialog.h"
|
||||
#include "ui_compositetexteditdialog.h"
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "element.h"
|
||||
#include "qetapp.h"
|
||||
|
||||
CompositeTextEditDialog::CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CompositeTextEditDialog),
|
||||
m_text(text)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_default_text = m_text->compositeText();
|
||||
ui->m_plain_text_edit->setPlainText(m_default_text);
|
||||
setUpComboBox();
|
||||
}
|
||||
|
||||
CompositeTextEditDialog::~CompositeTextEditDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CompositeTextEditDialog::plainText
|
||||
* @return The edited text
|
||||
*/
|
||||
QString CompositeTextEditDialog::plainText() const {
|
||||
return ui->m_plain_text_edit->toPlainText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CompositeTextEditDialog::setUpComboBox
|
||||
* Add the available element information in the combo box
|
||||
*/
|
||||
void CompositeTextEditDialog::setUpComboBox()
|
||||
{
|
||||
QStringList qstrl;
|
||||
Element *elmt = m_text->ParentElement();
|
||||
if(!elmt)
|
||||
return;
|
||||
|
||||
QStringList info_list = QETApp::elementInfoKeys();
|
||||
info_list.removeAll("formula"); //No need to have formula
|
||||
DiagramContext dc = elmt->elementInformations();
|
||||
|
||||
for(QString info : info_list)
|
||||
{
|
||||
if(dc.contains(info))
|
||||
qstrl << info;
|
||||
}
|
||||
|
||||
//We use a QMap because the keys of the map are sorted, then no matter the curent local,
|
||||
//the value of the combo box are always alphabetically sorted
|
||||
QMap <QString, QString> info_map;
|
||||
for(QString str : qstrl) {
|
||||
info_map.insert(QETApp::elementTranslatedInfoKey(str), QETApp::elementInfoToVar(str));
|
||||
}
|
||||
for(QString key : info_map.keys()) {
|
||||
ui->m_info_cb->addItem(key, info_map.value(key));
|
||||
}
|
||||
}
|
||||
|
||||
void CompositeTextEditDialog::on_m_info_cb_activated(const QString &arg1)
|
||||
{
|
||||
Q_UNUSED(arg1)
|
||||
ui->m_plain_text_edit->insertPlainText(ui->m_info_cb->currentData().toString());
|
||||
}
|
||||
42
sources/ui/compositetexteditdialog.h
Normal file
42
sources/ui/compositetexteditdialog.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef COMPOSITETEXTEDITDIALOG_H
|
||||
#define COMPOSITETEXTEDITDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class CompositeTextEditDialog;
|
||||
}
|
||||
|
||||
class DynamicElementTextItem;
|
||||
|
||||
/**
|
||||
* @brief The CompositeTextEditDialog class
|
||||
* CompositeTextEditDialog display a dialog use to write the complex text
|
||||
* of a dynamic element text item.
|
||||
* This dialog provide a QComboBox to quickly add an information of the element
|
||||
* in the composite text.
|
||||
*/
|
||||
class CompositeTextEditDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent = nullptr);
|
||||
~CompositeTextEditDialog() override;
|
||||
|
||||
QString plainText() const;
|
||||
|
||||
private slots:
|
||||
void on_m_info_cb_activated(const QString &arg1);
|
||||
|
||||
private :
|
||||
void setUpComboBox();
|
||||
QString infoToVar(const QString& info) const;
|
||||
|
||||
private:
|
||||
Ui::CompositeTextEditDialog *ui;
|
||||
QString m_default_text;
|
||||
DynamicElementTextItem *m_text = nullptr;
|
||||
};
|
||||
|
||||
#endif // COMPOSITETEXTEDITDIALOG_H
|
||||
81
sources/ui/compositetexteditdialog.ui
Normal file
81
sources/ui/compositetexteditdialog.ui
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CompositeTextEditDialog</class>
|
||||
<widget class="QDialog" name="CompositeTextEditDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>664</width>
|
||||
<height>538</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="m_info_cb"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Ajouter une variable :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="m_button_box">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="m_plain_text_edit">
|
||||
<property name="placeholderText">
|
||||
<string>Entrée votre votre texte composé ici, en vous aidant des variables disponible</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_button_box</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CompositeTextEditDialog</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>m_button_box</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CompositeTextEditDialog</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>
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "qetapp.h"
|
||||
#include "element.h"
|
||||
#include "compositetexteditdialog.h"
|
||||
|
||||
DynamicElementTextModel::DynamicElementTextModel(QObject *parent) :
|
||||
QStandardItemModel(parent)
|
||||
@@ -64,7 +65,11 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti)
|
||||
QStandardItem *src = new QStandardItem(tr("Source du texte"));
|
||||
src->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
QStandardItem *srca = new QStandardItem(deti->textFrom() == DynamicElementTextItem::UserText ? tr("Texte utilisateur") : tr("Information de l'élément"));
|
||||
QString title;
|
||||
if (deti->textFrom() == DynamicElementTextItem::UserText) title = tr("Texte utilisateur");
|
||||
else if (deti->textFrom() == DynamicElementTextItem::ElementInfo) title = tr("Information de l'élément");
|
||||
else title = tr("Texte composé");
|
||||
QStandardItem *srca = new QStandardItem(title);
|
||||
srca->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
||||
srca->setData(textFrom, Qt::UserRole+1);
|
||||
|
||||
@@ -95,6 +100,21 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti)
|
||||
qsi_list.clear();
|
||||
qsi_list << info << infoa;
|
||||
src->appendRow(qsi_list);
|
||||
|
||||
//Composite text
|
||||
QStandardItem *composite = new QStandardItem(tr("Texte composé"));
|
||||
composite->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
QStandardItem *compositea = new QStandardItem(deti->compositeText().isEmpty() ?
|
||||
tr("Mon texte composé") :
|
||||
autonum::AssignVariables::replaceVariable(deti->compositeText(), deti->ParentElement()->elementInformations()));
|
||||
compositea->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
||||
compositea->setData(DynamicElementTextModel::compositeText, Qt::UserRole+1); //Use to know the edited thing
|
||||
compositea->setData(deti->compositeText(), Qt::UserRole+2); //Use to know to element composite formula
|
||||
|
||||
qsi_list.clear();
|
||||
qsi_list << composite << compositea;
|
||||
src->appendRow(qsi_list);
|
||||
|
||||
|
||||
//Size
|
||||
@@ -220,6 +240,8 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
||||
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::UserText), undo);
|
||||
else if ((from == tr("Information de l'élément")) && (deti->textFrom() != DynamicElementTextItem::ElementInfo))
|
||||
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::ElementInfo), undo);
|
||||
else if ((from == tr("Texte composé")) && (deti->textFrom() != DynamicElementTextItem::CompositeText))
|
||||
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::CompositeText), undo);
|
||||
|
||||
if(from == tr("Texte utilisateur"))
|
||||
{
|
||||
@@ -233,6 +255,12 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
||||
if(info_name != deti->infoName())
|
||||
new QPropertyUndoCommand(deti, "infoName", QVariant(deti->infoName()), QVariant(info_name), undo);
|
||||
}
|
||||
else if (from == tr("Texte composé"))
|
||||
{
|
||||
QString composite_text = text_qsi->child(0,0)->child(2,1)->data(Qt::UserRole+2).toString();
|
||||
if(composite_text != deti->compositeText())
|
||||
new QPropertyUndoCommand(deti, "compositeText", QVariant(deti->compositeText()), QVariant(composite_text), undo);
|
||||
}
|
||||
|
||||
int fs = text_qsi->child(1,1)->data(Qt::EditRole).toInt();
|
||||
if (fs != deti->fontSize())
|
||||
@@ -262,9 +290,13 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn
|
||||
|
||||
QStandardItem *qsi = m_texts_list.value(deti)->child(0,0);
|
||||
|
||||
bool usr = true, info = false;
|
||||
if(tf == DynamicElementTextItem::ElementInfo) {
|
||||
usr = false; info = true;}
|
||||
bool usr = false, info = false, compo = false;
|
||||
|
||||
switch (tf) {
|
||||
case DynamicElementTextItem::UserText: usr = true; break;
|
||||
case DynamicElementTextItem::ElementInfo: info = true; break;
|
||||
case DynamicElementTextItem::CompositeText: compo = true; break;
|
||||
}
|
||||
|
||||
//User text
|
||||
qsi->child(0,0)->setEnabled(usr);
|
||||
@@ -272,6 +304,9 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn
|
||||
//Info text
|
||||
qsi->child(1,0)->setEnabled(info);
|
||||
qsi->child(1,1)->setEnabled(info);
|
||||
//Composite text
|
||||
qsi->child(2,0)->setEnabled(compo);
|
||||
qsi->child(2,1)->setEnabled(compo);
|
||||
}
|
||||
|
||||
void DynamicElementTextModel::dataEdited(QStandardItem *qsi)
|
||||
@@ -280,13 +315,17 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi)
|
||||
if (!deti)
|
||||
return;
|
||||
|
||||
blockSignals(true);
|
||||
|
||||
if (qsi->data().toInt() == textFrom)
|
||||
{
|
||||
QString from = qsi->data(Qt::DisplayRole).toString();
|
||||
if (from == tr("Texte utilisateur"))
|
||||
enableSourceText(deti, DynamicElementTextItem::UserText);
|
||||
else
|
||||
else if (from == tr("Information de l'élément"))
|
||||
enableSourceText(deti, DynamicElementTextItem::ElementInfo);
|
||||
else
|
||||
enableSourceText(deti, DynamicElementTextItem::CompositeText);
|
||||
}
|
||||
else if (qsi->data().toInt() == userText)
|
||||
{
|
||||
@@ -298,6 +337,13 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi)
|
||||
QString info = qsi->data(Qt::UserRole+2).toString();
|
||||
m_texts_list.value(deti)->setData(deti->ParentElement()->elementInformations().value(info), Qt::DisplayRole);
|
||||
}
|
||||
else if (qsi->data().toInt() == compositeText && deti->ParentElement())
|
||||
{
|
||||
QString compo = qsi->data(Qt::UserRole+2).toString();
|
||||
m_texts_list.value(deti)->setData(autonum::AssignVariables::replaceVariable(compo, deti->ParentElement()->elementInformations()), Qt::DisplayRole);
|
||||
}
|
||||
|
||||
blockSignals(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +365,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
|
||||
connection_list << connect(deti, &DynamicElementTextItem::fontSizeChanged, [deti,this](){this->updateDataFromText(deti, size);});
|
||||
connection_list << connect(deti, &DynamicElementTextItem::taggChanged, [deti,this](){this->updateDataFromText(deti, tagg);});
|
||||
connection_list << connect(deti, &DynamicElementTextItem::textChanged, [deti,this](){this->updateDataFromText(deti, userText);});
|
||||
connection_list << connect(deti, &DynamicElementTextItem::TextFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
|
||||
connection_list << connect(deti, &DynamicElementTextItem::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
|
||||
|
||||
m_hash_text_connect.insert(deti, connection_list);
|
||||
}
|
||||
@@ -344,8 +390,14 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
|
||||
switch (type)
|
||||
{
|
||||
case textFrom:
|
||||
qsi->child(0,1)->setData(deti->textFrom() == DynamicElementTextItem::UserText ? tr("Texte utilisateur") : tr("Information de l'élément"), Qt::DisplayRole);
|
||||
{
|
||||
switch (deti->textFrom()) {
|
||||
case DynamicElementTextItem::UserText: qsi->child(0,1)->setData(tr("Texte utilisateur"), Qt::DisplayRole); break;
|
||||
case DynamicElementTextItem::ElementInfo : qsi->child(0,1)->setData(tr("Information de l'élément"), Qt::DisplayRole); break;
|
||||
case DynamicElementTextItem::CompositeText : qsi->child(0,1)->setData(tr("Texte composé"), Qt::DisplayRole); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case userText:
|
||||
{
|
||||
QStandardItem *qsia = qsi->child(0,0);
|
||||
@@ -355,6 +407,8 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
|
||||
}
|
||||
case infoText:
|
||||
break;
|
||||
case compositeText:
|
||||
break;
|
||||
case size:
|
||||
qsi->child(1,1)->setData(deti->fontSize(), Qt::EditRole);
|
||||
break;
|
||||
@@ -389,6 +443,7 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti
|
||||
QComboBox *qcb = new QComboBox(parent);
|
||||
qcb->addItem(tr("Texte utilisateur"));
|
||||
qcb->addItem(tr("Information de l'élément"));
|
||||
qcb->addItem(tr("Texte composé"));
|
||||
return qcb;
|
||||
}
|
||||
case DynamicElementTextModel::infoText:
|
||||
@@ -417,6 +472,22 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti
|
||||
}
|
||||
return qcb;
|
||||
}
|
||||
case DynamicElementTextModel::compositeText:
|
||||
{
|
||||
const DynamicElementTextModel *detm = static_cast<const DynamicElementTextModel *>(index.model());
|
||||
QStandardItem *qsi = detm->itemFromIndex(index);
|
||||
|
||||
if(!qsi)
|
||||
break;
|
||||
|
||||
DynamicElementTextItem *deti = detm->textFromIndex(index);
|
||||
if(!deti)
|
||||
break;
|
||||
|
||||
CompositeTextEditDialog *cted = new CompositeTextEditDialog(deti);
|
||||
cted->setObjectName("composite_text");
|
||||
return cted;
|
||||
}
|
||||
case DynamicElementTextModel::color:
|
||||
{
|
||||
QColorDialog *cd = new QColorDialog(index.data(Qt::EditRole).value<QColor>());
|
||||
@@ -459,6 +530,32 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
|
||||
|
||||
}
|
||||
}
|
||||
else if (editor->objectName() == "composite_text")
|
||||
{
|
||||
if (QStandardItemModel *qsim = dynamic_cast<QStandardItemModel *>(model))
|
||||
{
|
||||
if(QStandardItem *qsi = qsim->itemFromIndex(index))
|
||||
{
|
||||
|
||||
CompositeTextEditDialog *cted = static_cast<CompositeTextEditDialog *>(editor);
|
||||
|
||||
QString edited_text = cted->plainText();
|
||||
QString assigned_text;
|
||||
|
||||
const DynamicElementTextModel *detm = static_cast<const DynamicElementTextModel *>(index.model());
|
||||
DynamicElementTextItem *deti = detm->textFromIndex(index);
|
||||
if(deti)
|
||||
{
|
||||
DiagramContext dc = deti->ParentElement()->elementInformations();
|
||||
assigned_text = autonum::AssignVariables::replaceVariable(edited_text, dc);
|
||||
}
|
||||
|
||||
qsi->setData(assigned_text, Qt::DisplayRole);
|
||||
qsi->setData(edited_text, Qt::UserRole+2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
|
||||
@@ -39,6 +39,7 @@ class DynamicElementTextModel : public QStandardItemModel
|
||||
textFrom =1,
|
||||
userText,
|
||||
infoText,
|
||||
compositeText,
|
||||
size,
|
||||
tagg,
|
||||
color
|
||||
|
||||
Reference in New Issue
Block a user