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

118 lines
5.8 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 "lrsubitemparentpropitem.h"
2016-02-17 10:11:00 +03:00
#include "../objectinspector/editors/lrcomboboxeditor.h"
#include "lrbasedesignintf.h"
#include "lritemdesignintf.h"
#include "lrobjectpropitem.h"
#include "lrpagedesignintf.h"
2016-02-17 10:11:00 +03:00
namespace {
LimeReport::ObjectPropItem*
createLocationPropItem(QObject* object, LimeReport::ObjectPropItem::ObjectsList* objects,
const QString& name, const QString& displayName, const QVariant& data,
LimeReport::ObjectPropItem* parent, bool readonly)
{
return new LimeReport::ItemLocationPropItem(object, objects, name, displayName, data, parent,
readonly);
2016-02-17 10:11:00 +03:00
}
bool VARIABLE_IS_NOT_USED registred = LimeReport::ObjectPropFactory::instance().registerCreator(
LimeReport::APropIdent("itemLocation", "LimeReport::ItemDesignIntf"),
QObject::tr("itemLocation"), createLocationPropItem);
} // namespace
2016-02-17 10:11:00 +03:00
LimeReport::ItemLocationPropItem::ItemLocationPropItem(QObject* object, ObjectsList* objects,
const QString& name,
const QString& displayName,
const QVariant& value,
ObjectPropItem* parent, bool readonly):
LimeReport::ObjectPropItem(object, objects, name, displayName, value, parent, readonly)
{
m_locationMap.insert(tr("Band"), LimeReport::ItemDesignIntf::Band);
m_locationMap.insert(tr("Page"), LimeReport::ItemDesignIntf::Page);
2016-02-17 10:11:00 +03:00
}
QWidget* LimeReport::ItemLocationPropItem::createProperyEditor(QWidget* parent) const
{
ComboBoxEditor* editor = new ComboBoxEditor(parent);
connect(editor, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotLocationChanged(QString)));
LimeReport::BaseDesignIntf* item = dynamic_cast<LimeReport::BaseDesignIntf*>(object());
if (item) {
2016-02-17 10:11:00 +03:00
QStringList locationTypes;
foreach (QString location, m_locationMap.keys()) {
2016-02-17 10:11:00 +03:00
locationTypes.append(location);
}
editor->addItems(locationTypes);
}
return editor;
}
QString LimeReport::ItemLocationPropItem::displayValue() const
{
return locationToString(
static_cast<LimeReport::ItemDesignIntf::LocationType>(propertyValue().toInt()));
2016-02-17 10:11:00 +03:00
}
void LimeReport::ItemLocationPropItem::setPropertyEditorData(QWidget* propertyEditor,
const QModelIndex&) const
{
ComboBoxEditor* editor = qobject_cast<ComboBoxEditor*>(propertyEditor);
2016-02-17 10:11:00 +03:00
editor->setTextValue(locationToString(propertyValue().toInt()));
}
void LimeReport::ItemLocationPropItem::setModelData(QWidget* propertyEditor,
QAbstractItemModel* model,
const QModelIndex& index)
{
Q_UNUSED(propertyEditor)
model->setData(index, object()->property(propertyName().toLatin1()));
2018-04-24 15:51:06 +03:00
setValueToObject(propertyName(), propertyValue());
2016-02-17 10:11:00 +03:00
}
QString LimeReport::ItemLocationPropItem::locationToString(
LimeReport::ItemDesignIntf::LocationType location) const
{
2016-02-17 10:11:00 +03:00
return m_locationMap.key(location);
}
LimeReport::ItemDesignIntf::LocationType
LimeReport::ItemLocationPropItem::stringToLocation(const QString& locationName)
{
2016-02-17 10:11:00 +03:00
return m_locationMap.value(locationName);
}
void LimeReport::ItemLocationPropItem::slotLocationChanged(const QString& text)
{
if (locationToString(object()->property(propertyName().toLatin1()).toInt()) != text) {
object()->setProperty(propertyName().toLatin1(), stringToLocation(text));
2016-02-17 10:11:00 +03:00
}
}