diff --git a/limereport/designer.pri b/limereport/designer.pri index 13bf6ea..ab07ed6 100644 --- a/limereport/designer.pri +++ b/limereport/designer.pri @@ -30,6 +30,7 @@ SOURCES += \ $$REPORT_PATH/objectinspector/propertyItems/lrcontentpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrmarginpropitem.cpp \ $$REPORT_PATH/objectinspector/propertyItems/lrseriespropitem.cpp \ + $$REPORT_PATH/objectinspector/propertyItems/lraxispropitem.cpp \ $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.cpp \ $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.cpp \ $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.cpp \ @@ -80,6 +81,7 @@ HEADERS += \ $$REPORT_PATH/objectinspector/propertyItems/lrcolorpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrmarginpropitem.h \ $$REPORT_PATH/objectinspector/propertyItems/lrseriespropitem.h \ + $$REPORT_PATH/objectinspector/propertyItems/lraxispropitem.h \ $$REPORT_PATH/objectinspector/editors/lrtextitempropertyeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcomboboxeditor.h \ $$REPORT_PATH/objectinspector/editors/lrcheckboxeditor.h \ diff --git a/limereport/items/lrchartaxiseditor.cpp b/limereport/items/lrchartaxiseditor.cpp new file mode 100644 index 0000000..90b1dbd --- /dev/null +++ b/limereport/items/lrchartaxiseditor.cpp @@ -0,0 +1,135 @@ +#include "lrchartaxiseditor.h" + +#include "ui_lrchartaxiseditor.h" +#include "lraxisdata.h" + +ChartAxisEditor::ChartAxisEditor(LimeReport::ChartItem *item, LimeReport::PageDesignIntf *page, bool isXAxis, QSettings *settings, QWidget *parent): + QWidget(parent), ui(new Ui::ChartAxisEditor), m_chartItem(item), m_page(page), + m_settings(settings), m_isXAxis(isXAxis) +{ + ui->setupUi(this); + readSetting(); + init(); +} + +ChartAxisEditor::~ChartAxisEditor() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) + writeSetting(); +#endif + delete ui; +} + +QSettings* ChartAxisEditor::settings() +{ + if (m_settings){ + return m_settings; + } + m_settings = new QSettings("LimeReport",QCoreApplication::applicationName()); + return m_settings; +} + +void ChartAxisEditor::readSetting() +{ + if (settings() == 0) return; + + settings()->beginGroup("ChartAxisEditor"); + QVariant v = settings()->value("Geometry"); + if (v.isValid()) { + restoreGeometry(v.toByteArray()); + } + + settings()->endGroup(); +} + +void ChartAxisEditor::writeSetting() +{ + if (settings() == 0) { + return; + } + settings()->beginGroup("ChartAxisEditor"); + settings()->setValue("Geometry",saveGeometry()); + settings()->endGroup(); +} + +void ChartAxisEditor::init() +{ + ui->gbAxis->setTitle(m_isXAxis ? QObject::tr("X Axis") : QObject::tr("Y Axis")); + ui->direction_checkbox->setVisible(!m_isXAxis); + + LimeReport::AxisData *axisData = m_isXAxis ? m_chartItem->xAxisData() : m_chartItem->yAxisData(); + + ui->minimumSpinBox->setValue(axisData->rangeMin()); + ui->maximumSpinBox->setValue(axisData->rangeMax()); + ui->stepSpinBox->setValue(axisData->step()); + + ui->minimumCheckBox->setChecked(axisData->isMinimumAutomatic()); + ui->maximumCheckBox->setChecked(axisData->isMaximumAutomatic()); + ui->stepCheckBox->setChecked(axisData->isStepAutomatic()); + + ui->direction_checkbox->setChecked(axisData->reverseDirection()); + + const bool isScaleCalcEnabled = axisData->calculateAxisScale(); + ui->enableScaleCalculation_checkbox->setChecked(isScaleCalcEnabled); + on_enableScaleCalculation_checkbox_stateChanged(isScaleCalcEnabled); +} + +void ChartAxisEditor::on_minimumCheckBox_stateChanged(int arg1) +{ + const bool isAutomatic = (bool)arg1; + ui->minimumSpinBox->setEnabled(!isAutomatic); +} + +void ChartAxisEditor::on_maximumCheckBox_stateChanged(int arg1) +{ + const bool isAutomatic = (bool)arg1; + ui->maximumSpinBox->setEnabled(!isAutomatic); +} + +void ChartAxisEditor::on_stepCheckBox_stateChanged(int arg1) +{ + const bool isAutomatic = (bool)arg1; + ui->stepSpinBox->setEnabled(!isAutomatic); +} + +void ChartAxisEditor::on_pushButtonOk_clicked() +{ + LimeReport::AxisData *axisData = m_isXAxis ? m_chartItem->xAxisData() : m_chartItem->yAxisData(); + if (!m_isXAxis) { + axisData->setReverseDirection(ui->direction_checkbox->isChecked()); + } + + axisData->setIsStepAutomatic(ui->stepCheckBox->isChecked()); + axisData->setManualStep(ui->stepSpinBox->value()); + axisData->setIsMinimumAutomatic(ui->minimumCheckBox->isChecked()); + axisData->setManualMinimum(ui->minimumSpinBox->value()); + axisData->setIsMaximumAutomatic(ui->maximumCheckBox->isChecked()); + axisData->setManualMaximum(ui->maximumSpinBox->value()); + + axisData->setCalculateAxisScale(ui->enableScaleCalculation_checkbox->isChecked()); + + axisData->update(); + close(); +} + +void ChartAxisEditor::on_enableScaleCalculation_checkbox_stateChanged(int arg1) +{ + const bool isEnabled = (bool)arg1; + ui->minimumCheckBox->setEnabled(isEnabled); + ui->maximumCheckBox->setEnabled(isEnabled); + ui->stepCheckBox->setEnabled(isEnabled); + + ui->minimumSpinBox->setEnabled(!ui->minimumCheckBox->isChecked() && isEnabled); + ui->maximumSpinBox->setEnabled(!ui->maximumCheckBox->isChecked() && isEnabled); + ui->stepSpinBox->setEnabled(!ui->stepCheckBox->isChecked() && isEnabled); + + ui->minimumCheckBox->setEnabled(isEnabled); + ui->maximumCheckBox->setEnabled(isEnabled); + ui->stepCheckBox->setEnabled(isEnabled); +} + +void ChartAxisEditor::on_cancelButton_clicked() +{ + close(); +} + diff --git a/limereport/items/lrchartaxiseditor.h b/limereport/items/lrchartaxiseditor.h new file mode 100644 index 0000000..5eeb58b --- /dev/null +++ b/limereport/items/lrchartaxiseditor.h @@ -0,0 +1,41 @@ +#ifndef CHARTAXISEDITOR_H +#define CHARTAXISEDITOR_H + +#include +#include "lrchartitem.h" + +namespace Ui { +class ChartAxisEditor; +} + +class ChartAxisEditor : public QWidget +{ + Q_OBJECT + public: + ChartAxisEditor(LimeReport::ChartItem* item, LimeReport::PageDesignIntf* page, bool isXAxis, + QSettings* settings=0, QWidget *parent = 0); + ~ChartAxisEditor(); + + QSettings *settings(); +private slots: + void on_minimumCheckBox_stateChanged(int arg1); + void on_maximumCheckBox_stateChanged(int arg1); + void on_stepCheckBox_stateChanged(int arg1); + void on_pushButtonOk_clicked(); + void on_enableScaleCalculation_checkbox_stateChanged(int arg1); + + void on_cancelButton_clicked(); + +private: + void readSetting(); + void writeSetting(); + void init(); + + Ui::ChartAxisEditor *ui; + LimeReport::ChartItem* m_chartItem; + LimeReport::PageDesignIntf* m_page; + QSettings* m_settings; + bool m_isXAxis; +}; + +#endif // CHARTAXISEDITOR_H diff --git a/limereport/items/lrchartaxiseditor.ui b/limereport/items/lrchartaxiseditor.ui new file mode 100755 index 0000000..0647ca5 --- /dev/null +++ b/limereport/items/lrchartaxiseditor.ui @@ -0,0 +1,212 @@ + + + ChartAxisEditor + + + + 0 + 0 + 380 + 268 + + + + Axis editor + + + + + + + 0 + 0 + + + + Axis + + + + + + true + + + Reverse direction + + + + + + + true + + + Enable scale calculation + + + + + + + QLayout::SetFixedSize + + + + + Step + + + + + + + Maximum + + + + + + + false + + + -99999999.000000000000000 + + + 99999999.000000000000000 + + + + + + + Minimum + + + + + + + Automatic + + + true + + + + + + + Automatic + + + true + + + + + + + Automatic + + + true + + + + + + + -9999999.000000000000000 + + + 9999999.990000000223517 + + + + + + + -9999999.000000000000000 + + + 99999999.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Ok + + + + + + + + + + + + + slotAddSeries() + slotDeleteSeries() + + \ No newline at end of file diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index 170e6f6..cf0e7d5 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -8,6 +8,7 @@ #include "lrpagedesignintf.h" #include "lrreportengine_p.h" #include "lrdatadesignintf.h" +#include "lrchartaxiseditor.h" #include "charts/lrpiechart.h" #include "charts/lrverticalbarchart.h" @@ -263,6 +264,11 @@ AxisData *ChartItem::yAxisData() return m_yAxisData; } +void ChartItem::showAxisEditorDialog(bool isXAxis) +{ + showDialog(new ChartAxisEditor(this, page(), isXAxis, settings())); +} + BaseDesignIntf *ChartItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent) { ChartItem* result = new ChartItem(owner,parent); @@ -797,25 +803,26 @@ void AbstractSeriesChart::updateMinAndMaxValues() qreal maxXValue = 0; qreal minXValue = 0; if (m_chartItem->itemMode() == DesignMode) { - maxYValue = 40; - maxXValue = 40; - } else { - for (SeriesItem* series : m_chartItem->series()){ - for (qreal value : series->data()->values()){ - minYValue = std::min(minYValue, value); - maxYValue = std::max(maxYValue, value); - } - if (series->data()->xAxisValues().isEmpty()) { - // Grid plot starts from 0 on x axis so x range must be decresed by 1 - const bool startingFromZero = m_chartItem->chartType() == ChartItem::GridLines; - const qreal valuesCount = this->valuesCount() - (startingFromZero ? 1 : 0); - minXValue = std::min(0.0, minXValue); - maxXValue = std::max(valuesCount, maxXValue); - } else { - for (qreal value : series->data()->xAxisValues()){ - minXValue = std::min(value, minXValue); - maxXValue = std::max(value, maxXValue); - } + m_chartItem->xAxisData()->updateForDesignMode(); + m_chartItem->yAxisData()->updateForDesignMode(); + return; + } + + for (SeriesItem* series : m_chartItem->series()){ + for (qreal value : series->data()->values()){ + minYValue = std::min(minYValue, value); + maxYValue = std::max(maxYValue, value); + } + if (series->data()->xAxisValues().isEmpty()) { + // Grid plot starts from 0 on x axis so x range must be decresed by 1 + const bool startingFromZero = m_chartItem->chartType() == ChartItem::GridLines; + const qreal valuesCount = this->valuesCount() - (startingFromZero ? 1 : 0); + minXValue = std::min(0.0, minXValue); + maxXValue = std::max(valuesCount, maxXValue); + } else { + for (qreal value : series->data()->xAxisValues()){ + minXValue = std::min(value, minXValue); + maxXValue = std::max(value, maxXValue); } } } diff --git a/limereport/items/lrchartitem.h b/limereport/items/lrchartitem.h index 076873b..8194f64 100644 --- a/limereport/items/lrchartitem.h +++ b/limereport/items/lrchartitem.h @@ -209,6 +209,9 @@ public: AxisData *xAxisData(); AxisData *yAxisData(); + + void showAxisEditorDialog(bool isXAxis); + QList &series(); void setSeries(const QList &series); bool isSeriesExists(const QString& name); diff --git a/limereport/limereport.pri b/limereport/limereport.pri index 4ed78f6..aca7167 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -47,6 +47,7 @@ SOURCES += \ $$REPORT_PATH/items/lrabstractlayout.cpp \ $$REPORT_PATH/items/lrchartitem.cpp \ $$REPORT_PATH/items/lrchartitemeditor.cpp \ + $$REPORT_PATH/items/lrchartaxiseditor.cpp \ $$REPORT_PATH/items/charts/lrhorizontalbarchart.cpp \ $$REPORT_PATH/items/charts/lrlineschart.cpp \ $$REPORT_PATH/items/charts/lrgridlineschart.cpp \ @@ -131,6 +132,7 @@ HEADERS += \ $$REPORT_PATH/items/lrabstractlayout.h \ $$REPORT_PATH/items/lrchartitem.h \ $$REPORT_PATH/items/lrchartitemeditor.h \ + $$REPORT_PATH/items/lrchartaxiseditor.h \ $$REPORT_PATH/items/charts/lrhorizontalbarchart.h \ $$REPORT_PATH/items/charts/lrlineschart.h \ $$REPORT_PATH/items/charts/lrgridlineschart.h \ @@ -195,6 +197,7 @@ FORMS += \ $$REPORT_PATH/lraboutdialog.ui \ $$REPORT_PATH/lrsettingdialog.ui \ $$REPORT_PATH/items/lrchartitemeditor.ui \ + $$REPORT_PATH/items/lrchartaxiseditor.ui \ $$REPORT_PATH/items/lrimageitemeditor.ui \ $$REPORT_PATH/scripteditor/lrscripteditor.ui diff --git a/limereport/lraxisdata.cpp b/limereport/lraxisdata.cpp index 7b5803b..433f909 100644 --- a/limereport/lraxisdata.cpp +++ b/limereport/lraxisdata.cpp @@ -43,6 +43,16 @@ void AxisData::update(qreal minValue, qreal maxValue) update(); } +void AxisData::updateForDesignMode() +{ + m_minValue = 0; + m_maxValue = 40; + bool tmp = m_calculateAxisScale; + m_calculateAxisScale = false; + update(); + m_calculateAxisScale = tmp; +} + int AxisData::segmentCount() const { return m_segmentCount; diff --git a/limereport/lraxisdata.h b/limereport/lraxisdata.h index 0492b4a..99a8a13 100644 --- a/limereport/lraxisdata.h +++ b/limereport/lraxisdata.h @@ -21,6 +21,7 @@ public: void copy(AxisData *other); void update(); void update(qreal minValue, qreal maxValue); + void updateForDesignMode(); int segmentCount() const; diff --git a/limereport/objectinspector/propertyItems/lraxispropitem.cpp b/limereport/objectinspector/propertyItems/lraxispropitem.cpp new file mode 100644 index 0000000..40466c4 --- /dev/null +++ b/limereport/objectinspector/propertyItems/lraxispropitem.cpp @@ -0,0 +1,57 @@ +#include "lraxispropitem.h" + +#include + +#include +#include +#include + +namespace { +LimeReport::ObjectPropItem * createYAxisPropItem( + QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly) +{ + return new LimeReport::AxisPropItem(object, objects, name, displayName, data, parent, readonly, false); +} + +LimeReport::ObjectPropItem * createXAxisPropItem( + QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly) +{ + return new LimeReport::AxisPropItem(object, objects, name, displayName, data, parent, readonly, true); +} +bool VARIABLE_IS_NOT_USED registredXAxisProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("xAxisSettings", "LimeReport::ChartItem"), QObject::tr("X axis"), createXAxisPropItem); +bool VARIABLE_IS_NOT_USED registredYAxisProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("yAxisSettings", "LimeReport::ChartItem"), QObject::tr("Y axis"), createYAxisPropItem); +} + +namespace LimeReport { + +QWidget *AxisPropItem::createProperyEditor(QWidget *parent) const +{ + return new AxisPropEditor(qobject_cast(object()), m_isXAxis, parent); +} + +QString AxisPropItem::displayValue() const +{ + return QObject::tr("Axis"); +} + +AxisPropEditor::AxisPropEditor(ChartItem *chart, bool isXAxis, QWidget *parent) + : QWidget(parent), m_button(new QPushButton(this)), m_chart(chart), m_isXAxis(isXAxis) +{ + 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 AxisPropEditor::slotButtonClicked() +{ + m_chart->showAxisEditorDialog(m_isXAxis); + emit editingFinished(); +} + +} diff --git a/limereport/objectinspector/propertyItems/lraxispropitem.h b/limereport/objectinspector/propertyItems/lraxispropitem.h new file mode 100644 index 0000000..93fc08d --- /dev/null +++ b/limereport/objectinspector/propertyItems/lraxispropitem.h @@ -0,0 +1,43 @@ +#ifndef AXISPROPITEM_H +#define AXISPROPITEM_H + +#include +#include +#include +#include + + +namespace LimeReport { + +class AxisPropEditor : public QWidget +{ + Q_OBJECT +public: + AxisPropEditor(ChartItem* chart, bool isXAxis, QWidget *parent = 0); +signals: + void editingFinished(); +private slots: + void slotButtonClicked(); +private: + QPushButton* m_button; + ChartItem* m_chart; + bool m_isXAxis; +}; + +class AxisPropItem: public LimeReport::ObjectPropItem +{ + Q_OBJECT +public: + AxisPropItem():ObjectPropItem(){} + AxisPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly, bool isXAxis) + :ObjectPropItem(object, objects, name, displayName, value, parent, readonly), m_isXAxis(isXAxis){} + QWidget* createProperyEditor(QWidget *parent) const; + QString displayValue() const; + +private: + bool m_isXAxis = false; +}; + +} // namespace LimeReport + +#endif // AXISPROPITEM_H