2017-08-03 17:36:08 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2017-08-03 17:36:08 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef DYNAMICELEMENTTEXTMODEL_H
|
|
|
|
#define DYNAMICELEMENTTEXTMODEL_H
|
|
|
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <qstyleditemdelegate.h>
|
|
|
|
#include "dynamicelementtextitem.h"
|
|
|
|
|
|
|
|
class QUndoCommand;
|
2017-11-27 19:37:39 +00:00
|
|
|
class ElementTextItemGroup;
|
|
|
|
class Element;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief The DynamicElementTextModel class
|
|
|
|
A model to use with QtView.
|
|
|
|
This model display and can edit the value of dynamic text of an element.
|
|
|
|
Set the delegate DynamicTextItemDelegate as delegate of this model.
|
|
|
|
*/
|
2017-08-03 17:36:08 +00:00
|
|
|
class DynamicElementTextModel : public QStandardItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-15 20:20:07 +02:00
|
|
|
enum ValueType {
|
|
|
|
textFrom =1,
|
|
|
|
userText,
|
|
|
|
infoText,
|
|
|
|
compositeText,
|
|
|
|
txtAlignment,
|
|
|
|
size,
|
|
|
|
font,
|
|
|
|
color,
|
|
|
|
pos,
|
|
|
|
frame,
|
|
|
|
rotation,
|
|
|
|
textWidth,
|
|
|
|
grpAlignment,
|
|
|
|
grpPos,
|
|
|
|
grpRotation,
|
|
|
|
grpVAdjust,
|
|
|
|
grpName,
|
|
|
|
grpHoldBottom,
|
|
|
|
grpFrame
|
|
|
|
};
|
|
|
|
|
|
|
|
DynamicElementTextModel(Element *element, QObject *parent = nullptr);
|
|
|
|
~DynamicElementTextModel() override;
|
|
|
|
|
|
|
|
bool indexIsInGroup(const QModelIndex &index) const;
|
|
|
|
DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
|
|
|
|
DynamicElementTextItem *textFromItem(QStandardItem *item) const;
|
|
|
|
QModelIndex indexFromText(DynamicElementTextItem *text) const;
|
|
|
|
QUndoCommand *undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo = nullptr) const;
|
|
|
|
QUndoCommand *undoForEditedGroup(ElementTextItemGroup *group, QUndoCommand *parent_undo = nullptr) const;
|
|
|
|
|
|
|
|
ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const;
|
|
|
|
ElementTextItemGroup *groupFromItem(QStandardItem *item) const;
|
|
|
|
QModelIndex indexFromGroup(ElementTextItemGroup *group) const;
|
|
|
|
bool indexIsText(const QModelIndex &index) const;
|
|
|
|
bool indexIsGroup(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
|
|
|
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
|
|
|
QStringList mimeTypes() const override;
|
|
|
|
|
2017-08-24 17:35:40 +00:00
|
|
|
signals:
|
2020-07-15 20:20:07 +02:00
|
|
|
void dataChanged();
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
private:
|
2020-07-15 20:20:07 +02:00
|
|
|
QList<QStandardItem *> itemsForText(DynamicElementTextItem *deti);
|
|
|
|
void addText(DynamicElementTextItem *deti);
|
|
|
|
void removeText(DynamicElementTextItem *deti);
|
|
|
|
void addGroup(ElementTextItemGroup *group);
|
|
|
|
void removeGroup(ElementTextItemGroup *group);
|
|
|
|
void addTextToGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group);
|
|
|
|
void removeTextFromGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group);
|
|
|
|
void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf );
|
|
|
|
void enableGroupRotationAndPos(ElementTextItemGroup *group);
|
|
|
|
void itemDataChanged(QStandardItem *qsi);
|
|
|
|
void setConnection(DynamicElementTextItem *deti, bool set);
|
|
|
|
void setConnection(ElementTextItemGroup *group, bool set);
|
|
|
|
void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type);
|
|
|
|
void updateDataFromGroup(ElementTextItemGroup *group, DynamicElementTextModel::ValueType type);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QPointer<Element> m_element;
|
|
|
|
QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
|
|
|
|
QHash <ElementTextItemGroup *, QStandardItem *> m_groups_list;
|
|
|
|
QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect;
|
|
|
|
QHash <ElementTextItemGroup *, QList<QMetaObject::Connection>> m_hash_group_connect;
|
|
|
|
bool m_block_dataChanged = false;
|
2017-08-03 17:36:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DynamicTextItemDelegate : public QStyledItemDelegate
|
|
|
|
{
|
2017-11-06 16:17:48 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
public:
|
|
|
|
DynamicTextItemDelegate(QObject *parent = Q_NULLPTR);
|
|
|
|
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
|
|
|
2017-11-05 14:33:03 +00:00
|
|
|
protected:
|
2020-07-15 20:20:07 +02:00
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
|
|
|
2017-08-06 10:18:33 +00:00
|
|
|
private:
|
2020-07-15 20:20:07 +02:00
|
|
|
QStringList availableInfo(DynamicElementTextItem *deti) const;
|
2017-08-03 17:36:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DYNAMICELEMENTTEXTMODEL_H
|