0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-27 09:58:11 +03:00
LimeReport/limereport/objectinspector/lrobjectpropitem.h

147 lines
7.1 KiB
C
Raw Normal View History

2016-02-17 10:11:00 +03:00
/***************************************************************************
* This file is part of the Lime Report project *
2021-08-18 20:21:36 +03:00
* Copyright (C) 2021 by Alexander Arin *
2016-02-17 10:11:00 +03:00
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library 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 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library 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. *
****************************************************************************/
#ifndef LROBJECTPROPITEM_H
#define LROBJECTPROPITEM_H
#include <QString>
#include <QVariant>
#include <QModelIndex>
#include <QMetaProperty>
#include <QAbstractItemModel>
#include <QDebug>
#include "lrattribsabstractfactory.h"
#include "lrsingleton.h"
namespace LimeReport{
class ObjectPropItem : public QObject
{
Q_OBJECT
public:
typedef QList< QObject* > ObjectsList;
ObjectPropItem(){invalidate();}
ObjectPropItem(QObject *object, ObjectsList* objects, const QString& propertyName, const QString& displayName, const QVariant& propertyValue, ObjectPropItem* parent, bool readonly=true);
ObjectPropItem(QObject *object, ObjectsList* objects, const QString& propertyName, const QString& displayName, ObjectPropItem *parent, bool isClass = false);
~ObjectPropItem();
virtual QVariant propertyValue() const;
virtual void setPropertyValue(QVariant value);
virtual QString propertyName() const {return m_name;}
virtual QString displayName() const;
2016-02-17 10:11:00 +03:00
virtual QString displayValue() const;
virtual QIcon iconValue() const{return QIcon();}
virtual bool isHaveChildren() const {return m_childItems.count()>0;}
virtual bool isHaveValue() const {return m_haveValue;}
virtual bool isValueReadonly() const {return m_readonly;}
void setValueReadOnly(bool value){m_readonly=value;}
virtual bool isValueModified() const {return false;}
virtual QWidget* createProperyEditor(QWidget * /*parent*/) const {return 0;}
virtual void setPropertyEditorData(QWidget *, const QModelIndex &) const{}
virtual void setModelData(QWidget * /*editor*/, QAbstractItemModel * /*model*/, const QModelIndex &/*index*/){}
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const;
virtual void updatePropertyValue();
virtual bool paint(QPainter *, const StyleOptionViewItem &, const QModelIndex &);
2016-02-17 10:11:00 +03:00
ObjectPropItem* parent() const{ return m_parent;}
QObject* object() const{return m_object;}
ObjectsList* objects() {return m_objects;}
2016-02-17 10:11:00 +03:00
ObjectPropItem* child(int row);
QList<ObjectPropItem*> children(){return m_childItems;}
ObjectPropItem* findChild(const QString& propertyName);
ObjectPropItem* findPropertyItem(const QString& propertyName);
int childCount();
void appendItem(ObjectPropItem* item);
void sortItem();
int row();
bool isValid(){return m_valid;}
int colorIndex(){return m_colorIndex;}
void setColorIndex(int propertyValue);
void setModel(QAbstractItemModel* model){m_model=model;}
QAbstractItemModel* model(){return m_model;}
2016-06-10 18:05:18 +03:00
void setModelIndex(const QModelIndex& index){m_index=index;}
2016-02-17 10:11:00 +03:00
QModelIndex modelIndex(){return m_index;}
bool isClass(){return m_isClass;}
bool isTranslateProperty() const;
void setTranslateProperty(bool translatePropperty);
2016-02-17 10:11:00 +03:00
#ifdef INSPECT_BASEDESIGN
private slots:
void slotPropertyChanged(const QString& name, QVariant, QVariant newValue);
void slotPropertyObjectName(const QString& oldValue, const QString& newValue);
#endif
private:
bool m_valid;
void invalidate(){m_object=0; m_objects=0; m_valid = false; m_name = ""; m_value=QVariant(); m_isClass=false;}
2016-02-17 10:18:19 +03:00
2016-02-17 10:11:00 +03:00
protected:
void beginChangeValue(){ m_changingValue = true; }
void endChangeValue(){ m_changingValue = false; }
bool isValueChanging(){ return m_changingValue; }
2016-02-17 10:18:19 +03:00
void setValueToObject(const QString& propertyName, QVariant propertyValue);
2016-02-17 10:11:00 +03:00
private:
QObject* m_object;
ObjectsList* m_objects;
2016-02-17 10:11:00 +03:00
QString m_name;
QString m_displayName;
QVariant m_value;
bool m_haveValue;
ObjectPropItem* m_parent;
QList<ObjectPropItem*> m_childItems;
QList<ObjectPropItem*> m_globalPropList;
int m_colorIndex;
bool m_readonly;
QAbstractItemModel* m_model;
QModelIndex m_index;
bool m_isClass;
bool m_changingValue;
bool m_translatePropperty;
2016-02-17 10:11:00 +03:00
};
typedef QPair<QString,QString> APropIdent;
typedef ObjectPropItem* (*CreatePropItem)(QObject *object, ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly);
class ObjectPropFactory : public AttribsAbstractFactory<LimeReport::ObjectPropItem, APropIdent, CreatePropItem, QString>
{
private:
friend class Singleton<ObjectPropFactory>;
private:
ObjectPropFactory(){}
~ObjectPropFactory(){}
ObjectPropFactory(const ObjectPropFactory&){}
ObjectPropFactory& operator = (const ObjectPropFactory&){return *this;}
};
}
Q_DECLARE_METATYPE(LimeReport::ObjectPropItem*)
2016-02-17 10:11:00 +03:00
#endif // LROBJECTPROPITEM_H