QElectroTech  0.8-dev
dynamicelementtextmodel.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DYNAMICELEMENTTEXTMODEL_H
19 #define DYNAMICELEMENTTEXTMODEL_H
20 
21 #include <QStandardItemModel>
22 #include <qstyleditemdelegate.h>
23 #include "dynamicelementtextitem.h"
24 
25 class QUndoCommand;
27 class Element;
28 
35 class DynamicElementTextModel : public QStandardItemModel
36 {
37  Q_OBJECT
38 
39  public:
40  enum ValueType {
49  pos,
59  grpFrame
60  };
61 
62  DynamicElementTextModel(Element *element, QObject *parent = nullptr);
63  ~DynamicElementTextModel() override;
64 
65  bool indexIsInGroup(const QModelIndex &index) const;
66  DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
67  DynamicElementTextItem *textFromItem(QStandardItem *item) const;
68  QModelIndex indexFromText(DynamicElementTextItem *text) const;
69  QUndoCommand *undoForEditedText(
71  QUndoCommand *parent_undo = nullptr) const;
72  QUndoCommand *undoForEditedGroup(
73  ElementTextItemGroup *group,
74  QUndoCommand *parent_undo = nullptr) const;
75 
76  ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const;
77  ElementTextItemGroup *groupFromItem(QStandardItem *item) const;
78  QModelIndex indexFromGroup(ElementTextItemGroup *group) const;
79  bool indexIsText(const QModelIndex &index) const;
80  bool indexIsGroup(const QModelIndex &index) const;
81 
82  bool canDropMimeData(const QMimeData *data,
83  Qt::DropAction action,
84  int row,
85  int column,
86  const QModelIndex &parent) const override;
87  bool dropMimeData(const QMimeData *data,
88  Qt::DropAction action,
89  int row,
90  int column,
91  const QModelIndex &parent) override;
92  QMimeData *mimeData(const QModelIndexList &indexes) const override;
93  QStringList mimeTypes() const override;
94 
95  signals:
96  void dataChanged();
97 
98  private:
99  QList<QStandardItem *> itemsForText(DynamicElementTextItem *deti);
100  void addText(DynamicElementTextItem *deti);
102  void addGroup(ElementTextItemGroup *group);
103  void removeGroup(ElementTextItemGroup *group);
105  ElementTextItemGroup *group);
107  ElementTextItemGroup *group);
111  void itemDataChanged(QStandardItem *qsi);
112  void setConnection(DynamicElementTextItem *deti, bool set);
113  void setConnection(ElementTextItemGroup *group, bool set);
118 
119  private:
120  QPointer<Element> m_element;
121  QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
122  QHash <ElementTextItemGroup *, QStandardItem *> m_groups_list;
123  QHash <DynamicElementTextItem *,
124  QList<QMetaObject::Connection>> m_hash_text_connect;
125  QHash <ElementTextItemGroup *,
126  QList<QMetaObject::Connection>> m_hash_group_connect;
127  bool m_block_dataChanged = false;
128 };
129 
130 class DynamicTextItemDelegate : public QStyledItemDelegate
131 {
132  Q_OBJECT
133 
134  public:
135  DynamicTextItemDelegate(QObject *parent = Q_NULLPTR);
136 
137  QWidget *createEditor(QWidget *parent,
138  const QStyleOptionViewItem &option,
139  const QModelIndex &index) const override;
140  void setModelData(QWidget *editor,
141  QAbstractItemModel *model,
142  const QModelIndex &index) const override;
143 
144  protected:
145  bool eventFilter(QObject *object, QEvent *event) override;
146 
147  private:
148  QStringList availableInfo(DynamicElementTextItem *deti) const;
149 };
150 
151 #endif // DYNAMICELEMENTTEXTMODEL_H
DynamicTextItemDelegate::eventFilter
bool eventFilter(QObject *object, QEvent *event) override
Definition: dynamicelementtextmodel.cpp:1850
DynamicElementTextModel::m_element
QPointer< Element > m_element
Definition: dynamicelementtextmodel.h:120
Element::linkType
virtual kind linkType() const
Definition: element.h:159
DynamicElementTextModel::grpFrame
@ grpFrame
Definition: dynamicelementtextmodel.h:59
DynamicTextItemDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: dynamicelementtextmodel.cpp:1570
DynamicTextItemDelegate::availableInfo
QStringList availableInfo(DynamicElementTextItem *deti) const
DynamicTextItemDelegate::availableInfo.
Definition: dynamicelementtextmodel.cpp:1897
DynamicElementTextModel::indexFromText
QModelIndex indexFromText(DynamicElementTextItem *text) const
DynamicElementTextModel::indexFromText.
Definition: dynamicelementtextmodel.cpp:478
DynamicTextItemDelegate::setModelData
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: dynamicelementtextmodel.cpp:1740
DynamicElementTextModel::setConnection
void setConnection(DynamicElementTextItem *deti, bool set)
DynamicElementTextModel::setConnection Set up the connection for deti to keep up to date the data of ...
Definition: dynamicelementtextmodel.cpp:1342
DynamicElementTextItem
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
Definition: dynamicelementtextitem.h:39
DynamicElementTextModel::removeText
void removeText(DynamicElementTextItem *deti)
DynamicElementTextModel::removeText.
Definition: dynamicelementtextmodel.cpp:386
QET::Icons::textGroup
QIcon textGroup
Definition: qeticons.cpp:217
DynamicElementTextModel::infoText
@ infoText
Definition: dynamicelementtextmodel.h:43
DynamicElementTextModel::userText
@ userText
Definition: dynamicelementtextmodel.h:42
DynamicElementTextModel::updateDataFromText
void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type)
Definition: dynamicelementtextmodel.cpp:1414
DynamicElementTextModel::textFromItem
DynamicElementTextItem * textFromItem(QStandardItem *item) const
DynamicElementTextModel::textFromItem.
Definition: dynamicelementtextmodel.cpp:424
DynamicElementTextItem::infoName
QString infoName
Definition: dynamicelementtextitem.h:48
ElementTextItemGroup::holdToBottomPageChanged
void holdToBottomPageChanged(bool)
Element::elementInformations
DiagramContext elementInformations() const
Definition: element.h:97
conductor.h
ElementTextItemGroup::pos
QPointF pos
Definition: elementtextitemgroup.h:39
DynamicElementTextModel::groupFromIndex
ElementTextItemGroup * groupFromIndex(const QModelIndex &index) const
DynamicElementTextModel::groupFromIndex.
Definition: dynamicelementtextmodel.cpp:887
DynamicElementTextModel::textFrom
@ textFrom
Definition: dynamicelementtextmodel.h:41
DynamicElementTextModel::grpAlignment
@ grpAlignment
Definition: dynamicelementtextmodel.h:53
DynamicElementTextModel::itemsForText
QList< QStandardItem * > itemsForText(DynamicElementTextItem *deti)
DynamicElementTextModel::itemsForText.
Definition: dynamicelementtextmodel.cpp:124
DynamicElementTextModel::size
@ size
Definition: dynamicelementtextmodel.h:46
ElementTextItemGroup::verticalAdjustment
int verticalAdjustment
Definition: elementtextitemgroup.h:41
DynamicElementTextModel::textFromIndex
DynamicElementTextItem * textFromIndex(const QModelIndex &index) const
DynamicElementTextModel::textFromIndex.
Definition: dynamicelementtextmodel.cpp:404
DynamicElementTextItem::textWidth
qreal textWidth
Definition: dynamicelementtextitem.h:51
elementtextitemgroup.h
QETApp::elementInfoKeys
static QStringList elementInfoKeys()
QETApp::elementInfoKeys.
Definition: qetapp.cpp:366
DynamicElementTextModel
The DynamicElementTextModel class A model to use with QtView. This model display and can edit the val...
Definition: dynamicelementtextmodel.h:36
DiagramTextItem::color
QColor color
Definition: diagramtextitem.h:37
CompositeTextEditDialog
The CompositeTextEditDialog class CompositeTextEditDialog display a dialog use to write the complex t...
Definition: compositetexteditdialog.h:20
QET::Icons::PartText
QIcon PartText
Definition: qeticons.cpp:134
Element::textAdded
void textAdded(DynamicElementTextItem *deti)
DynamicElementTextModel::m_hash_text_connect
QHash< DynamicElementTextItem *, QList< QMetaObject::Connection > > m_hash_text_connect
Definition: dynamicelementtextmodel.h:124
DynamicElementTextModel::grpVAdjust
@ grpVAdjust
Definition: dynamicelementtextmodel.h:56
DynamicElementTextItem::frameChanged
void frameChanged(bool frame)
dynamicelementtextmodel.h
alignmenttextdialog.h
DynamicElementTextModel::indexIsText
bool indexIsText(const QModelIndex &index) const
DynamicElementTextModel::indexIsText.
Definition: dynamicelementtextmodel.cpp:948
DynamicElementTextItem::compositeTextChanged
void compositeTextChanged(QString text)
addelementtextcommand.h
DynamicTextItemDelegate::DynamicTextItemDelegate
DynamicTextItemDelegate(QObject *parent=Q_NULLPTR)
Definition: dynamicelementtextmodel.cpp:1566
DiagramTextItem::colorChanged
void colorChanged(QColor color)
DiagramTextItem::alignment
Qt::Alignment alignment
Definition: diagramtextitem.h:38
DynamicElementTextModel::m_hash_group_connect
QHash< ElementTextItemGroup *, QList< QMetaObject::Connection > > m_hash_group_connect
Definition: dynamicelementtextmodel.h:126
DynamicElementTextModel::m_texts_list
QHash< DynamicElementTextItem *, QStandardItem * > m_texts_list
Definition: dynamicelementtextmodel.h:121
qetapp.h
ElementTextItemGroup::alignment
Qt::Alignment alignment
Definition: elementtextitemgroup.h:42
Element::textsGroupAboutToBeRemoved
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group)
DynamicElementTextModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition: dynamicelementtextmodel.cpp:1159
DynamicElementTextModel::enableGroupRotationAndPos
void enableGroupRotationAndPos(ElementTextItemGroup *group)
DynamicElementTextModel::enableGroupRotation Enable/disable the item "group rotation" according the o...
Definition: dynamicelementtextmodel.cpp:1232
QETApp::elementTranslatedInfoKey
static QString elementTranslatedInfoKey(const QString &)
ElementsProperties::translatedInfo Return the translated information key given by info If info don't ...
Definition: qetapp.cpp:400
autonum::AssignVariables::replaceVariable
static QString replaceVariable(const QString &formula, const DiagramContext &dc)
AssignVariables::replaceVariable Replace the variables in formula in form %{my-var} to the correspond...
Definition: assignvariables.cpp:208
DynamicElementTextModel::m_block_dataChanged
bool m_block_dataChanged
Definition: dynamicelementtextmodel.h:127
ElementTextItemGroup::holdToBottomPage
bool holdToBottomPage
Definition: elementtextitemgroup.h:44
ElementTextItemGroup::frameChanged
void frameChanged(bool frame)
qeticons.h
DynamicElementTextModel::ValueType
ValueType
Definition: dynamicelementtextmodel.h:40
DynamicElementTextItem::uuid
QUuid uuid() const
Definition: dynamicelementtextitem.cpp:518
DynamicElementTextItem::textWidthChanged
void textWidthChanged(qreal width)
DynamicElementTextModel::grpRotation
@ grpRotation
Definition: dynamicelementtextmodel.h:55
DynamicElementTextItem::text
QString text
Definition: dynamicelementtextitem.h:46
DynamicElementTextModel::frame
@ frame
Definition: dynamicelementtextmodel.h:50
QET::correctAngle
qreal correctAngle(const qreal &)
Definition: qet.cpp:545
DynamicElementTextModel::groupFromItem
ElementTextItemGroup * groupFromItem(QStandardItem *item) const
DynamicElementTextModel::groupFromItem.
Definition: dynamicelementtextmodel.cpp:906
ElementTextItemGroup::yChanged
void yChanged()
compositetexteditdialog.h
DynamicElementTextModel::~DynamicElementTextModel
~DynamicElementTextModel() override
Definition: dynamicelementtextmodel.cpp:84
ElementTextItemGroup::texts
QList< DynamicElementTextItem * > texts() const
ElementTextItemGroup::texts.
Definition: elementtextitemgroup.cpp:330
DiagramTextItem::fontChanged
void fontChanged(QFont font)
Element::textRemovedFromGroup
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
DynamicElementTextItem::textFromChanged
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
DynamicElementTextModel::addGroup
void addGroup(ElementTextItemGroup *group)
DynamicElementTextModel::AddGroup Add a text item group to this model.
Definition: dynamicelementtextmodel.cpp:691
element.h
DynamicElementTextModel::grpHoldBottom
@ grpHoldBottom
Definition: dynamicelementtextmodel.h:58
DynamicElementTextItem::frame
bool frame
Definition: dynamicelementtextitem.h:50
Conductor::properties
ConductorProperties properties
Definition: conductor.h:48
DynamicElementTextItem::CompositeText
@ CompositeText
Definition: dynamicelementtextitem.h:58
qpropertyundocommand.h
DynamicElementTextModel::color
@ color
Definition: dynamicelementtextmodel.h:48
DynamicElementTextItem::elementUseForInfo
Element * elementUseForInfo() const
DynamicElementTextItem::elementUseForInfo.
Definition: dynamicelementtextitem.cpp:258
DynamicElementTextModel::removeGroup
void removeGroup(ElementTextItemGroup *group)
DynamicElementTextModel::removeGroup Remove the text item group from this model.
Definition: dynamicelementtextmodel.cpp:842
DynamicElementTextItem::updateXref
void updateXref()
DynamicElementTextItem::updateXref Create or delete the Xref according to the current properties of t...
Definition: dynamicelementtextitem.cpp:1251
DynamicElementTextModel::textWidth
@ textWidth
Definition: dynamicelementtextmodel.h:52
DiagramContext::value
QVariant value(const QString &key) const
Definition: diagramcontext.cpp:100
Element
Definition: element.h:41
ConductorProperties::m_function
QString m_function
Definition: conductorproperties.h:90
DynamicElementTextModel::grpName
@ grpName
Definition: dynamicelementtextmodel.h:57
ElementTextItemGroup::alignmentChanged
void alignmentChanged(Qt::Alignment)
DynamicElementTextItem::TextFrom
TextFrom
Definition: dynamicelementtextitem.h:55
DynamicElementTextItem::UserText
@ UserText
Definition: dynamicelementtextitem.h:56
Element::AllReport
@ AllReport
Definition: element.h:54
QPropertyUndoCommand::setAnimated
void setAnimated(bool animate=true, bool first_time=true)
QPropertyUndoCommand::setAnimated.
Definition: qpropertyundocommand.cpp:103
DynamicElementTextItem::parentElement
Element * parentElement() const
DynamicElementTextItem::ParentElement.
Definition: dynamicelementtextitem.cpp:227
DynamicElementTextItem::infoNameChanged
void infoNameChanged(QString info)
DynamicElementTextModel::canDropMimeData
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
Definition: dynamicelementtextmodel.cpp:1001
DynamicElementTextModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
DynamicElementTextModel::dropMimeData.
Definition: dynamicelementtextmodel.cpp:1062
Element::textsGroupAdded
void textsGroupAdded(ElementTextItemGroup *group)
RemoveTextFromGroupCommand
The RemoveTextFromGroupCommand class.
Definition: addelementtextcommand.h:125
DynamicTextItemDelegate
Definition: dynamicelementtextmodel.h:131
Element::textAddedToGroup
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
ElementTextItemGroup::xChanged
void xChanged()
DynamicElementTextModel::removeTextFromGroup
void removeTextFromGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group)
Definition: dynamicelementtextmodel.cpp:866
ElementTextItemGroup
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
Definition: elementtextitemgroup.h:36
DynamicElementTextItem::textFrom
TextFrom textFrom
Definition: dynamicelementtextitem.h:47
Element::textRemoved
void textRemoved(DynamicElementTextItem *deti)
DynamicElementTextModel::font
@ font
Definition: dynamicelementtextmodel.h:47
DynamicElementTextModel::DynamicElementTextModel
DynamicElementTextModel(Element *element, QObject *parent=nullptr)
Definition: dynamicelementtextmodel.cpp:60
DynamicElementTextModel::undoForEditedGroup
QUndoCommand * undoForEditedGroup(ElementTextItemGroup *group, QUndoCommand *parent_undo=nullptr) const
DynamicElementTextModel::undoForEditedGroup.
Definition: dynamicelementtextmodel.cpp:625
DynamicElementTextModel::compositeText
@ compositeText
Definition: dynamicelementtextmodel.h:44
DynamicElementTextItem::m_watched_conductor
QPointer< Conductor > m_watched_conductor
Definition: dynamicelementtextitem.h:142
DynamicElementTextModel::indexFromGroup
QModelIndex indexFromGroup(ElementTextItemGroup *group) const
DynamicElementTextModel::indexFromGroup.
Definition: dynamicelementtextmodel.cpp:933
DynamicElementTextModel::addTextToGroup
void addTextToGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group)
DynamicElementTextModel::textAddedToGroup Add the text text to the group group.
Definition: dynamicelementtextmodel.cpp:859
DynamicElementTextModel::rotation
@ rotation
Definition: dynamicelementtextmodel.h:51
DynamicElementTextModel::txtAlignment
@ txtAlignment
Definition: dynamicelementtextmodel.h:45
DynamicElementTextModel::addText
void addText(DynamicElementTextItem *deti)
DynamicElementTextModel::addText.
Definition: dynamicelementtextmodel.cpp:377
DiagramContext::contains
bool contains(const QString &) const
Definition: diagramcontext.cpp:70
DynamicElementTextModel::enableSourceText
void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf)
DynamicElementTextModel::enableSourceText Enable the good field, according to the current source of t...
Definition: dynamicelementtextmodel.cpp:1199
ElementTextItemGroup::verticalAdjustmentChanged
void verticalAdjustmentChanged(int)
QET::Horizontal
@ Horizontal
Horizontal segment.
Definition: qet.h:89
DiagramTextItem::font
QFont font
Definition: diagramtextitem.h:40
DynamicElementTextItem::parentGroup
ElementTextItemGroup * parentGroup() const
DynamicElementTextItem::parentGroup.
Definition: dynamicelementtextitem.cpp:236
dynamicelementtextitem.h
DynamicElementTextModel::pos
@ pos
Definition: dynamicelementtextmodel.h:49
DynamicElementTextModel::indexIsInGroup
bool indexIsInGroup(const QModelIndex &index) const
DynamicElementTextModel::indexIsInGroup.
Definition: dynamicelementtextmodel.cpp:99
AlignmentTextDialog::alignment
Qt::Alignment alignment() const
AlignmentTextDialog::alignment.
Definition: alignmenttextdialog.cpp:57
DynamicElementTextModel::indexIsGroup
bool indexIsGroup(const QModelIndex &index) const
DynamicElementTextModel::indexIsGroup.
Definition: dynamicelementtextmodel.cpp:978
Conductor
Definition: conductor.h:43
terminal.h
ConductorProperties::m_wire_color
QString m_wire_color
Definition: conductorproperties.h:92
ElementTextItemGroup::name
QString name
Definition: elementtextitemgroup.h:43
DynamicElementTextItem::compositeText
QString compositeText
Definition: dynamicelementtextitem.h:49
DynamicElementTextModel::mimeTypes
QStringList mimeTypes() const override
DynamicElementTextModel::mimeTypes.
Definition: dynamicelementtextmodel.cpp:1185
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
CompositeTextEditDialog::plainText
QString plainText() const
CompositeTextEditDialog::plainText.
Definition: compositetexteditdialog.cpp:41
DynamicElementTextModel::m_groups_list
QHash< ElementTextItemGroup *, QStandardItem * > m_groups_list
Definition: dynamicelementtextmodel.h:122
ConductorProperties::m_tension_protocol
QString m_tension_protocol
Definition: conductorproperties.h:91
ElementTextItemGroup::frame
bool frame
Definition: elementtextitemgroup.h:45
DynamicElementTextModel::updateDataFromGroup
void updateDataFromGroup(ElementTextItemGroup *group, DynamicElementTextModel::ValueType type)
Definition: dynamicelementtextmodel.cpp:1507
DynamicElementTextModel::itemDataChanged
void itemDataChanged(QStandardItem *qsi)
Definition: dynamicelementtextmodel.cpp:1269
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
AddTextToGroupCommand
The AddTextToGroupCommand class.
Definition: addelementtextcommand.h:105
DynamicElementTextItem::ElementInfo
@ ElementInfo
Definition: dynamicelementtextitem.h:57
ConductorProperties::m_wire_section
QString m_wire_section
Definition: conductorproperties.h:93
DynamicElementTextModel::grpPos
@ grpPos
Definition: dynamicelementtextmodel.h:54
AlignmentTextDialog
Definition: alignmenttextdialog.h:28
DynamicElementTextModel::dataChanged
void dataChanged()
DiagramContext
Definition: diagramcontext.h:56
diagram.h
DynamicElementTextItem::textChanged
void textChanged(QString text)
ElementTextItemGroup::rotation
qreal rotation
Definition: elementtextitemgroup.h:40
DynamicElementTextModel::undoForEditedText
QUndoCommand * undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo=nullptr) const
DynamicElementTextModel::undoForEditedText.
Definition: dynamicelementtextmodel.cpp:496
ElementTextItemGroup::rotationChanged
void rotationChanged(qreal)