0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
LimeReport/limereport/objectinspector/lrobjectpropitem.cpp

230 lines
8.1 KiB
C++
Raw Permalink 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. *
****************************************************************************/
#include "lrobjectpropitem.h"
2016-02-17 10:11:00 +03:00
#include "lrobjectitemmodel.h"
#ifdef INSPECT_BASEDESIGN
#include "lrbasedesignintf.h"
#endif
#include <QDebug>
namespace LimeReport {
bool lesThen(ObjectPropItem* v1, ObjectPropItem* v2)
2016-02-17 10:11:00 +03:00
{
return v1->displayName().compare(v2->displayName()) < 0;
}
ObjectPropItem::ObjectPropItem(QObject* object, ObjectsList* objects, const QString& name,
const QString& displayName, ObjectPropItem* parent, bool isClass):
m_object(object),
m_name(name),
m_displayName(displayName),
m_haveValue(false),
m_parent(parent),
m_colorIndex(-1),
m_readonly(true),
m_model(0),
m_isClass(isClass),
m_changingValue(false),
m_translatePropperty(true)
{
if (parent)
setModel(parent->model());
m_index = QModelIndex();
// if (objects) foreach(QObject* item, *objects) m_objects.append(item);
m_objects = objects;
2016-02-17 10:11:00 +03:00
#ifdef INSPECT_BASEDESIGN
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object);
if (item) {
connect(item, SIGNAL(propertyChanged(QString, QVariant, QVariant)), this,
SLOT(slotPropertyChanged(QString, QVariant, QVariant)));
connect(item, SIGNAL(propertyObjectNameChanged(QString, QString)), this,
SLOT(slotPropertyObjectName(QString, QString)));
2016-02-17 10:11:00 +03:00
}
#endif
}
ObjectPropItem::ObjectPropItem(QObject* object, ObjectsList* objects, const QString& name,
const QString& displayName, const QVariant& value,
ObjectPropItem* parent, bool readonly):
m_object(object),
m_name(name),
m_displayName(displayName),
m_value(value),
m_haveValue(true),
m_parent(parent),
m_colorIndex(-1),
m_readonly(readonly),
m_model(0),
m_isClass(false),
m_changingValue(false),
m_translatePropperty(true)
2016-02-17 10:11:00 +03:00
{
if (parent)
setModel(parent->model());
m_index = QModelIndex();
// if (objects) foreach(QObject* item, *objects) m_objects.append(item);
m_objects = objects;
2016-02-17 10:11:00 +03:00
#ifdef INSPECT_BASEDESIGN
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(object);
if (item) {
connect(item, SIGNAL(propertyChanged(QString, QVariant, QVariant)), this,
SLOT(slotPropertyChanged(QString, QVariant, QVariant)));
connect(item, SIGNAL(propertyObjectNameChanged(QString, QString)), this,
SLOT(slotPropertyObjectName(QString, QString)));
2016-02-17 10:11:00 +03:00
}
#endif
}
ObjectPropItem::~ObjectPropItem() { qDeleteAll(m_childItems); }
2016-02-17 10:11:00 +03:00
int ObjectPropItem::childCount() { return m_childItems.count(); }
2016-02-17 10:11:00 +03:00
void ObjectPropItem::appendItem(ObjectPropItem* item)
2016-02-17 10:11:00 +03:00
{
m_childItems.append(item);
if (m_parent && (!item->isClass()))
m_parent->m_globalPropList.append(item);
2016-02-17 10:11:00 +03:00
}
void ObjectPropItem::sortItem() { std::sort(m_childItems.begin(), m_childItems.end(), lesThen); }
2016-02-17 10:11:00 +03:00
QVariant ObjectPropItem::propertyValue() const { return m_value; }
void ObjectPropItem::setPropertyValue(QVariant value)
{
m_value = value;
LimeReport::QObjectPropertyModel* itemModel
= dynamic_cast<LimeReport::QObjectPropertyModel*>(model());
if (itemModel) {
2016-02-17 10:11:00 +03:00
itemModel->itemDataChanged(modelIndex());
foreach (ObjectPropItem* item, children()) {
if (item->modelIndex().isValid())
itemModel->itemDataChanged(item->modelIndex());
2016-02-17 10:11:00 +03:00
}
}
}
QString ObjectPropItem::displayName() const
{
return isTranslateProperty() ? m_displayName : propertyName();
}
int ObjectPropItem::row()
{
2016-02-17 10:11:00 +03:00
if (m_parent)
return m_parent->m_childItems.indexOf(const_cast<ObjectPropItem*>(this));
return 0;
}
ObjectPropItem* ObjectPropItem::child(int row) { return m_childItems[row]; }
2016-02-17 10:11:00 +03:00
void ObjectPropItem::setColorIndex(int value)
{
m_colorIndex = value;
for (int i = 0; i < m_childItems.count(); i++) {
2016-02-17 10:11:00 +03:00
m_childItems[i]->setColorIndex(value);
}
}
#ifdef INSPECT_BASEDESIGN
void ObjectPropItem::slotPropertyChanged(const QString& name, QVariant, QVariant newValue)
2016-02-17 10:11:00 +03:00
{
if (name.compare(propertyName(), Qt::CaseInsensitive) == 0 && !isValueChanging()) {
2016-02-17 10:11:00 +03:00
setPropertyValue(newValue);
}
}
void ObjectPropItem::slotPropertyObjectName(const QString& oldValue, const QString& newValue)
2016-02-17 10:11:00 +03:00
{
Q_UNUSED(oldValue)
if (propertyName().compare("objectName", Qt::CaseInsensitive) == 0 && !isValueChanging()) {
2016-02-17 10:11:00 +03:00
setPropertyValue(newValue);
}
}
#endif
void ObjectPropItem::setValueToObject(const QString& propertyName, QVariant propertyValue)
2016-02-17 10:18:19 +03:00
{
object()->setProperty(propertyName.toLatin1(), propertyValue);
if (objects()) {
2016-11-01 14:56:06 +03:00
foreach (QObject* item, *objects()) {
if (item->metaObject()->indexOfProperty(propertyName.toLatin1()) != -1)
2016-11-01 14:56:06 +03:00
item->setProperty(propertyName.toLatin1(), propertyValue);
}
2016-02-17 10:18:19 +03:00
}
}
bool ObjectPropItem::isTranslateProperty() const { return m_translatePropperty; }
void ObjectPropItem::setTranslateProperty(bool translatePropperty)
{
m_translatePropperty = translatePropperty;
}
ObjectPropItem* ObjectPropItem::findChild(const QString& name)
2016-02-17 10:11:00 +03:00
{
foreach (ObjectPropItem* item, m_childItems) {
if (item->propertyName() == name)
return item;
2016-02-17 10:11:00 +03:00
}
return 0;
}
ObjectPropItem* ObjectPropItem::findPropertyItem(const QString& propertyName)
2016-02-17 10:11:00 +03:00
{
foreach (ObjectPropItem* item, m_globalPropList) {
if (item->propertyName() == propertyName)
return item;
2016-02-17 10:11:00 +03:00
}
return 0;
}
void ObjectPropItem::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
const QModelIndex&) const
2016-02-17 10:11:00 +03:00
{
editor->setGeometry(option.rect);
}
void ObjectPropItem::updatePropertyValue()
{
m_model->setData(m_index, m_object->property(m_name.toLatin1()));
2016-02-17 10:11:00 +03:00
}
bool ObjectPropItem::paint(QPainter*, const StyleOptionViewItem&, const QModelIndex&)
2016-02-17 10:11:00 +03:00
{
return false;
}
QString ObjectPropItem::displayValue() const { return m_value.toString(); }
2016-02-17 10:11:00 +03:00
} // namespace LimeReport