/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* 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 . *
* *
** 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 . *
* *
* 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 "lrflagspropitem.h"
#include "lrenumpropitem.h"
#include "lrboolpropitem.h"
#include "../editors/lrcheckboxeditor.h"
#include "lrobjectitemmodel.h"
#include
#include
#include
#include
#include
#include
namespace {
LimeReport::ObjectPropItem * createFlagsPropItem(
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
{
return new LimeReport::FlagsPropItem(object, objects, name, displayName, data, parent, readonly);
}
bool registred = LimeReport::ObjectPropFactory::instance().registerCreator(
LimeReport::APropIdent("flags",""),QObject::tr("flags"),createFlagsPropItem
);
} // namespace
namespace LimeReport {
void FlagsPropItem::createChildren()
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
for (int i=0;iappendItem(new LimeReport::FlagPropItem(
object(), objects(), QString(propEnum.key(i)), QString(propEnum.key(i)),
bool((propertyValue().toInt() & propEnum.keyToValue(propEnum.key(i)))==propEnum.keyToValue(propEnum.key(i))),
this, false
)
);
}
}
void FlagsPropItem::updateChildren()
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
for (int i=0;isetPropertyValue(bool((propertyValue().toInt() & propEnum.keyToValue(propEnum.key(i)))==propEnum.keyToValue(propEnum.key(i))));
}
}
FlagsPropItem::FlagsPropItem(QObject *object, ObjectPropItem::ObjectsList *objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent, bool readonly)
:ObjectPropItem(object, objects, name, displayName, value, parent, readonly)
{
createChildren();
}
FlagsPropItem::FlagsPropItem(QObject *object, ObjectPropItem::ObjectsList *objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent, bool readonly, QSet acceptableValues)
:ObjectPropItem(object, objects, name, displayName, value, parent, readonly),m_acceptableValues(acceptableValues){}
QString FlagsPropItem::displayValue() const
{
QString result;
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
for (int i=0;i(propertyEditor);
editor->setChecked(propertyValue().toBool());
}
void FlagPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
bool value = qobject_cast(propertyEditor)->isChecked();
model->setData(index,value);
int flags = object()->property(parent()->propertyName().toLatin1()).toInt();
if (value) flags=flags | valueByName(displayName());
else if (flags&valueByName(displayName())) flags=flags ^ valueByName(displayName());
setValueToObject(parent()->propertyName(),flags);
parent()->setPropertyValue(flags);
}
int FlagPropItem::valueByName(const QString& typeName)
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(parent()->propertyName().toLatin1())).enumerator();
return propEnum.keyToValue(typeName.toLatin1());
}
} // namespace LimeReport