QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
dynamicelementtextmodel.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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 "../qetgraphicsitem/dynamicelementtextitem.h"
22
23#include <QHash>
24#include <QStandardItemModel>
25#include <qstyleditemdelegate.h>
26
27class QUndoCommand;
29class Element;
30
37class DynamicElementTextModel : public QStandardItemModel
38{
39 Q_OBJECT
40
41 public:
64
65 DynamicElementTextModel(Element *element, QObject *parent = nullptr);
66 ~DynamicElementTextModel() override;
67
68 bool indexIsInGroup(const QModelIndex &index) const;
69 DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
70 DynamicElementTextItem *textFromItem(QStandardItem *item) const;
71 QModelIndex indexFromText(DynamicElementTextItem *text) const;
72 QUndoCommand *undoForEditedText(
74 QUndoCommand *parent_undo = nullptr) const;
75 QUndoCommand *undoForEditedGroup(
77 QUndoCommand *parent_undo = nullptr) const;
78
79 ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const;
80 ElementTextItemGroup *groupFromItem(QStandardItem *item) const;
81 QModelIndex indexFromGroup(ElementTextItemGroup *group) const;
82 bool indexIsText(const QModelIndex &index) const;
83 bool indexIsGroup(const QModelIndex &index) const;
84
85 bool canDropMimeData(
86 const QMimeData *data,
87 Qt::DropAction action,
88 int row,
89 int column,
90 const QModelIndex &parent) const override;
91 bool dropMimeData(
92 const QMimeData *data,
93 Qt::DropAction action,
94 int row,
95 int column,
96 const QModelIndex &parent) override;
97 QMimeData *mimeData(const QModelIndexList &indexes) const override;
98 QStringList mimeTypes() const override;
99
100 signals:
102
103 private:
104 QList<QStandardItem *> itemsForText(DynamicElementTextItem *deti);
107 void addGroup(ElementTextItemGroup *group);
109 void addTextToGroup(
111 ElementTextItemGroup *group);
113 ElementTextItemGroup *group);
114 void enableSourceText(
118 void itemDataChanged(QStandardItem *qsi);
119 void setConnection(DynamicElementTextItem *deti, bool set);
120 void setConnection(ElementTextItemGroup *group, bool set);
125
126 private:
127 QPointer<Element> m_element;
128 QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
129 QHash <ElementTextItemGroup *, QStandardItem *> m_groups_list;
130 QHash <DynamicElementTextItem *,
131 QList<QMetaObject::Connection>> m_hash_text_connect;
132 QHash <ElementTextItemGroup *,
133 QList<QMetaObject::Connection>> m_hash_group_connect;
135};
136
137class DynamicTextItemDelegate : public QStyledItemDelegate
138{
139 Q_OBJECT
140
141 public:
142 DynamicTextItemDelegate(QObject *parent = Q_NULLPTR);
143
144 QWidget *createEditor(
145 QWidget *parent,
146 const QStyleOptionViewItem &option,
147 const QModelIndex &index) const override;
148 void setModelData(
149 QWidget *editor,
150 QAbstractItemModel *model,
151 const QModelIndex &index) const override;
152
153 protected:
154 bool eventFilter(QObject *object, QEvent *event) override;
155
156 private:
157 QStringList availableInfo(DynamicElementTextItem *deti) const;
158};
159
160#endif // DYNAMICELEMENTTEXTMODEL_H
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
Definition dynamicelementtextitem.h:40
TextFrom
Definition dynamicelementtextitem.h:57
The DynamicElementTextModel class A model to use with QtView. This model display and can edit the val...
Definition dynamicelementtextmodel.h:38
QHash< DynamicElementTextItem *, QList< QMetaObject::Connection > > m_hash_text_connect
Definition dynamicelementtextmodel.h:131
void enableGroupRotationAndPos(ElementTextItemGroup *group)
DynamicElementTextModel::enableGroupRotation Enable/disable the item "group rotation" according the o...
Definition dynamicelementtextmodel.cpp:1260
DynamicElementTextItem * textFromIndex(const QModelIndex &index) const
DynamicElementTextModel::textFromIndex.
Definition dynamicelementtextmodel.cpp:422
bool indexIsInGroup(const QModelIndex &index) const
DynamicElementTextModel::indexIsInGroup.
Definition dynamicelementtextmodel.cpp:103
bool indexIsText(const QModelIndex &index) const
DynamicElementTextModel::indexIsText.
Definition dynamicelementtextmodel.cpp:976
~DynamicElementTextModel() override
Definition dynamicelementtextmodel.cpp:88
QUndoCommand * undoForEditedGroup(ElementTextItemGroup *group, QUndoCommand *parent_undo=nullptr) const
DynamicElementTextModel::undoForEditedGroup.
Definition dynamicelementtextmodel.cpp:653
ValueType
Definition dynamicelementtextmodel.h:42
@ pos
Definition dynamicelementtextmodel.h:51
@ keepVisualRotation
Definition dynamicelementtextmodel.h:54
@ textWidth
Definition dynamicelementtextmodel.h:55
@ grpVAdjust
Definition dynamicelementtextmodel.h:59
@ size
Definition dynamicelementtextmodel.h:48
@ grpAlignment
Definition dynamicelementtextmodel.h:56
@ textFrom
Definition dynamicelementtextmodel.h:43
@ color
Definition dynamicelementtextmodel.h:50
@ infoText
Definition dynamicelementtextmodel.h:45
@ txtAlignment
Definition dynamicelementtextmodel.h:47
@ compositeText
Definition dynamicelementtextmodel.h:46
@ grpFrame
Definition dynamicelementtextmodel.h:62
@ font
Definition dynamicelementtextmodel.h:49
@ grpName
Definition dynamicelementtextmodel.h:60
@ grpPos
Definition dynamicelementtextmodel.h:57
@ grpRotation
Definition dynamicelementtextmodel.h:58
@ userText
Definition dynamicelementtextmodel.h:44
@ rotation
Definition dynamicelementtextmodel.h:53
@ grpHoldBottom
Definition dynamicelementtextmodel.h:61
@ frame
Definition dynamicelementtextmodel.h:52
QList< QStandardItem * > itemsForText(DynamicElementTextItem *deti)
DynamicElementTextModel::itemsForText.
Definition dynamicelementtextmodel.cpp:128
bool indexIsGroup(const QModelIndex &index) const
DynamicElementTextModel::indexIsGroup.
Definition dynamicelementtextmodel.cpp:1006
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition dynamicelementtextmodel.cpp:1187
void updateDataFromGroup(ElementTextItemGroup *group, DynamicElementTextModel::ValueType type)
Definition dynamicelementtextmodel.cpp:1535
QStringList mimeTypes() const override
DynamicElementTextModel::mimeTypes.
Definition dynamicelementtextmodel.cpp:1213
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:1370
void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type)
Definition dynamicelementtextmodel.cpp:1442
QModelIndex indexFromText(DynamicElementTextItem *text) const
DynamicElementTextModel::indexFromText.
Definition dynamicelementtextmodel.cpp:496
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
Definition dynamicelementtextmodel.cpp:1029
void addGroup(ElementTextItemGroup *group)
DynamicElementTextModel::AddGroup Add a text item group to this model.
Definition dynamicelementtextmodel.cpp:719
void removeText(DynamicElementTextItem *deti)
DynamicElementTextModel::removeText.
Definition dynamicelementtextmodel.cpp:404
void itemDataChanged(QStandardItem *qsi)
Definition dynamicelementtextmodel.cpp:1297
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
DynamicElementTextModel::dropMimeData.
Definition dynamicelementtextmodel.cpp:1090
void addTextToGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group)
DynamicElementTextModel::textAddedToGroup Add the text text to the group group.
Definition dynamicelementtextmodel.cpp:887
QHash< DynamicElementTextItem *, QStandardItem * > m_texts_list
Definition dynamicelementtextmodel.h:128
ElementTextItemGroup * groupFromItem(QStandardItem *item) const
DynamicElementTextModel::groupFromItem.
Definition dynamicelementtextmodel.cpp:934
QPointer< Element > m_element
Definition dynamicelementtextmodel.h:127
void removeTextFromGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group)
Definition dynamicelementtextmodel.cpp:894
void addText(DynamicElementTextItem *deti)
DynamicElementTextModel::addText.
Definition dynamicelementtextmodel.cpp:395
QHash< ElementTextItemGroup *, QList< QMetaObject::Connection > > m_hash_group_connect
Definition dynamicelementtextmodel.h:133
DynamicElementTextItem * textFromItem(QStandardItem *item) const
DynamicElementTextModel::textFromItem.
Definition dynamicelementtextmodel.cpp:442
QHash< ElementTextItemGroup *, QStandardItem * > m_groups_list
Definition dynamicelementtextmodel.h:129
void removeGroup(ElementTextItemGroup *group)
DynamicElementTextModel::removeGroup Remove the text item group from this model.
Definition dynamicelementtextmodel.cpp:870
ElementTextItemGroup * groupFromIndex(const QModelIndex &index) const
DynamicElementTextModel::groupFromIndex.
Definition dynamicelementtextmodel.cpp:915
QModelIndex indexFromGroup(ElementTextItemGroup *group) const
DynamicElementTextModel::indexFromGroup.
Definition dynamicelementtextmodel.cpp:961
QUndoCommand * undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo=nullptr) const
DynamicElementTextModel::undoForEditedText.
Definition dynamicelementtextmodel.cpp:514
void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf)
DynamicElementTextModel::enableSourceText Enable the good field, according to the current source of t...
Definition dynamicelementtextmodel.cpp:1227
bool m_block_dataChanged
Definition dynamicelementtextmodel.h:134
Definition dynamicelementtextmodel.h:138
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition dynamicelementtextmodel.cpp:1598
bool eventFilter(QObject *object, QEvent *event) override
Definition dynamicelementtextmodel.cpp:1878
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition dynamicelementtextmodel.cpp:1768
QStringList availableInfo(DynamicElementTextItem *deti) const
DynamicTextItemDelegate::availableInfo.
Definition dynamicelementtextmodel.cpp:1925
Definition element.h:43
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
Definition elementtextitemgroup.h:36