2017-08-16 13:52:15 +00:00
|
|
|
#include "compositetexteditdialog.h"
|
2018-07-19 14:14:31 +00:00
|
|
|
|
|
|
|
#include <utility>
|
2017-08-16 13:52:15 +00:00
|
|
|
#include "ui_compositetexteditdialog.h"
|
|
|
|
#include "dynamicelementtextitem.h"
|
|
|
|
#include "element.h"
|
|
|
|
#include "qetapp.h"
|
2017-09-13 16:38:16 +00:00
|
|
|
#include "conductor.h"
|
2017-08-16 13:52:15 +00:00
|
|
|
|
|
|
|
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);
|
2017-08-24 12:38:35 +00:00
|
|
|
#if QT_VERSION >= 0x050300
|
|
|
|
ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible"));
|
|
|
|
#endif
|
2017-08-16 13:52:15 +00:00
|
|
|
setUpComboBox();
|
|
|
|
}
|
|
|
|
|
2018-03-11 16:00:58 +00:00
|
|
|
CompositeTextEditDialog::CompositeTextEditDialog(QString text, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::CompositeTextEditDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-07-19 14:14:31 +00:00
|
|
|
m_default_text = std::move(text);
|
2018-03-11 16:00:58 +00:00
|
|
|
ui->m_plain_text_edit->setPlainText(m_default_text);
|
|
|
|
#if QT_VERSION >= 0x050300
|
|
|
|
ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible"));
|
|
|
|
#endif
|
|
|
|
setUpComboBox();
|
|
|
|
}
|
|
|
|
|
2017-08-16 13:52:15 +00:00
|
|
|
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;
|
2018-03-11 16:00:58 +00:00
|
|
|
|
2018-05-03 09:33:30 +00:00
|
|
|
if(m_text && (m_text->parentElement()->linkType() & Element::AllReport)) //Special treatment for text owned by a folio report
|
2017-09-13 16:38:16 +00:00
|
|
|
{
|
2020-07-05 14:01:38 +02:00
|
|
|
qstrl << "label" << "function" << "tension_protocol" << "conductor_color" << "conductor_section";
|
2017-09-13 16:38:16 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-16 13:52:15 +00:00
|
|
|
{
|
2018-03-11 16:00:58 +00:00
|
|
|
qstrl = QETApp::elementInfoKeys();
|
2018-05-03 09:33:30 +00:00
|
|
|
qstrl.removeAll("formula");
|
2017-08-16 13:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& str : qstrl) {
|
2017-08-16 13:52:15 +00:00
|
|
|
info_map.insert(QETApp::elementTranslatedInfoKey(str), QETApp::elementInfoToVar(str));
|
|
|
|
}
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& key : info_map.keys()) {
|
2017-08-16 13:52:15 +00:00
|
|
|
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());
|
|
|
|
}
|
2017-11-06 16:17:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CompositeTextEditDialog::focusInEvent
|
|
|
|
* Reimplemented from QWidget::focusInEvent
|
|
|
|
* @param event
|
|
|
|
*/
|
|
|
|
void CompositeTextEditDialog::focusInEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
ui->m_plain_text_edit->setFocus();
|
|
|
|
QDialog::focusInEvent(event);
|
|
|
|
}
|