0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-30 19:38:10 +03:00
LimeReport/limereport/objectinspector/propertyItems/lrenumpropitem.cpp

182 lines
6.8 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. *
****************************************************************************/
#include "lrenumpropitem.h"
#include "../editors/lrcomboboxeditor.h"
#include "lrbanddesignintf.h"
namespace {
LimeReport::ObjectPropItem * createEnumPropItem(
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
{
return new LimeReport::EnumPropItem(object, objects, name, displayName, data, parent, readonly);
}
2016-10-18 15:00:26 +03:00
bool VARIABLE_IS_NOT_USED registred = LimeReport::ObjectPropFactory::instance().registerCreator(
2016-02-17 10:11:00 +03:00
LimeReport::APropIdent("enum",""),QObject::tr("enum"),createEnumPropItem
);
}
namespace LimeReport {
QWidget *EnumPropItem::createProperyEditor(QWidget *parent) const
{
ComboBoxEditor *editor = new ComboBoxEditor(parent,false);
connect(editor,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotEnumChanged(QString)));
QStringList enumValues;
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
for (int i=0;i<propEnum.keyCount();i++){
if (m_acceptableValues.isEmpty()) enumValues.append(tr(propEnum.key(i)));
2016-02-17 10:11:00 +03:00
else {
if (m_acceptableValues.contains(propEnum.value(i))){
enumValues.append(tr(propEnum.key(i)));
2016-02-17 10:11:00 +03:00
}
}
}
editor->addItems(enumValues);
return editor;
}
void EnumPropItem::slotEnumChanged(const QString &text)
{
if ( nameByType(object()->property(propertyName().toLatin1()).toInt())!=text){
beginChangeValue();
setPropertyValue(typeByName(text));
2016-02-17 10:39:17 +03:00
setValueToObject(propertyName(),typeByName(text));
2016-02-17 10:11:00 +03:00
endChangeValue();
}
}
void EnumPropItem::initTranslation()
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
for (int i=0;i<propEnum.keyCount();i++){
m_translation.insert(QString(tr(propEnum.key(i))), QString(propEnum.key(i)));
}
}
void EnumPropItem::translateEnumItemName()
{
tr("Default");
tr("Portrait");
tr("Landscape");
tr("NoneAutoWidth");
tr("MaxWordLength");
tr("MaxStringLength");
tr("TransparentMode");
tr("OpaqueMode");
tr("Angle0");
tr("Angle90");
tr("Angle180");
tr("Angle270");
tr("Angle45");
tr("Angle315");
tr("DateTime");
tr("Double");
tr("NoBrush");
tr("SolidPattern");
tr("Dense1Pattern");
tr("Dense2Pattern");
tr("Dense3Pattern");
tr("Dense4Pattern");
tr("Dense5Pattern");
tr("Dense6Pattern");
tr("Dense7Pattern");
tr("HorPattern");
tr("VerPattern");
tr("CrossPattern");
tr("BDiagPattern");
tr("FDiagPattern");
tr("LeftToRight");
tr("RightToLeft");
tr("LayoutDirectionAuto");
tr("LeftItemAlign");
tr("RightItemAlign");
tr("CenterItemAlign");
tr("ParentWidthItemAlign");
tr("DesignedItemAlign");
tr("HorizontalLine");
tr("VerticalLine");
tr("Ellipse");
tr("Rectangle");
tr("Page");
tr("Band");
tr("Horizontal");
tr("Vertical");
tr("VerticalUniform");
2017-12-11 00:29:36 +03:00
tr("Pie");
tr("VerticalBar");
tr("HorizontalBar");
tr("LegendAlignTop");
tr("LegendAlignCenter");
tr("LegendAlignBottom");
tr("TitleAlignLeft");
tr("TitleAlignRight");
tr("TitleAlignCenter");
2018-06-21 14:29:00 +03:00
tr("Layout");
tr("Table");
tr("Millimeters");
tr("Inches");
tr("Scale");
tr("Split");
}
2016-02-17 10:11:00 +03:00
void EnumPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
{
ComboBoxEditor *editor=qobject_cast<ComboBoxEditor *>(propertyEditor);
editor->setTextValue(nameByType(propertyValue().toInt()));
}
void EnumPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
2016-02-17 10:18:19 +03:00
setValueToObject(propertyName(),typeByName(qobject_cast<ComboBoxEditor*>(propertyEditor)->text()));
2016-02-17 10:11:00 +03:00
model->setData(index,object()->property(propertyName().toLatin1()));
}
QString EnumPropItem::nameByType(int value) const
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
return isTranslateProperty() ? tr(propEnum.valueToKey(value)) : propEnum.valueToKey(value);
2016-02-17 10:11:00 +03:00
}
int EnumPropItem::typeByName(const QString &value) const
{
QMetaEnum propEnum = object()->metaObject()->property(object()->metaObject()->indexOfProperty(propertyName().toLatin1())).enumerator();
return propEnum.keyToValue(m_translation.value(value).toLatin1());
2016-02-17 10:11:00 +03:00
}
QString EnumPropItem::displayValue() const
{
return nameByType((propertyValue().toInt()));
}
}