mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
First step for the dynamic element text : Now user can add directly from the diagram editor an editable text of an element.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5005 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
76
sources/ui/dynamicelementtextmodel.h
Normal file
76
sources/ui/dynamicelementtextmodel.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
class DynamicElementTextModel : public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ValueType {
|
||||
textFrom =1,
|
||||
userText,
|
||||
infoText,
|
||||
size,
|
||||
tagg,
|
||||
color
|
||||
};
|
||||
|
||||
DynamicElementTextModel(QObject *parent = nullptr);
|
||||
~DynamicElementTextModel();
|
||||
|
||||
void addText(DynamicElementTextItem *deti);
|
||||
void removeText(DynamicElementTextItem *deti);
|
||||
DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
|
||||
DynamicElementTextItem *textFromItem(QStandardItem *item) const;
|
||||
QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const;
|
||||
|
||||
private:
|
||||
void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf );
|
||||
void dataEdited(QStandardItem *qsi);
|
||||
void setConnection(DynamicElementTextItem *deti, bool set);
|
||||
void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type);
|
||||
|
||||
private:
|
||||
QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
|
||||
QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect;
|
||||
};
|
||||
|
||||
class DynamicTextItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
DynamicTextItemDelegate(QObject *parent = Q_NULLPTR);
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif // DYNAMICELEMENTTEXTMODEL_H
|
||||
Reference in New Issue
Block a user