From 85b3c940d418841c448e0e6cff348b88d3e99a1c Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 31 Jan 2020 20:00:28 +0300 Subject: [PATCH] ChartItem: Series property editor has been added --- limereport/base/lrattribsabstractfactory.h | 6 +-- limereport/designer.pri | 2 + limereport/items/lrchartitem.cpp | 2 +- limereport/items/lrchartitem.h | 7 +-- limereport/items/lrchartitemeditor.cpp | 2 +- limereport/items/lrchartitemeditor.h | 4 ++ .../lrobjectinspectorwidget.cpp | 8 ++- .../objectinspector/lrobjectitemmodel.cpp | 10 ++-- .../propertyItems/lrimagepropitem.cpp | 4 +- .../propertyItems/lrseriespropitem.cpp | 51 +++++++++++++++++++ .../propertyItems/lrseriespropitem.h | 41 +++++++++++++++ .../propertyItems/lrstringpropitem.cpp | 2 +- 12 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 limereport/objectinspector/propertyItems/lrseriespropitem.cpp create mode 100644 limereport/objectinspector/propertyItems/lrseriespropitem.h diff --git a/limereport/base/lrattribsabstractfactory.h b/limereport/base/lrattribsabstractfactory.h index d760aa5..3499253 100644 --- a/limereport/base/lrattribsabstractfactory.h +++ b/limereport/base/lrattribsabstractfactory.h @@ -54,11 +54,11 @@ private: friend class Singleton< AttribsAbstractFactory< AbstractProduct,IdentifierType,ProductCreator,Attribs > >; public: bool registerCreator(const IdentifierType& id, Attribs attribs, ProductCreator creator){ - return (m_factoryMap.insert(id,creator).value()==creator)&& - (m_attribsMap.insert(id,attribs).value()==attribs); + return (m_factoryMap.insert(id,creator).value() == creator) && + (m_attribsMap.insert(id,attribs).value() == attribs); } bool unregisterCreator(const IdentifierType& id){ - return (m_factoryMap.remove(id)==1)&&(m_attribsMap.remove(id)==1); + return (m_factoryMap.remove(id) == 1) && (m_attribsMap.remove(id) == 1); } ProductCreator objectCreator(const IdentifierType& id){ if (m_factoryMap.contains(id)){ diff --git a/limereport/designer.pri b/limereport/designer.pri index 1c7e279..deef2d8 100644 --- a/limereport/designer.pri +++ b/limereport/designer.pri @@ -28,6 +28,7 @@ SOURCES += \ $$REPORT_PATH/objectinspector/propertyItems/lrgroupfieldpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrcontentpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrmarginpropitem.cpp \ + $$REPORT_PATH/objectinspector/propertyItems/lrseriespropitem.cpp \ $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.cpp \ $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.cpp \ $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.cpp \ @@ -71,6 +72,7 @@ HEADERS += \ $$REPORT_PATH/objectinspector/propertyItems/lrqrealpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrcolorpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrmarginpropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lrseriespropitem.h \ $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.h \ diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index b80e700..5a366bb 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -251,7 +251,7 @@ QWidget *ChartItem::defaultEditor() QSettings* l_settings = (page()->settings() != 0) ? page()->settings() : (page()->reportEditor()!=0) ? page()->reportEditor()->settings() : 0; - QWidget* editor = new ChartItemEditor(this,page(),l_settings); + QWidget* editor = new ChartItemEditor(this, page(), l_settings); editor->setAttribute(Qt::WA_DeleteOnClose); return editor; } diff --git a/limereport/items/lrchartitem.h b/limereport/items/lrchartitem.h index bd1ca40..8929668 100644 --- a/limereport/items/lrchartitem.h +++ b/limereport/items/lrchartitem.h @@ -117,7 +117,7 @@ class ChartItem : public LimeReport::ItemDesignIntf Q_ENUMS(LegendAlign) Q_ENUMS(TitleAlign) Q_ENUMS(ChartType) - Q_PROPERTY(ACollectionProperty series READ fakeCollectionReader) + Q_PROPERTY(ACollectionProperty series READ fakeCollectionReader WRITE setSeries) Q_PROPERTY(QString datasource READ datasource WRITE setDatasource) Q_PROPERTY(QString chartTitle READ chartTitle WRITE setChartTitle) Q_PROPERTY(bool drawLegendBorder READ drawLegendBorder WRITE setDrawLegendBorder) @@ -163,6 +163,7 @@ public: QList labels() const; void setLabels(const QList &labels); + QWidget* defaultEditor(); protected: void paintChartTitle(QPainter* painter, QRectF titleRect); @@ -173,9 +174,9 @@ protected: QObject* elementAt(const QString& collectionName,int index); void collectionLoadFinished(const QString& collectionName){Q_UNUSED(collectionName)} void updateItemSize(DataSourceManager *dataManager, RenderPass, int); - void fillLabels(IDataSource* dataSource); - QWidget* defaultEditor(); + void fillLabels(IDataSource* dataSource); bool isNeedUpdateSize(RenderPass pass) const; + void setSeries(ACollectionProperty series){Q_UNUSED(series)} private: QList m_series; QString m_datasource; diff --git a/limereport/items/lrchartitemeditor.cpp b/limereport/items/lrchartitemeditor.cpp index f772632..92ea3fb 100644 --- a/limereport/items/lrchartitemeditor.cpp +++ b/limereport/items/lrchartitemeditor.cpp @@ -189,9 +189,9 @@ void ChartItemEditor::on_splitter_splitterMoved(int , int ) #endif } - void ChartItemEditor::on_pbOk_clicked() { + emit editingFinished(); close(); } diff --git a/limereport/items/lrchartitemeditor.h b/limereport/items/lrchartitemeditor.h index a406fc8..f24123f 100644 --- a/limereport/items/lrchartitemeditor.h +++ b/limereport/items/lrchartitemeditor.h @@ -25,6 +25,10 @@ public: protected: void resizeEvent(QResizeEvent *); void moveEvent(QMoveEvent *); + +signals: + void editingFinished(); + private slots: void on_splitter_splitterMoved(int, int); void on_pbOk_clicked(); diff --git a/limereport/objectinspector/lrobjectinspectorwidget.cpp b/limereport/objectinspector/lrobjectinspectorwidget.cpp index 3997e16..1a3be38 100644 --- a/limereport/objectinspector/lrobjectinspectorwidget.cpp +++ b/limereport/objectinspector/lrobjectinspectorwidget.cpp @@ -95,13 +95,17 @@ void ObjectInspectorTreeView::mousePressEvent(QMouseEvent *event) if ((event->button()==Qt::LeftButton)){ QModelIndex index=indexAt(event->pos()); if (index.isValid()){ - if (event->pos().x()pos().x() < indentation()) { if (!nodeFromIndex(index)->isHaveValue()) setExpanded(index,!isExpanded(index)); } else { if ((index.column()==1)&&(!nodeFromIndex(index)->isHaveChildren())) { setCurrentIndex(index); - edit(index); + + Qt::ItemFlags flags = index.model()->flags(index); + if ( !(((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0)) ) + edit(index); + return ; } } diff --git a/limereport/objectinspector/lrobjectitemmodel.cpp b/limereport/objectinspector/lrobjectitemmodel.cpp index eb09d92..0f725db 100644 --- a/limereport/objectinspector/lrobjectitemmodel.cpp +++ b/limereport/objectinspector/lrobjectitemmodel.cpp @@ -363,14 +363,14 @@ QModelIndex QObjectPropertyModel::parent(const QModelIndex &child) const Qt::ItemFlags QObjectPropertyModel::flags(const QModelIndex &index) const { - if ((index.column()==1)&&(!nodeFromIndex(index)->isValueReadonly())) return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + if ((index.column() == 1) && (!nodeFromIndex(index)->isValueReadonly())) return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; else return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } CreatePropItem QObjectPropertyModel::propertyItemCreator(QMetaProperty prop) { - CreatePropItem creator=0; - creator=ObjectPropFactory::instance().objectCreator(APropIdent(prop.name(),prop.enclosingMetaObject()->className())); + CreatePropItem creator = 0; + creator = ObjectPropFactory::instance().objectCreator(APropIdent(prop.name(),prop.enclosingMetaObject()->className())); if (!creator){ if (prop.isFlagType()){ creator=ObjectPropFactory::instance().objectCreator(APropIdent("flags","")); @@ -390,7 +390,7 @@ CreatePropItem QObjectPropertyModel::propertyItemCreator(QMetaProperty prop) return 0; } } - creator=ObjectPropFactory::instance().objectCreator(APropIdent(prop.typeName(),"")); + creator = ObjectPropFactory::instance().objectCreator(APropIdent(prop.typeName(),"")); if (!creator) {qDebug()<<"Editor for propperty name = \""<property(prop.name()), parent, - !(prop.isWritable()&&prop.isDesignable()) + !(prop.isWritable() && prop.isDesignable()) ); } else { propertyItem=new ObjectPropItem( diff --git a/limereport/objectinspector/propertyItems/lrimagepropitem.cpp b/limereport/objectinspector/propertyItems/lrimagepropitem.cpp index c6d324b..e44797d 100644 --- a/limereport/objectinspector/propertyItems/lrimagepropitem.cpp +++ b/limereport/objectinspector/propertyItems/lrimagepropitem.cpp @@ -48,12 +48,12 @@ QWidget* ImagePropItem::createProperyEditor(QWidget *parent) const QString ImagePropItem::displayValue() const { - return (propertyValue().isNull())?"":"Picture"; + return (propertyValue().isNull()) ? "" : QObject::tr("image"); } void ImagePropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const { - ImageEditor *editor =qobject_cast(propertyEditor); + ImageEditor *editor = qobject_cast(propertyEditor); editor->setImage(propertyValue().value()); } diff --git a/limereport/objectinspector/propertyItems/lrseriespropitem.cpp b/limereport/objectinspector/propertyItems/lrseriespropitem.cpp new file mode 100644 index 0000000..3e5b6eb --- /dev/null +++ b/limereport/objectinspector/propertyItems/lrseriespropitem.cpp @@ -0,0 +1,51 @@ +#include "lrseriespropitem.h" + +#include + +#include +#include +#include + +namespace{ +LimeReport::ObjectPropItem * createSeriesPropItem( + QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly) +{ + return new LimeReport::SeriesPropItem(object, objects, name, displayName, data, parent, readonly); +} +bool VARIABLE_IS_NOT_USED registredSeriesProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("series", "LimeReport::ChartItem"), QObject::tr("series"), createSeriesPropItem); +} + +namespace LimeReport { + +QWidget *SeriesPropItem::createProperyEditor(QWidget *parent) const +{ + return new SeriesPropEditor(qobject_cast(object()), parent); +} + +QString SeriesPropItem::displayValue() const +{ + return QObject::tr("Series"); +} + +SeriesPropEditor::SeriesPropEditor(ChartItem *chart, QWidget *parent) + : QWidget(parent), m_button(new QPushButton(this)), m_chart(chart) +{ + m_button->setText("..."); + QHBoxLayout* layout = new QHBoxLayout(this); + layout->addWidget(m_button); + layout->setSpacing(1); + layout->setContentsMargins(1,0,1,1); + setLayout(layout); + setFocusProxy(m_button); + setAutoFillBackground(true); + connect(m_button,SIGNAL(clicked()),this,SLOT(slotButtonClicked())); +} + +void SeriesPropEditor::slotButtonClicked() +{ + m_chart->showEditorDialog(); + emit editingFinished(); +} + + +} diff --git a/limereport/objectinspector/propertyItems/lrseriespropitem.h b/limereport/objectinspector/propertyItems/lrseriespropitem.h new file mode 100644 index 0000000..b7cdb1e --- /dev/null +++ b/limereport/objectinspector/propertyItems/lrseriespropitem.h @@ -0,0 +1,41 @@ +#ifndef SERIESPROPITEM_H +#define SERIESPROPITEM_H + +#include +#include +#include +#include + +namespace LimeReport { + +class SeriesPropEditor : public QWidget +{ + Q_OBJECT +public: + SeriesPropEditor(ChartItem* chart, QWidget *parent = 0); +signals: + void editingFinished(); +private slots: + void slotButtonClicked(); +private: + QPushButton* m_button; + ChartItem* m_chart; +}; + +class SeriesPropItem : public LimeReport::ObjectPropItem{ + Q_OBJECT +public: + SeriesPropItem():ObjectPropItem(){} + SeriesPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly) + :ObjectPropItem(object, objects, name, displayName, value, parent, readonly){} + QWidget* createProperyEditor(QWidget *parent) const; + QString displayValue() const; +}; + +} // namespace LimeReport + + + + + +#endif // SERIESPROPITEM_H diff --git a/limereport/objectinspector/propertyItems/lrstringpropitem.cpp b/limereport/objectinspector/propertyItems/lrstringpropitem.cpp index 8c4c19a..b742c55 100644 --- a/limereport/objectinspector/propertyItems/lrstringpropitem.cpp +++ b/limereport/objectinspector/propertyItems/lrstringpropitem.cpp @@ -54,7 +54,7 @@ QWidget * StringPropItem::createProperyEditor(QWidget *parent) const void StringPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const { - ButtonLineEditor *editor =qobject_cast(propertyEditor); + ButtonLineEditor *editor = qobject_cast(propertyEditor); editor->setText(propertyValue().toString()); }