mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-10-01 11:40:02 +03:00
Add axis property dialog
This commit is contained in:
135
limereport/items/lrchartaxiseditor.cpp
Normal file
135
limereport/items/lrchartaxiseditor.cpp
Normal file
@@ -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();
|
||||
}
|
||||
|
41
limereport/items/lrchartaxiseditor.h
Normal file
41
limereport/items/lrchartaxiseditor.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef CHARTAXISEDITOR_H
|
||||
#define CHARTAXISEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#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
|
212
limereport/items/lrchartaxiseditor.ui
Executable file
212
limereport/items/lrchartaxiseditor.ui
Executable file
@@ -0,0 +1,212 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ChartAxisEditor</class>
|
||||
<widget class="QWidget" name="ChartAxisEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>380</width>
|
||||
<height>268</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Axis editor</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gbAxis">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Axis</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="direction_checkbox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reverse direction</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableScaleCalculation_checkbox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable scale calculation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="stepLabel">
|
||||
<property name="text">
|
||||
<string>Step</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="maximumLabel">
|
||||
<property name="text">
|
||||
<string>Maximum</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QDoubleSpinBox" name="minimumSpinBox">
|
||||
<property name="showGroupSeparator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-99999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>99999999.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="minimumLabel">
|
||||
<property name="text">
|
||||
<string>Minimum</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QCheckBox" name="stepCheckBox">
|
||||
<property name="text">
|
||||
<string>Automatic</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="minimumCheckBox">
|
||||
<property name="text">
|
||||
<string>Automatic</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QCheckBox" name="maximumCheckBox">
|
||||
<property name="text">
|
||||
<string>Automatic</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QDoubleSpinBox" name="stepSpinBox">
|
||||
<property name="minimum">
|
||||
<double>-9999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999999.990000000223517</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QDoubleSpinBox" name="maximumSpinBox">
|
||||
<property name="minimum">
|
||||
<double>-9999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>99999999.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonOk">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<slots>
|
||||
<slot>slotAddSeries()</slot>
|
||||
<slot>slotDeleteSeries()</slot>
|
||||
</slots>
|
||||
</ui>
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -209,6 +209,9 @@ public:
|
||||
|
||||
AxisData *xAxisData();
|
||||
AxisData *yAxisData();
|
||||
|
||||
void showAxisEditorDialog(bool isXAxis);
|
||||
|
||||
QList<SeriesItem *> &series();
|
||||
void setSeries(const QList<SeriesItem *> &series);
|
||||
bool isSeriesExists(const QString& name);
|
||||
|
Reference in New Issue
Block a user