When we select an element dynamic text, the element properties widget switch to the tab of dynamics text and expand and select the item in the tree that represent the dynamic text.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5024 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-08-22 18:27:23 +00:00
parent fe46dc29a6
commit 53ae49b3c7
11 changed files with 93 additions and 15 deletions

View File

@@ -171,7 +171,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
* @brief DynamicElementTextItem::ParentElement
* @return a pointer to the parent element. Note the pointer can be null.
*/
Element *DynamicElementTextItem::ParentElement() const {
Element *DynamicElementTextItem::parentElement() const {
return m_parent_element;
}

View File

@@ -67,7 +67,7 @@ class DynamicElementTextItem : public DiagramTextItem
QDomElement toXml(QDomDocument &dom_doc) const override;
void fromXml(const QDomElement &dom_elmt) override;
Element *ParentElement() const;
Element *parentElement() const;
DynamicElementTextItem::TextFrom textFrom() const;
void setTextFrom (DynamicElementTextItem::TextFrom text_from);

View File

@@ -34,7 +34,7 @@ QString CompositeTextEditDialog::plainText() const {
void CompositeTextEditDialog::setUpComboBox()
{
QStringList qstrl;
Element *elmt = m_text->ParentElement();
Element *elmt = m_text->parentElement();
if(!elmt)
return;

View File

@@ -128,13 +128,13 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
//We already edit an element, just update the editor with a new element
if (m_edited_qgi_type == Element::Type)
{
static_cast<ElementPropertiesWidget*>(editors().first())->setElement(deti->ParentElement());
static_cast<ElementPropertiesWidget*>(editors().first())->setDynamicText(deti);
return;
}
clear();
m_edited_qgi_type = Element::Type;
addEditor(new ElementPropertiesWidget(deti->ParentElement(), this));
addEditor(new ElementPropertiesWidget(deti, this));
break; }
default:

View File

@@ -105,6 +105,21 @@ void DynamicElementTextItemEditor::apply()
deti->blockSignals(false);
}
/**
* @brief DynamicElementTextItemEditor::setCurrentText
* Expand and select the item for text @text
* @param text
*/
void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text)
{
QModelIndex index = m_model->indexFromText(text);
if(!index.isValid())
return;
m_tree_view->expand(index);
m_tree_view->setCurrentIndex(index);
}
void DynamicElementTextItemEditor::dataEdited(QStandardItem *qsi)
{
Q_UNUSED(qsi)

View File

@@ -41,6 +41,7 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge
QString title() const override {return tr("Textes");}
bool setLiveEdit(bool live_edit) override;
void apply() override;
void setCurrentText(DynamicElementTextItem *text);
private:
void dataEdited(QStandardItem *qsi);

View File

@@ -107,7 +107,7 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti)
QStandardItem *compositea = new QStandardItem(deti->compositeText().isEmpty() ?
tr("Mon texte composé") :
autonum::AssignVariables::replaceVariable(deti->compositeText(), deti->ParentElement()->elementInformations()));
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
@@ -219,6 +219,19 @@ DynamicElementTextItem *DynamicElementTextModel::textFromItem(QStandardItem *ite
return nullptr;
}
/**
* @brief DynamicElementTextModel::indexFromText
* @param text
* @return the QModelIndex for @text, or a default QModelIndex if not match
*/
QModelIndex DynamicElementTextModel::indexFromText(DynamicElementTextItem *text) const
{
if(!m_texts_list.contains(text))
return QModelIndex();
return m_texts_list.value(text)->index();
}
/**
* @brief DynamicElementTextModel::undoForEditedText
* @param deti
@@ -332,15 +345,15 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi)
QString text = qsi->data(Qt::DisplayRole).toString();
m_texts_list.value(deti)->setData(text, Qt::DisplayRole);
}
else if (qsi->data().toInt() == infoText && deti->ParentElement())
else if (qsi->data().toInt() == infoText && deti->parentElement())
{
QString info = qsi->data(Qt::UserRole+2).toString();
m_texts_list.value(deti)->setData(deti->ParentElement()->elementInformations().value(info), Qt::DisplayRole);
m_texts_list.value(deti)->setData(deti->parentElement()->elementInformations().value(info), Qt::DisplayRole);
}
else if (qsi->data().toInt() == compositeText && deti->ParentElement())
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);
m_texts_list.value(deti)->setData(autonum::AssignVariables::replaceVariable(compo, deti->parentElement()->elementInformations()), Qt::DisplayRole);
}
blockSignals(false);
@@ -546,7 +559,7 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
DynamicElementTextItem *deti = detm->textFromIndex(index);
if(deti)
{
DiagramContext dc = deti->ParentElement()->elementInformations();
DiagramContext dc = deti->parentElement()->elementInformations();
assigned_text = autonum::AssignVariables::replaceVariable(edited_text, dc);
}
@@ -569,7 +582,7 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
QStringList DynamicTextItemDelegate::availableInfo(DynamicElementTextItem *deti) const
{
QStringList qstrl;
Element *elmt = deti->ParentElement();
Element *elmt = deti->parentElement();
if(!elmt)
return qstrl;

View File

@@ -52,6 +52,7 @@ class DynamicElementTextModel : public QStandardItemModel
void removeText(DynamicElementTextItem *deti);
DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
DynamicElementTextItem *textFromItem(QStandardItem *item) const;
QModelIndex indexFromText(DynamicElementTextItem *text) const;
QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const;
private:

View File

@@ -25,6 +25,7 @@
#include "diagramposition.h"
#include "qeticons.h"
#include "dynamicelementtextitemeditor.h"
#include "dynamicelementtextitem.h"
#include <QVBoxLayout>
#include <QLabel>
@@ -46,6 +47,27 @@ ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt, QWidget *parent)
setElement(elmt);
}
/**
* @brief ElementPropertiesWidget::ElementPropertiesWidget
* Same as default constructor, the edited element, is the parent element of @text.
* The only difference with default constructor, is that the current tab is the tab for dynamic texts,
* and the item in the tree that represent @text is expanded and selected.
* @param text
* @param parent
*/
ElementPropertiesWidget::ElementPropertiesWidget(DynamicElementTextItem *text, QWidget *parent) :
AbstractElementPropertiesEditorWidget (parent),
m_tab (nullptr),
m_general_widget(nullptr)
{
if(text->parentElement())
{
m_diagram = text->parentElement()->diagram();
buildGui();
setDynamicText(text);
}
}
/**
* @brief ElementPropertiesWidget::setElement
* Set @element to be the edited element
@@ -73,6 +95,29 @@ void ElementPropertiesWidget::setElement(Element *element)
updateUi();
}
/**
* @brief ElementPropertiesWidget::setDynamicText
* convenience function: same as call : ElementPropertiesWidget::setElement, with parameter the parent element of @text.
* Set the dynamics text tab as current tab, expand and select the item that represent @text
* @param text
*/
void ElementPropertiesWidget::setDynamicText(DynamicElementTextItem *text)
{
if(text->parentElement())
{
setElement(text->parentElement());
for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
{
if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
{
DynamicElementTextItemEditor *detie = static_cast<DynamicElementTextItemEditor *>(aepew);
m_tab->setCurrentWidget(detie);
detie->setCurrentText(text);
}
}
}
}
/**
* @brief ElementPropertiesWidget::apply
* Apply the new properties by pushing an undo command

View File

@@ -24,6 +24,7 @@ class Element;
class Diagram;
class QTabWidget;
class ElementsLocation;
class DynamicElementTextItem;
class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget
@@ -32,7 +33,9 @@ class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget
public:
explicit ElementPropertiesWidget(Element *elmt, QWidget *parent = nullptr);
explicit ElementPropertiesWidget(DynamicElementTextItem *text, QWidget *parent = nullptr);
void setElement(Element *element) override;
void setDynamicText(DynamicElementTextItem *text);
void apply() override;
void reset() override;
bool setLiveEdit(bool live_edit) override;

View File

@@ -38,13 +38,13 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D
const QSet<DynamicElementTextItem *> elmt_set = m_removed_contents.m_element_texts;
for(DynamicElementTextItem *deti : elmt_set)
{
if (m_removed_contents.m_elements.contains(deti->ParentElement()))
if (m_removed_contents.m_elements.contains(deti->parentElement()))
m_removed_contents.m_element_texts.remove(deti);
}
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
m_elmt_text_hash.insert(deti, deti->ParentElement());
m_elmt_text_hash.insert(deti, deti->parentElement());
setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
@@ -109,7 +109,7 @@ void DeleteQGraphicsItemCommand::redo()
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
{
deti->ParentElement()->removeDynamicTextItem(deti);
deti->parentElement()->removeDynamicTextItem(deti);
deti->setParentItem(nullptr);
}