diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h --- a/src/common/KReportItemBase.h +++ b/src/common/KReportItemBase.h @@ -83,10 +83,11 @@ virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script); /** - @brief Override if the item supports a simple data source, such as a field @return The field name or expression for the data source */ - virtual QString itemDataSource() const; + QString itemDataSource() const; + + void setItemDataSource(const QString &source); /** @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report @@ -153,13 +154,15 @@ protected: virtual void createProperties() = 0; + void createDataSourceProperty(); bool parseReportRect(const QDomElement &elem); static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*); static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*); KProperty *nameProperty(); QString oldName() const; void setOldName(const QString &old); + KProperty* dataSourceProperty(); Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p); @@ -169,6 +172,7 @@ Private * const d; Q_SLOT void aboutToDeleteProperty(KPropertySet& set, KProperty& property); + friend class KReportDesignerItemRectBase; }; #endif diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -21,6 +21,7 @@ #include "KReportUtils_p.h" #include +#include #include #include @@ -62,6 +63,7 @@ KProperty *nameProperty; KProperty *sizeProperty; KProperty *positionProperty; + KProperty *dataSourceProperty = 0; QString oldName; qreal z = 0; KReportUnit unit; @@ -101,6 +103,17 @@ delete d; } +void KReportItemBase::createDataSourceProperty() +{ + if (d->dataSourceProperty) { + return; + } + d->dataSourceProperty + = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); + d->dataSourceProperty->setOption("extraValueAllowed", true); + d->set->addProperty(d->dataSourceProperty); +} + bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts) { return KReportUtils::parseReportTextStyleData(elemSource, ts); @@ -154,7 +167,14 @@ QString KReportItemBase::itemDataSource() const { - return QString(); + return d->dataSourceProperty ? d->dataSourceProperty->value().toString() : QString(); +} + +void KReportItemBase::setItemDataSource(const QString& source) +{ + if (d->dataSourceProperty && d->dataSourceProperty->value() != source) { + d->dataSourceProperty->setValue(source); + } } KPropertySet* KReportItemBase::propertySet() @@ -192,6 +212,11 @@ d->oldName = old; } +KProperty* KReportItemBase::dataSourceProperty() +{ + return d->dataSourceProperty; +} + QPointF KReportItemBase::position() const { return d->unit.convertToPoint(d->positionProperty->value().toPointF()); diff --git a/src/items/check/KReportDesignerItemCheckBox.h b/src/items/check/KReportDesignerItemCheckBox.h --- a/src/items/check/KReportDesignerItemCheckBox.h +++ b/src/items/check/KReportDesignerItemCheckBox.h @@ -49,9 +49,6 @@ private Q_SLOTS: void slotPropertyChanged(KPropertySet &, KProperty &); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; }; #endif // KREPORTDESIGNERITEMCHECK_H diff --git a/src/items/check/KReportDesignerItemCheckBox.cpp b/src/items/check/KReportDesignerItemCheckBox.cpp --- a/src/items/check/KReportDesignerItemCheckBox.cpp +++ b/src/items/check/KReportDesignerItemCheckBox.cpp @@ -145,7 +145,7 @@ //properties addPropertyAsAttribute(&entity, nameProperty()); - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString()); addPropertyAsAttribute(&entity, m_checkStyle); addPropertyAsAttribute(&entity, m_staticValue); @@ -175,9 +175,3 @@ KReportDesignerItemRectBase::propertyChanged(s, p); if (designer()) designer()->setModified(true); } - -void KReportDesignerItemCheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} diff --git a/src/items/check/KReportItemCheck.h b/src/items/check/KReportItemCheck.h --- a/src/items/check/KReportItemCheck.h +++ b/src/items/check/KReportItemCheck.h @@ -38,11 +38,7 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource()const override; - protected: - - KProperty * m_controlSource; KProperty* m_checkStyle; KProperty* m_foregroundColor; KProperty* m_lineColor; diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -39,7 +39,7 @@ : KReportItemCheckBox() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(KReportUtils::readZAttribute(element.toElement())); m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color")))); m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style"))); @@ -79,9 +79,7 @@ QVariantList{ tr("Cross"), tr("Tick"), tr("Dot") }); m_checkStyle = new KProperty("check-style", listData, QLatin1String("Cross"), tr("Style")); - m_controlSource - = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); - m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); + createDataSourceProperty(); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); @@ -91,7 +89,6 @@ m_lineStyle = new KProperty("line-style", static_cast(Qt::SolidLine), tr("Line Style"), QString(), KProperty::LineStyle); m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field")); - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_staticValue); propertySet()->addProperty(m_checkStyle); propertySet()->addProperty(m_foregroundColor); @@ -109,11 +106,6 @@ return ls; } -QString KReportItemCheckBox::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - // RTTI QString KReportItemCheckBox::typeName() const { diff --git a/src/items/field/KReportDesignerItemField.h b/src/items/field/KReportDesignerItemField.h --- a/src/items/field/KReportDesignerItemField.h +++ b/src/items/field/KReportDesignerItemField.h @@ -42,9 +42,6 @@ void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget = nullptr) override; KReportDesignerItemField* clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - private: void init(QGraphicsScene *scene); QRectF getTextRect() const; diff --git a/src/items/field/KReportDesignerItemField.cpp b/src/items/field/KReportDesignerItemField.cpp --- a/src/items/field/KReportDesignerItemField.cpp +++ b/src/items/field/KReportDesignerItemField.cpp @@ -39,9 +39,10 @@ connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); + dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); setZValue(z()); - updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); + updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("field")); } // methods (constructors) @@ -126,7 +127,7 @@ // properties addPropertyAsAttribute(&entity, nameProperty()); - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); addPropertyAsAttribute(&entity, m_wordWrap); @@ -173,17 +174,8 @@ } } - updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); + updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("field")); KReportDesignerItemRectBase::propertyChanged(s, p); if (designer())designer()->setModified(true); } - -void KReportDesignerItemField::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - //kreportpluginDebug() << m_reportDesigner->fieldKeys() << m_reportDesigner->fieldNames(); - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} - - diff --git a/src/items/field/KReportItemField.h b/src/items/field/KReportItemField.h --- a/src/items/field/KReportItemField.h +++ b/src/items/field/KReportItemField.h @@ -40,11 +40,7 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; - protected: - - KProperty * m_controlSource; KProperty * m_horizontalAlignment; KProperty * m_verticalAlignment; KProperty * m_font; @@ -76,8 +72,6 @@ return m_font->value().value(); } - void setItemDataSource(const QString&); - private: void createProperties() override; diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -40,7 +40,7 @@ : KReportItemField() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); @@ -86,8 +86,7 @@ void KReportItemField::createProperties() { - m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); - m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); + createDataSourceProperty(); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); @@ -129,7 +128,6 @@ _trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format")); #endif - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); @@ -186,19 +184,6 @@ return d; } -QString KReportItemField::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - -void KReportItemField::setItemDataSource(const QString& t) -{ - if (m_controlSource->value() != t) { - m_controlSource->setValue(t); - } - //kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource(); -} - KReportLineStyle KReportItemField::lineStyle() const { KReportLineStyle ls; @@ -243,13 +228,9 @@ #else Q_UNUSED(script); #endif - if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string - str = ids.mid(1); - } else { - str = data.toString(); - } + str = data.toString(); } else { - str = m_itemValue->value().toString(); + str = m_itemValue->value().toString(); } tb->setText(str); diff --git a/src/items/field/KReportScriptField.h b/src/items/field/KReportScriptField.h --- a/src/items/field/KReportScriptField.h +++ b/src/items/field/KReportScriptField.h @@ -44,13 +44,13 @@ public Q_SLOTS: - //! @return the source (column) that the field gets its data from* + //! @return the data source for the field element + //! The source can be a column name or a valid script expression if prefixed with a '='. QString source() const; - //! Sets the source (column) for the field. - //! Valid values include a column name, fixed string if prefixed with '$' - //! or a valid script expression if prefixed with a '=' - void setSource(const QString&); + //! Sets the data source for the field element. + //! @see source() + void setSource(const QString &s); //! @return the horizontal alignment as an integer //! Valid values are left: -1, center: 0, right; 1 diff --git a/src/items/image/KReportDesignerItemImage.h b/src/items/image/KReportDesignerItemImage.h --- a/src/items/image/KReportDesignerItemImage.h +++ b/src/items/image/KReportDesignerItemImage.h @@ -38,9 +38,6 @@ QWidget *widget = nullptr) override; KReportDesignerItemImage *clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - private: void init(QGraphicsScene *scene); diff --git a/src/items/image/KReportDesignerItemImage.cpp b/src/items/image/KReportDesignerItemImage.cpp --- a/src/items/image/KReportDesignerItemImage.cpp +++ b/src/items/image/KReportDesignerItemImage.cpp @@ -40,7 +40,7 @@ connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); setZValue(z()); } @@ -122,7 +122,7 @@ map.appendChild(doc->createTextNode(QLatin1String(inlineImageData()))); entity.appendChild(map); } else { - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); } parent->appendChild(entity); @@ -142,9 +142,3 @@ KReportDesignerItemRectBase::propertyChanged(s, p); if (designer()) designer()->setModified(true); } - -void KReportDesignerItemImage::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} diff --git a/src/items/image/KReportItemImage.h b/src/items/image/KReportItemImage.h --- a/src/items/image/KReportItemImage.h +++ b/src/items/image/KReportItemImage.h @@ -39,16 +39,12 @@ int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; - protected: - KProperty * m_controlSource; KProperty* m_resizeMode; KProperty* m_staticImage; void setMode(const QString&); void setInlineImageData(const QByteArray &dat, const QString& = QString()); - void setColumn(const QString&); QString mode() const; bool isInline() const; QByteArray inlineImageData() const; diff --git a/src/items/image/KReportItemImage.cpp b/src/items/image/KReportItemImage.cpp --- a/src/items/image/KReportItemImage.cpp +++ b/src/items/image/KReportItemImage.cpp @@ -36,7 +36,7 @@ : KReportItemImage() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_resizeMode->setValue(element.toElement().attribute(QLatin1String("report:resize-mode"), QLatin1String("stretch"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); @@ -112,30 +112,18 @@ void KReportItemImage::createProperties() { - m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); + createDataSourceProperty(); KPropertyListData *listData = new KPropertyListData( { QLatin1String("clip"), QLatin1String("stretch") }, QVariantList{ tr("Clip"), tr("Stretch") }); m_resizeMode = new KProperty("resize-mode", listData, QLatin1String("clip"), tr("Resize Mode")); m_staticImage = new KProperty("static-image", QPixmap(), tr("Value"), tr("Value used if not bound to a field")); - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_resizeMode); propertySet()->addProperty(m_staticImage); } - -void KReportItemImage::setColumn(const QString &c) -{ - m_controlSource->setValue(c); -} - -QString KReportItemImage::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - QString KReportItemImage::typeName() const { return QLatin1String("image"); diff --git a/src/items/image/KReportScriptImage.h b/src/items/image/KReportScriptImage.h --- a/src/items/image/KReportScriptImage.h +++ b/src/items/image/KReportScriptImage.h @@ -89,10 +89,10 @@ /** * Get the data from a file (expected to be an image) * the returned data will be base64 encoded - * @param Path location of file - * @return File data enoded in base64 + * @param path location of file */ - void loadFromFile(const QVariant &); + void loadFromFile(const QVariant &path); + private: KReportItemImage *m_image; diff --git a/src/items/image/KReportScriptImage.cpp b/src/items/image/KReportScriptImage.cpp --- a/src/items/image/KReportScriptImage.cpp +++ b/src/items/image/KReportScriptImage.cpp @@ -70,9 +70,9 @@ m_image->setInlineImageData(ba); } -void Image::loadFromFile(const QVariant &pth) +void Image::loadFromFile(const QVariant &path) { - QString str = pth.toString(); + QString str = path.toString(); m_image->setInlineImageData(QByteArray(), str); } } diff --git a/src/items/text/KReportDesignerItemText.h b/src/items/text/KReportDesignerItemText.h --- a/src/items/text/KReportDesignerItemText.h +++ b/src/items/text/KReportDesignerItemText.h @@ -41,9 +41,6 @@ void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; KReportDesignerItemText* clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - private: QRectF getTextRect() const; void init(QGraphicsScene *scene); diff --git a/src/items/text/KReportDesignerItemText.cpp b/src/items/text/KReportDesignerItemText.cpp --- a/src/items/text/KReportDesignerItemText.cpp +++ b/src/items/text/KReportDesignerItemText.cpp @@ -42,10 +42,10 @@ connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); setZValue(z()); - updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), + updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("textarea")); } @@ -128,7 +128,7 @@ // properties addPropertyAsAttribute(&entity, nameProperty()); - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); entity.setAttribute(QLatin1String("report:bottom-padding"), m_bottomPadding); @@ -147,13 +147,6 @@ parent->appendChild(entity); } -void KReportDesignerItemText::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} - - void KReportDesignerItemText::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); @@ -172,6 +165,6 @@ designer()->setModified(true); } - updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), + updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("textarea")); } diff --git a/src/items/text/KReportItemText.h b/src/items/text/KReportItemText.h --- a/src/items/text/KReportItemText.h +++ b/src/items/text/KReportItemText.h @@ -42,11 +42,7 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; - protected: - - KProperty* m_controlSource; KProperty* m_horizontalAlignment; KProperty* m_verticalAlignment; KProperty* m_font; diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -40,7 +40,7 @@ : KReportItemText() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); @@ -108,10 +108,7 @@ void KReportItemText::createProperties() { - //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); - - //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); - m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); + createDataSourceProperty(); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); @@ -141,7 +138,6 @@ m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("suffix", QLatin1String("%")); - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); @@ -155,11 +151,6 @@ } -QString KReportItemText::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - qreal KReportItemText::bottomPadding() const { return m_bottomPadding; @@ -208,11 +199,7 @@ QString cs = itemDataSource(); if (!cs.isEmpty()) { - if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string - qstrValue = cs.mid(1); - } else { - qstrValue = data.toString(); - } + qstrValue = data.toString(); } else { qstrValue = m_itemValue->value().toString(); } diff --git a/src/items/text/KReportScriptText.h b/src/items/text/KReportScriptText.h --- a/src/items/text/KReportScriptText.h +++ b/src/items/text/KReportScriptText.h @@ -38,13 +38,13 @@ ~Text() override; public Q_SLOTS: - //! @return the source (column) that the text-item gets its data from* + //! @return the data source for the text element + //! The source can be a column name or a valid script expression if prefixed with a '='. QString source() const; - //! Sets the source (column) for the text-item. - //! Valid values include a column name, fixed string if prefixed with '$' - //! or a valid script expression if prefixed with a '=' - void setSource(const QString&); + //! Sets the data source for the text element. + //! @see source() + void setSource(const QString &s); //! @return the horizontal alignment as an integer //! Valid values are left: -1, center: 0, right; 1 @@ -111,8 +111,8 @@ //! Sets the size of the text-item to the given size in points void setSize(const QSizeF&); - //!Load the contets for the text item from the given file - void loadFromFile(const QString& fileName); + //!Load the contents for the text item from the given file + bool loadFromFile(const QString& fileName); private: KReportItemText *m_text; }; diff --git a/src/items/text/KReportScriptText.cpp b/src/items/text/KReportScriptText.cpp --- a/src/items/text/KReportScriptText.cpp +++ b/src/items/text/KReportScriptText.cpp @@ -43,7 +43,7 @@ void Text::setSource(const QString& s) { - m_text->m_controlSource->setValue(s); + m_text->setItemDataSource(s); } int Text::horizontalAlignment() const @@ -187,22 +187,23 @@ m_text->setSize(s); } -void Text::loadFromFile(const QString &fn) +bool Text::loadFromFile(const QString &fileName) { - QFile file(fn); + QFile file(fileName); //kreportpluginDebug() << "Loading from" << fn; if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - m_text->m_controlSource->setValue(tr("$Unable to read %1").arg(fn)); - return; + kreportpluginWarning() << "Failed to load value for text element from file" << fileName; + return false; } QTextStream in(&file); QString data = in.readAll(); /* while (!in.atEnd()) { QString line = in.readLine(); process_line(line); }*/ - m_text->m_controlSource->setValue(QVariant(QLatin1String("$") + data)); + m_text->m_itemValue->setValue(data); + return true; } } diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.h b/src/plugins/barcode/KReportDesignerItemBarcode.h --- a/src/plugins/barcode/KReportDesignerItemBarcode.h +++ b/src/plugins/barcode/KReportDesignerItemBarcode.h @@ -44,9 +44,6 @@ KReportDesignerItemBarcode *clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - private: void init(QGraphicsScene *scene); diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.cpp b/src/plugins/barcode/KReportDesignerItemBarcode.cpp --- a/src/plugins/barcode/KReportDesignerItemBarcode.cpp +++ b/src/plugins/barcode/KReportDesignerItemBarcode.cpp @@ -136,7 +136,7 @@ // properties addPropertyAsAttribute(&entity, nameProperty()); - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, m_horizontalAlignment); addPropertyAsAttribute(&entity, m_format); addPropertyAsAttribute(&entity, m_maxLength); @@ -165,9 +165,3 @@ KReportDesignerItemRectBase::propertyChanged(s, p); if (designer()) designer()->setModified(true); } - -void KReportDesignerItemBarcode::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} diff --git a/src/plugins/barcode/KReportItemBarcode.h b/src/plugins/barcode/KReportItemBarcode.h --- a/src/plugins/barcode/KReportItemBarcode.h +++ b/src/plugins/barcode/KReportItemBarcode.h @@ -39,11 +39,8 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; protected: - - KProperty * m_controlSource; KProperty * m_horizontalAlignment; KProperty * m_format; KProperty * m_maxLength; diff --git a/src/plugins/barcode/KReportItemBarcode.cpp b/src/plugins/barcode/KReportItemBarcode.cpp --- a/src/plugins/barcode/KReportItemBarcode.cpp +++ b/src/plugins/barcode/KReportItemBarcode.cpp @@ -38,7 +38,7 @@ : KReportItemBarcode() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); @@ -115,8 +115,7 @@ void KReportItemBarcode::createProperties() { - m_controlSource - = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); + createDataSourceProperty(); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); @@ -148,7 +147,6 @@ m_maxLength = new KProperty("barcode-max-length", 5, tr("Max Length"), tr("Maximum Barcode Length")); - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_format); propertySet()->addProperty(m_horizontalAlignment); @@ -165,11 +163,6 @@ Qt::AlignLeft); } -QString KReportItemBarcode::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - QString KReportItemBarcode::format() const { return m_format->value().toString(); @@ -210,7 +203,7 @@ QString val; - if (m_controlSource->value().toString().isEmpty()) { + if (itemDataSource().isEmpty()) { val = m_itemValue->value().toString(); } else { val = data.toString(); diff --git a/src/plugins/barcode/KReportScriptBarcode.h b/src/plugins/barcode/KReportScriptBarcode.h --- a/src/plugins/barcode/KReportScriptBarcode.h +++ b/src/plugins/barcode/KReportScriptBarcode.h @@ -79,24 +79,24 @@ /** - * Get the control source (field name) of the barcode - * @return control source + * @return the data source for the element + * The source can be a column name or a valid script expression if prefixed with a '='. */ - QString source(); + QString source() const; /** - * Set the control source (field name) of the barcode - * @param controlsource + * Sets the data source for the element. + * @see source() */ - void setSource(const QString&); + void setSource(const QString &s); /** * Get the barcode format * @return format as string */ - QString format(); + QString format() const; /** * Set the barcode format diff --git a/src/plugins/barcode/KReportScriptBarcode.cpp b/src/plugins/barcode/KReportScriptBarcode.cpp --- a/src/plugins/barcode/KReportScriptBarcode.cpp +++ b/src/plugins/barcode/KReportScriptBarcode.cpp @@ -63,17 +63,17 @@ m_barcode->setHorizontalAlignment(value); } -QString Barcode::source() +QString Barcode::source() const { - return m_barcode->m_controlSource->value().toString(); + return m_barcode->itemDataSource(); } void Barcode::setSource(const QString& s) { - m_barcode->m_controlSource->setValue(s); + m_barcode->setItemDataSource(s); } -QString Barcode::format() +QString Barcode::format() const { return m_barcode->m_format->value().toString(); } diff --git a/src/plugins/chart/KReportDesignerItemChart.cpp b/src/plugins/chart/KReportDesignerItemChart.cpp --- a/src/plugins/chart/KReportDesignerItemChart.cpp +++ b/src/plugins/chart/KReportDesignerItemChart.cpp @@ -87,7 +87,7 @@ painter->setBackground(bg); painter->setPen(Qt::black); - painter->drawText(rect(), 0, dataSourceAndObjectTypeName(m_dataSource->value().toString(), "chart")); + painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), "chart")); painter->setPen(QPen(QColor(224, 224, 224))); painter->drawRect(rect()); painter->setBackgroundMode(Qt::TransparentMode); @@ -114,8 +114,8 @@ QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_name); - addPropertyAsAttribute(&entity, m_dataSource); + addPropertyAsAttribute(&entity, nameProperty()); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, m_chartType); addPropertyAsAttribute(&entity, m_chartSubType); addPropertyAsAttribute(&entity, m_threeD); @@ -190,7 +190,7 @@ if (m_reportDesigner->reportData()) { QStringList ql = m_reportDesigner->reportData()->dataSources(); QStringList qn = m_reportDesigner->reportData()->dataSourceNames(); - m_dataSource->setListData(ql, qn); + dataSourceProperty()->setListData(ql, qn); } KoReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/plugins/chart/KReportItemChart.h b/src/plugins/chart/KReportItemChart.h --- a/src/plugins/chart/KReportItemChart.h +++ b/src/plugins/chart/KReportItemChart.h @@ -73,8 +73,6 @@ virtual bool supportsSubQuery() const { return true; } protected: - - KProperty * m_dataSource; KProperty * m_font; KProperty * m_chartType; KProperty * m_chartSubType; diff --git a/src/plugins/chart/KReportItemChart.cpp b/src/plugins/chart/KReportItemChart.cpp --- a/src/plugins/chart/KReportItemChart.cpp +++ b/src/plugins/chart/KReportItemChart.cpp @@ -53,7 +53,7 @@ { QDomElement e = element->toElement(); m_name->setValue(KReportUtils::readNameAttribute(e)); - m_dataSource->setValue(e.attribute("report:data-source")); + setItemDataSource(e.attribute("report:item-data-source")); Z = e.attribute("report:z-index").toDouble(); m_chartType->setValue(e.attribute("report:chart-type").toInt()); m_chartSubType->setValue(e.attribute("report:chart-sub-type").toInt()); @@ -84,17 +84,13 @@ m_chartWidget = 0; m_set = new KPropertySet; - QStringList strings; - QList keys; - QStringList stringkeys; - - m_dataSource = new KProperty("data-source", QStringList(), QStringList(), QString(), tr("Data Source")); - - m_dataSource->setOption("extraValueAllowed", "true"); + createDataSourceProperty(); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Field Font")); + QList keys; keys << 1 << 2 << 3 << 4 << 5; + QStringList strings; strings << tr("Bar") << tr("Line") << tr("Pie") << tr("Ring") << tr("Polar"); KProperty::ListData *typeData = new KProperty::ListData(keys, strings); m_chartType = new KProperty("chart-type", typeData, 1, tr("Chart Type")); @@ -110,6 +106,7 @@ keys.clear(); strings.clear(); + QStringList stringkeys; stringkeys << "default" << "rainbow" << "subdued"; strings << tr("Default") << tr("Rainbow") << tr("Subdued"); m_colorScheme = new KProperty("chart-color-scheme", stringkeys, strings, "default", tr("Color Scheme")); @@ -152,7 +149,6 @@ tr("Fields from child data source")); addDefaultProperties(); - m_set->addProperty(m_dataSource); m_set->addProperty(m_chartType); m_set->addProperty(m_chartSubType); m_set->addProperty(m_font); @@ -226,7 +222,7 @@ m_chartWidget = 0; if (m_reportData) { - QString src = m_dataSource->value().toString(); + QString src = itemDataSource(); if (!src.isEmpty()) { KReportData *curs = m_reportData->create(src); diff --git a/src/plugins/chart/KReportScriptChart.cpp b/src/plugins/chart/KReportScriptChart.cpp --- a/src/plugins/chart/KReportScriptChart.cpp +++ b/src/plugins/chart/KReportScriptChart.cpp @@ -51,12 +51,12 @@ QString Chart::dataSource() { - return m_chart->m_dataSource->value().toString(); + return m_chart->itemDataSource(); } void Chart::setDataSource(const QString &ds) { - m_chart->m_dataSource->setValue(ds); + m_chart->setItemDataSource(ds); } bool Chart::threeD() diff --git a/src/plugins/maps/KReportDesignerItemMaps.h b/src/plugins/maps/KReportDesignerItemMaps.h --- a/src/plugins/maps/KReportDesignerItemMaps.h +++ b/src/plugins/maps/KReportDesignerItemMaps.h @@ -40,9 +40,6 @@ QWidget *widget = nullptr) override; KReportDesignerItemMaps *clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event) override; - private: void init(QGraphicsScene *scene); diff --git a/src/plugins/maps/KReportDesignerItemMaps.cpp b/src/plugins/maps/KReportDesignerItemMaps.cpp --- a/src/plugins/maps/KReportDesignerItemMaps.cpp +++ b/src/plugins/maps/KReportDesignerItemMaps.cpp @@ -37,7 +37,7 @@ connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); + dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); setZValue(z()); } @@ -98,7 +98,7 @@ // properties addPropertyAsAttribute(&entity, nameProperty()); - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, m_latitudeProperty); addPropertyAsAttribute(&entity, m_longitudeProperty); addPropertyAsAttribute(&entity, m_zoomProperty); @@ -125,9 +125,3 @@ KReportDesignerItemRectBase::propertyChanged(s, p); if (designer()) designer()->setModified(true); } - -void KReportDesignerItemMaps::mousePressEvent(QGraphicsSceneMouseEvent * event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} diff --git a/src/plugins/maps/KReportItemMaps.h b/src/plugins/maps/KReportItemMaps.h --- a/src/plugins/maps/KReportItemMaps.h +++ b/src/plugins/maps/KReportItemMaps.h @@ -51,7 +51,6 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; QVariant realItemData(const QVariant &itemData) const override; void renderFinished(); @@ -64,14 +63,11 @@ OROPicture* oroImage(); protected: - KProperty* m_controlSource; KProperty* m_latitudeProperty; KProperty* m_longitudeProperty; KProperty* m_zoomProperty; KProperty* m_themeProperty; - void setColumn(const QString&); - qreal m_longtitude = 0.0; qreal m_latitude = 0.0; int m_zoom = 1200; diff --git a/src/plugins/maps/KReportItemMaps.cpp b/src/plugins/maps/KReportItemMaps.cpp --- a/src/plugins/maps/KReportItemMaps.cpp +++ b/src/plugins/maps/KReportItemMaps.cpp @@ -38,7 +38,7 @@ : KReportItemMaps() { nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement())); - m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_latitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:latitude")).toDouble()); m_longitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:longitude")).toDouble()); @@ -56,7 +56,7 @@ void KReportItemMaps::createProperties() { - m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); + createDataSourceProperty(); m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), QString(), KProperty::Double); m_latitudeProperty->setOption("min", -90); @@ -86,24 +86,12 @@ KProperty::ValueOption::IgnoreOld); } - propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_latitudeProperty); propertySet()->addProperty(m_longitudeProperty); propertySet()->addProperty(m_zoomProperty); propertySet()->addProperty(m_themeProperty); } - -void KReportItemMaps::setColumn(const QString &c) -{ - m_controlSource->setValue(c); -} - -QString KReportItemMaps::itemDataSource() const -{ - return m_controlSource->value().toString(); -} - QString KReportItemMaps::typeName() const { return QLatin1String("maps"); diff --git a/src/plugins/web/KReportDesignerItemWeb.h b/src/plugins/web/KReportDesignerItemWeb.h --- a/src/plugins/web/KReportDesignerItemWeb.h +++ b/src/plugins/web/KReportDesignerItemWeb.h @@ -40,9 +40,6 @@ void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; KReportDesignerItemWeb *clone() override; -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - private: void init(QGraphicsScene *scene); diff --git a/src/plugins/web/KReportDesignerItemWeb.cpp b/src/plugins/web/KReportDesignerItemWeb.cpp --- a/src/plugins/web/KReportDesignerItemWeb.cpp +++ b/src/plugins/web/KReportDesignerItemWeb.cpp @@ -93,7 +93,7 @@ QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties - addPropertyAsAttribute(&entity, m_controlSource); + addPropertyAsAttribute(&entity, dataSourceProperty()); addPropertyAsAttribute(&entity, nameProperty()); entity.setAttribute(QLatin1String("report:z-index"), zValue()); buildXMLRect(doc, &entity, this); @@ -116,9 +116,3 @@ designer()->setModified(true); } } - -void KReportDesignerItemWeb::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); - KReportDesignerItemRectBase::mousePressEvent(event); -} diff --git a/src/plugins/web/KReportItemWeb.h b/src/plugins/web/KReportItemWeb.h --- a/src/plugins/web/KReportItemWeb.h +++ b/src/plugins/web/KReportItemWeb.h @@ -48,7 +48,6 @@ QString typeName() const override; int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override; - QString itemDataSource() const override; private Q_SLOTS: void loadFinished(bool); @@ -62,7 +61,6 @@ protected: void createProperties() override; - KProperty *m_controlSource; QWebPage *m_webPage; friend class Scripting::Web; diff --git a/src/plugins/web/KReportItemWeb.cpp b/src/plugins/web/KReportItemWeb.cpp --- a/src/plugins/web/KReportItemWeb.cpp +++ b/src/plugins/web/KReportItemWeb.cpp @@ -45,7 +45,7 @@ { QDomElement e = element.toElement(); - m_controlSource->setValue(e.attribute(QLatin1String("report:item-data-source"))); + setItemDataSource(e.attribute(QLatin1String("report:item-data-source"))); nameProperty()->setValue(KReportUtils::readNameAttribute(e)); setZ(e.attribute(QLatin1String("report:z-index")).toDouble()); parseReportRect(e); @@ -60,9 +60,7 @@ void KReportItemWeb::createProperties() { - m_controlSource - = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source")); - propertySet()->addProperty(m_controlSource); + createDataSourceProperty(); } KReportItemWeb::~KReportItemWeb() @@ -131,8 +129,3 @@ return 0; //Item doesn't stretch the section height } - -QString KReportItemWeb::itemDataSource() const -{ - return m_controlSource->value().toString(); -} diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -92,6 +92,9 @@ void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) { //Update and show properties + if (item()->dataSourceProperty()) { + item()->dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); + } item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); designer()->changeSet(item()->propertySet()); setSelected(true);