"Fossies" - the Fresh Open Source Software Archive

Member "labplot-2.8.2/src/kdefrontend/dockwidgets/HistogramDock.cpp" (24 Feb 2021, 65229 Bytes) of package /linux/privat/labplot-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "HistogramDock.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 /***************************************************************************
    2     File                 : HistogramDock.cpp
    3     Project              : LabPlot
    4     Description          : widget for Histogram properties
    5     --------------------------------------------------------------------
    6     Copyright            : (C) 2016 Anu Mittal (anu22mittal@gmail.com)
    7     Copyright            : (C) 2018-2021 by Alexander Semke (alexander.semke@web.de)
    8 
    9  ***************************************************************************/
   10 
   11 /***************************************************************************
   12  *                                                                         *
   13  *  This program is free software; you can redistribute it and/or modify   *
   14  *  it under the terms of the GNU General Public License as published by   *
   15  *  the Free Software Foundation; either version 2 of the License, or      *
   16  *  (at your option) any later version.                                    *
   17  *                                                                         *
   18  *  This program is distributed in the hope that it will be useful,        *
   19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   21  *  GNU General Public License for more details.                           *
   22  *                                                                         *
   23  *   You should have received a copy of the GNU General Public License     *
   24  *   along with this program; if not, write to the Free Software           *
   25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   26  *   Boston, MA  02110-1301  USA                                           *
   27  *                                                                         *
   28  ***************************************************************************/
   29 
   30 #include "HistogramDock.h"
   31 #include "backend/worksheet/plots/cartesian/Histogram.h"
   32 #include "backend/worksheet/Worksheet.h"
   33 #include "backend/worksheet/plots/cartesian/Symbol.h"
   34 #include "backend/core/AspectTreeModel.h"
   35 #include "backend/core/column/Column.h"
   36 #include "backend/core/Project.h"
   37 #include "backend/core/datatypes/Double2StringFilter.h"
   38 #include "backend/core/datatypes/DateTime2StringFilter.h"
   39 #include "commonfrontend/widgets/TreeViewComboBox.h"
   40 #include "kdefrontend/TemplateHandler.h"
   41 #include "kdefrontend/GuiTools.h"
   42 
   43 #include <QCompleter>
   44 #include <QDir>
   45 #include <QDirModel>
   46 #include <QFileDialog>
   47 #include <QImageReader>
   48 #include <QPainter>
   49 
   50 #include <KConfig>
   51 #include <KLocalizedString>
   52 
   53 /*!
   54   \class HistogramDock
   55   \brief  Provides a widget for editing the properties of the Histograms (2D-curves) currently selected in the project explorer.
   56 
   57   If more than one curves are set, the properties of the first column are shown. The changes of the properties are applied to all curves.
   58   The exclusions are the name, the comment and the datasets (columns) of the curves  - these properties can only be changed if there is only one single curve.
   59 
   60   \ingroup kdefrontend
   61 */
   62 HistogramDock::HistogramDock(QWidget* parent) : BaseDock(parent), cbDataColumn(new TreeViewComboBox) {
   63     ui.setupUi(this);
   64     m_leName = ui.leName;
   65     m_leComment = ui.leComment;
   66 
   67     // Tab "General"
   68     auto* gridLayout = qobject_cast<QGridLayout*>(ui.tabGeneral->layout());
   69     gridLayout->addWidget(cbDataColumn, 3, 2, 1, 1);
   70 
   71     //Tab "Values"
   72     gridLayout = qobject_cast<QGridLayout*>(ui.tabValues->layout());
   73     cbValuesColumn = new TreeViewComboBox(ui.tabValues);
   74     gridLayout->addWidget(cbValuesColumn, 2, 2, 1, 1);
   75 
   76     //add formats for numeric values
   77     ui.cbValuesNumericFormat->addItem(i18n("Decimal"), QVariant('f'));
   78     ui.cbValuesNumericFormat->addItem(i18n("Scientific (e)"), QVariant('e'));
   79     ui.cbValuesNumericFormat->addItem(i18n("Scientific (E)"), QVariant('E'));
   80     ui.cbValuesNumericFormat->addItem(i18n("Automatic (e)"), QVariant('g'));
   81     ui.cbValuesNumericFormat->addItem(i18n("Automatic (E)"), QVariant('G'));
   82 
   83     //add format for date, time and datetime values
   84     for (const auto& s : AbstractColumn::dateFormats())
   85         ui.cbValuesDateTimeFormat->addItem(s, QVariant(s));
   86 
   87     for (const auto& s : AbstractColumn::timeFormats())
   88         ui.cbValuesDateTimeFormat->addItem(s, QVariant(s));
   89 
   90     for (const auto& s1 : AbstractColumn::dateFormats()) {
   91         for (const auto& s2 : AbstractColumn::timeFormats())
   92             ui.cbValuesDateTimeFormat->addItem(s1 + ' ' + s2, QVariant(s1 + ' ' + s2));
   93     }
   94 
   95     ui.cbValuesDateTimeFormat->setEditable(true);
   96 
   97     //Tab "Filling"
   98     ui.cbFillingColorStyle->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
   99     ui.bFillingOpen->setIcon( QIcon::fromTheme("document-open") );
  100 
  101     ui.leFillingFileName->setCompleter(new QCompleter(new QDirModel, this));
  102 
  103     //adjust layouts in the tabs
  104     for (int i = 0; i < ui.tabWidget->count(); ++i) {
  105         auto* layout = dynamic_cast<QGridLayout*>(ui.tabWidget->widget(i)->layout());
  106         if (!layout)
  107             continue;
  108 
  109         layout->setContentsMargins(2,2,2,2);
  110         layout->setHorizontalSpacing(2);
  111         layout->setVerticalSpacing(2);
  112     }
  113 
  114     ui.leBinWidth->setValidator(new QDoubleValidator(ui.leBinWidth));
  115     ui.leBinRangesMin->setValidator(new QDoubleValidator(ui.leBinRangesMin));
  116     ui.leBinRangesMax->setValidator(new QDoubleValidator(ui.leBinRangesMax));
  117 
  118     //Slots
  119     //General
  120     connect(ui.leName, &QLineEdit::textChanged, this, &HistogramDock::nameChanged);
  121     connect(ui.leComment, &QLineEdit::textChanged, this, &HistogramDock::commentChanged);
  122     connect( ui.chkVisible, SIGNAL(clicked(bool)), this, SLOT(visibilityChanged(bool)) );
  123     connect( cbDataColumn, SIGNAL(currentModelIndexChanged(QModelIndex)), this, SLOT(dataColumnChanged(QModelIndex)) );
  124     connect( ui.cbType, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int)) );
  125     connect( ui.cbOrientation, SIGNAL(currentIndexChanged(int)), this, SLOT(orientationChanged(int)));
  126     connect( ui.cbBinningMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(binningMethodChanged(int)) );
  127     connect(ui.sbBinCount, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &HistogramDock::binCountChanged);
  128     connect(ui.leBinWidth, &QLineEdit::textChanged, this, &HistogramDock::binWidthChanged);
  129     connect( ui.chkAutoBinRanges, &QCheckBox::stateChanged, this, &HistogramDock::autoBinRangesChanged );
  130     connect( ui.leBinRangesMin, &QLineEdit::textChanged, this, &HistogramDock::binRangesMinChanged );
  131     connect( ui.leBinRangesMax, &QLineEdit::textChanged, this, &HistogramDock::binRangesMaxChanged );
  132     connect(ui.dteBinRangesMin, &QDateTimeEdit::dateTimeChanged, this, &HistogramDock::binRangesMinDateTimeChanged);
  133     connect(ui.dteBinRangesMax, &QDateTimeEdit::dateTimeChanged, this, &HistogramDock::binRangesMaxDateTimeChanged);
  134 
  135     //Line
  136     connect(ui.cbLineType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &HistogramDock::lineTypeChanged);
  137     connect(ui.cbLineStyle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &HistogramDock::lineStyleChanged);
  138     connect(ui.kcbLineColor, &KColorButton::changed, this, &HistogramDock::lineColorChanged);
  139     connect(ui.sbLineWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &HistogramDock::lineWidthChanged);
  140     connect(ui.sbLineOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &HistogramDock::lineOpacityChanged);
  141 
  142     //Symbol
  143     connect( ui.cbSymbolStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(symbolsStyleChanged(int)) );
  144     connect( ui.sbSymbolSize, SIGNAL(valueChanged(double)), this, SLOT(symbolsSizeChanged(double)) );
  145     connect( ui.sbSymbolRotation, SIGNAL(valueChanged(int)), this, SLOT(symbolsRotationChanged(int)) );
  146     connect( ui.sbSymbolOpacity, SIGNAL(valueChanged(int)), this, SLOT(symbolsOpacityChanged(int)) );
  147 
  148     connect( ui.cbSymbolFillingStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(symbolsFillingStyleChanged(int)) );
  149     connect( ui.kcbSymbolFillingColor, SIGNAL(changed(QColor)), this, SLOT(symbolsFillingColorChanged(QColor)) );
  150 
  151     connect( ui.cbSymbolBorderStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(symbolsBorderStyleChanged(int)) );
  152     connect( ui.kcbSymbolBorderColor, SIGNAL(changed(QColor)), this, SLOT(symbolsBorderColorChanged(QColor)) );
  153     connect( ui.sbSymbolBorderWidth, SIGNAL(valueChanged(double)), this, SLOT(symbolsBorderWidthChanged(double)) );
  154 
  155     //Values
  156     connect( ui.cbValuesType, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesTypeChanged(int)) );
  157     connect( cbValuesColumn, SIGNAL(currentModelIndexChanged(QModelIndex)), this, SLOT(valuesColumnChanged(QModelIndex)) );
  158     connect( ui.cbValuesPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesPositionChanged(int)) );
  159     connect( ui.sbValuesDistance, SIGNAL(valueChanged(double)), this, SLOT(valuesDistanceChanged(double)) );
  160     connect( ui.sbValuesRotation, SIGNAL(valueChanged(int)), this, SLOT(valuesRotationChanged(int)) );
  161     connect( ui.sbValuesOpacity, SIGNAL(valueChanged(int)), this, SLOT(valuesOpacityChanged(int)) );
  162     connect(ui.cbValuesNumericFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &HistogramDock::valuesNumericFormatChanged);
  163     connect(ui.sbValuesPrecision, QOverload<int>::of(&QSpinBox::valueChanged), this, &HistogramDock::valuesPrecisionChanged);
  164     connect(ui.cbValuesDateTimeFormat, &QComboBox::currentTextChanged, this, &HistogramDock::valuesDateTimeFormatChanged);
  165     connect(ui.leValuesPrefix, &QLineEdit::textChanged, this, &HistogramDock::valuesPrefixChanged);
  166     connect(ui.leValuesSuffix, &QLineEdit::textChanged, this, &HistogramDock::valuesSuffixChanged);
  167     connect( ui.kfrValuesFont, SIGNAL(fontSelected(QFont)), this, SLOT(valuesFontChanged(QFont)) );
  168     connect( ui.kcbValuesColor, SIGNAL(changed(QColor)), this, SLOT(valuesColorChanged(QColor)) );
  169 
  170     //Filling
  171     connect(ui.chkFillingEnabled, &QCheckBox::stateChanged, this, &HistogramDock::fillingEnabledChanged);
  172     connect( ui.cbFillingType, SIGNAL(currentIndexChanged(int)), this, SLOT(fillingTypeChanged(int)) );
  173     connect( ui.cbFillingColorStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(fillingColorStyleChanged(int)) );
  174     connect( ui.cbFillingImageStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(fillingImageStyleChanged(int)) );
  175     connect( ui.cbFillingBrushStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(fillingBrushStyleChanged(int)) );
  176     connect( ui.bFillingOpen, SIGNAL(clicked(bool)), this, SLOT(selectFile()));
  177     connect(ui.leFillingFileName, &QLineEdit::textChanged, this, &HistogramDock::fileNameChanged);
  178     connect( ui.leFillingFileName, SIGNAL(textChanged(QString)), this, SLOT(fileNameChanged()) );
  179     connect( ui.kcbFillingFirstColor, SIGNAL(changed(QColor)), this, SLOT(fillingFirstColorChanged(QColor)) );
  180     connect( ui.kcbFillingSecondColor, SIGNAL(changed(QColor)), this, SLOT(fillingSecondColorChanged(QColor)) );
  181     connect( ui.sbFillingOpacity, SIGNAL(valueChanged(int)), this, SLOT(fillingOpacityChanged(int)) );
  182 
  183     //Error bars
  184     connect( ui.cbErrorType, SIGNAL(currentIndexChanged(int)), this, SLOT(errorTypeChanged(int)) );
  185     connect( ui.cbErrorBarsType, SIGNAL(currentIndexChanged(int)), this, SLOT(errorBarsTypeChanged(int)) );
  186     connect( ui.sbErrorBarsCapSize, SIGNAL(valueChanged(double)), this, SLOT(errorBarsCapSizeChanged(double)) );
  187     connect( ui.cbErrorBarsStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(errorBarsStyleChanged(int)) );
  188     connect( ui.kcbErrorBarsColor, SIGNAL(changed(QColor)), this, SLOT(errorBarsColorChanged(QColor)) );
  189     connect( ui.sbErrorBarsWidth, SIGNAL(valueChanged(double)), this, SLOT(errorBarsWidthChanged(double)) );
  190     connect( ui.sbErrorBarsOpacity, SIGNAL(valueChanged(int)), this, SLOT(errorBarsOpacityChanged(int)) );
  191 
  192     //template handler
  193     auto* frame = new QFrame(this);
  194     auto* layout = new QHBoxLayout(frame);
  195     layout->setContentsMargins(0, 11, 0, 11);
  196 
  197     auto* templateHandler = new TemplateHandler(this, TemplateHandler::ClassName::Histogram);
  198     layout->addWidget(templateHandler);
  199     connect(templateHandler, &TemplateHandler::loadConfigRequested, this, &HistogramDock::loadConfigFromTemplate);
  200     connect(templateHandler, &TemplateHandler::saveConfigRequested, this, &HistogramDock::saveConfigAsTemplate);
  201     connect(templateHandler, &TemplateHandler::info, this, &HistogramDock::info);
  202 
  203     ui.verticalLayout->addWidget(frame);
  204 
  205     retranslateUi();
  206     init();
  207 
  208     //TODO: activate the tab for error-bars again once the functionality is implemented
  209     ui.tabWidget->removeTab(5);
  210 }
  211 
  212 HistogramDock::~HistogramDock() {
  213     if (m_aspectTreeModel)
  214         delete m_aspectTreeModel;
  215 }
  216 
  217 void HistogramDock::init() {
  218     //General
  219     //bins option
  220     ui.cbBinningMethod->addItem(i18n("By Number"));
  221     ui.cbBinningMethod->addItem(i18n("By Width"));
  222     ui.cbBinningMethod->addItem(i18n("Square-root"));
  223     ui.cbBinningMethod->addItem(i18n("Rice"));
  224     ui.cbBinningMethod->addItem(i18n("Sturges"));
  225     ui.cbBinningMethod->addItem(i18n("Doane"));
  226     ui.cbBinningMethod->addItem(i18n("Scott"));
  227 
  228     //histogram type
  229     ui.cbType->addItem(i18n("Ordinary Histogram"));
  230     ui.cbType->addItem(i18n("Cumulative Histogram"));
  231 //  ui.cbType->addItem(i18n("AvgShifted Histogram"));
  232 
  233     //Orientation
  234     ui.cbOrientation->addItem(i18n("Vertical"));
  235     ui.cbOrientation->addItem(i18n("Horizontal"));
  236 
  237     //Line
  238     ui.cbLineType->addItem(i18n("None"));
  239     ui.cbLineType->addItem(i18n("Bars"));
  240     ui.cbLineType->addItem(i18n("Envelope"));
  241     ui.cbLineType->addItem(i18n("Drop Lines"));
  242 
  243     GuiTools::updatePenStyles(ui.cbLineStyle, Qt::black);
  244 
  245     //Symbols
  246     GuiTools::updatePenStyles(ui.cbSymbolBorderStyle, Qt::black);
  247 
  248     QPainter pa;
  249     //TODO size of the icon depending on the actual height of the combobox?
  250     int iconSize = 20;
  251     QPixmap pm(iconSize, iconSize);
  252     ui.cbSymbolStyle->setIconSize(QSize(iconSize, iconSize));
  253     QTransform trafo;
  254     trafo.scale(15, 15);
  255 
  256     QPen pen(Qt::SolidPattern, 0);
  257     const QColor& color = (palette().color(QPalette::Base).lightness() < 128) ? Qt::white : Qt::black;
  258     pen.setColor(color);
  259     pa.setPen( pen );
  260 
  261     ui.cbSymbolStyle->addItem(i18n("None"));
  262     for (int i = 1; i < 19; ++i) {  //TODO: use enum count
  263         auto style = (Symbol::Style)i;
  264         pm.fill(Qt::transparent);
  265         pa.begin(&pm);
  266         pa.setPen(pen);
  267         pa.setRenderHint(QPainter::Antialiasing);
  268         pa.translate(iconSize/2,iconSize/2);
  269         pa.drawPath(trafo.map(Symbol::pathFromStyle(style)));
  270         pa.end();
  271         ui.cbSymbolStyle->addItem(QIcon(pm), Symbol::nameFromStyle(style));
  272     }
  273 
  274     GuiTools::updateBrushStyles(ui.cbSymbolFillingStyle, Qt::black);
  275     m_initializing = false;
  276 
  277     //Values
  278     ui.cbValuesType->addItem(i18n("No Values"));
  279     ui.cbValuesType->addItem(i18n("Frequency"));
  280     ui.cbValuesType->addItem(i18n("Custom Column"));
  281 
  282     ui.cbValuesPosition->addItem(i18n("Above"));
  283     ui.cbValuesPosition->addItem(i18n("Below"));
  284     ui.cbValuesPosition->addItem(i18n("Left"));
  285     ui.cbValuesPosition->addItem(i18n("Right"));
  286 
  287     //Filling
  288     ui.cbFillingType->clear();
  289     ui.cbFillingType->addItem(i18n("Color"));
  290     ui.cbFillingType->addItem(i18n("Image"));
  291     ui.cbFillingType->addItem(i18n("Pattern"));
  292 
  293     ui.cbFillingColorStyle->clear();
  294     ui.cbFillingColorStyle->addItem(i18n("Single Color"));
  295     ui.cbFillingColorStyle->addItem(i18n("Horizontal Linear Gradient"));
  296     ui.cbFillingColorStyle->addItem(i18n("Vertical Linear Gradient"));
  297     ui.cbFillingColorStyle->addItem(i18n("Diagonal Linear Gradient (Start From Top Left)"));
  298     ui.cbFillingColorStyle->addItem(i18n("Diagonal Linear Gradient (Start From Bottom Left)"));
  299     ui.cbFillingColorStyle->addItem(i18n("Radial Gradient"));
  300 
  301     ui.cbFillingImageStyle->clear();
  302     ui.cbFillingImageStyle->addItem(i18n("Scaled and Cropped"));
  303     ui.cbFillingImageStyle->addItem(i18n("Scaled"));
  304     ui.cbFillingImageStyle->addItem(i18n("Scaled, Keep Proportions"));
  305     ui.cbFillingImageStyle->addItem(i18n("Centered"));
  306     ui.cbFillingImageStyle->addItem(i18n("Tiled"));
  307     ui.cbFillingImageStyle->addItem(i18n("Center Tiled"));
  308     GuiTools::updateBrushStyles(ui.cbFillingBrushStyle, Qt::SolidPattern);
  309 
  310     //Error-bars
  311     pm.fill(Qt::transparent);
  312     pa.begin( &pm );
  313     pa.setRenderHint(QPainter::Antialiasing);
  314     pa.drawLine(3,10,17,10);//vert. line
  315     pa.drawLine(10,3,10,17);//hor. line
  316     pa.end();
  317     ui.cbErrorBarsType->addItem(i18n("Bars"));
  318     ui.cbErrorBarsType->setItemIcon(0, pm);
  319 
  320     pm.fill(Qt::transparent);
  321     pa.begin( &pm );
  322     pa.setRenderHint(QPainter::Antialiasing);
  323     pa.setBrush(Qt::SolidPattern);
  324     pa.drawLine(3,10,17,10); //vert. line
  325     pa.drawLine(10,3,10,17); //hor. line
  326     pa.drawLine(7,3,13,3); //upper cap
  327     pa.drawLine(7,17,13,17); //bottom cap
  328     pa.drawLine(3,7,3,13); //left cap
  329     pa.drawLine(17,7,17,13); //right cap
  330     pa.end();
  331     ui.cbErrorBarsType->addItem(i18n("Bars with Ends"));
  332     ui.cbErrorBarsType->setItemIcon(1, pm);
  333 
  334     ui.cbErrorType->addItem(i18n("No Errors"));
  335 
  336     GuiTools::updatePenStyles(ui.cbErrorBarsStyle, Qt::black);
  337 }
  338 
  339 void HistogramDock::setModel() {
  340     m_aspectTreeModel->enablePlottableColumnsOnly(true);
  341     m_aspectTreeModel->enableShowPlotDesignation(true);
  342 
  343     QList<AspectType> list{AspectType::Folder, AspectType::Workbook, AspectType::Datapicker,
  344                            AspectType::DatapickerCurve, AspectType::Spreadsheet, AspectType::LiveDataSource,
  345                            AspectType::Column, AspectType::Worksheet, AspectType::CartesianPlot,
  346                            AspectType::XYFitCurve, AspectType::XYSmoothCurve, AspectType::CantorWorksheet};
  347 
  348     cbDataColumn->setTopLevelClasses(list);
  349     cbValuesColumn->setTopLevelClasses(list);
  350 
  351     list = {AspectType::Column};
  352     m_aspectTreeModel->setSelectableAspects(list);
  353 
  354     cbDataColumn->setModel(m_aspectTreeModel);
  355     cbValuesColumn->setModel(m_aspectTreeModel);
  356 }
  357 
  358 void HistogramDock::setCurves(QList<Histogram*> list) {
  359     m_initializing = true;
  360     m_curvesList = list;
  361     m_curve = list.first();
  362     m_aspect = list.first();
  363     Q_ASSERT(m_curve);
  364     m_aspectTreeModel = new AspectTreeModel(m_curve->project());
  365     setModel();
  366 
  367     SET_NUMBER_LOCALE
  368     ui.sbLineWidth->setLocale(numberLocale);
  369     ui.sbSymbolSize->setLocale(numberLocale);
  370     ui.sbSymbolBorderWidth->setLocale(numberLocale);
  371     ui.sbValuesDistance->setLocale(numberLocale);
  372     ui.sbErrorBarsCapSize->setLocale(numberLocale);
  373     ui.sbErrorBarsWidth->setLocale(numberLocale);
  374 
  375     //if there are more then one curve in the list, disable the content in the tab "general"
  376     if (m_curvesList.size() == 1) {
  377         ui.lName->setEnabled(true);
  378         ui.leName->setEnabled(true);
  379         ui.lComment->setEnabled(true);
  380         ui.leComment->setEnabled(true);
  381 
  382         ui.lXColumn->setEnabled(true);
  383         cbDataColumn->setEnabled(true);
  384 
  385         this->setModelIndexFromColumn(cbDataColumn, m_curve->dataColumn());
  386         this->setModelIndexFromColumn(cbValuesColumn, m_curve->valuesColumn());
  387         ui.leName->setText(m_curve->name());
  388         ui.leComment->setText(m_curve->comment());
  389     } else {
  390         ui.lName->setEnabled(false);
  391         ui.leName->setEnabled(false);
  392         ui.lComment->setEnabled(false);
  393         ui.leComment->setEnabled(false);
  394 
  395         ui.lXColumn->setEnabled(false);
  396         cbDataColumn->setEnabled(false);
  397         cbDataColumn->setCurrentModelIndex(QModelIndex());
  398         cbValuesColumn->setCurrentModelIndex(QModelIndex());
  399 
  400         ui.leName->setText(QString());
  401         ui.leComment->setText(QString());
  402     }
  403 
  404     ui.leName->setStyleSheet("");
  405     ui.leName->setToolTip("");
  406 
  407     //show the properties of the first curve
  408     ui.cbType->setCurrentIndex(m_curve->type());
  409     ui.cbOrientation->setCurrentIndex(m_curve->orientation());
  410     ui.cbBinningMethod->setCurrentIndex(m_curve->binningMethod());
  411     ui.sbBinCount->setValue(m_curve->binCount());
  412     ui.leBinWidth->setText(numberLocale.toString(m_curve->binWidth()));
  413     ui.chkAutoBinRanges->setChecked(m_curve->autoBinRanges());
  414     ui.leBinRangesMin->setText( numberLocale.toString(m_curve->binRangesMin()) );
  415     ui.leBinRangesMax->setText( numberLocale.toString(m_curve->binRangesMax()) );
  416     ui.chkVisible->setChecked( m_curve->isVisible() );
  417 
  418     //handle numeric vs. datetime widgets
  419     //TODO: we need to react on range format changes in the plot in general,
  420     //add signal-slot connection for this
  421     const auto* plot = static_cast<const CartesianPlot*>(m_curve->parent(AspectType::CartesianPlot));
  422     ui.dteBinRangesMin->setDisplayFormat(plot->xRangeDateTimeFormat());
  423     ui.dteBinRangesMax->setDisplayFormat(plot->xRangeDateTimeFormat());
  424     ui.dteBinRangesMin->setDateTime(QDateTime::fromMSecsSinceEpoch(m_curve->binRangesMin()));
  425     ui.dteBinRangesMax->setDateTime(QDateTime::fromMSecsSinceEpoch(m_curve->binRangesMax()));
  426 
  427     bool numeric = (plot->xRangeFormat() == CartesianPlot::RangeFormat::Numeric);
  428 
  429     ui.lBinRangesMin->setVisible(numeric);
  430     ui.lBinRangesMax->setVisible(numeric);
  431     ui.leBinRangesMin->setVisible(numeric);
  432     ui.leBinRangesMax->setVisible(numeric);
  433 
  434     ui.lBinRangesMinDateTime->setVisible(!numeric);
  435     ui.dteBinRangesMin->setVisible(!numeric);
  436     ui.lBinRangesMaxDateTime->setVisible(!numeric);
  437     ui.dteBinRangesMax->setVisible(!numeric);
  438 
  439     //load the remaining properties
  440     KConfig config(QString(), KConfig::SimpleConfig);
  441     loadConfig(config);
  442 
  443     //Slots
  444     //General-tab
  445     connect(m_curve, &Histogram::aspectDescriptionChanged, this, &HistogramDock::curveDescriptionChanged);
  446     connect(m_curve, &Histogram::dataColumnChanged, this, &HistogramDock::curveDataColumnChanged);
  447     connect(m_curve, &Histogram::typeChanged, this, &HistogramDock::curveTypeChanged);
  448     connect(m_curve, &Histogram::orientationChanged, this, &HistogramDock::curveOrientationChanged);
  449     connect(m_curve, &Histogram::binningMethodChanged, this, &HistogramDock::curveBinningMethodChanged);
  450     connect(m_curve, &Histogram::binCountChanged, this, &HistogramDock::curveBinCountChanged);
  451     connect(m_curve, &Histogram::binWidthChanged, this, &HistogramDock::curveBinWidthChanged);
  452     connect(m_curve, &Histogram::autoBinRangesChanged, this, &HistogramDock::curveAutoBinRangesChanged);
  453     connect(m_curve, &Histogram::binRangesMinChanged, this, &HistogramDock::curveBinRangesMinChanged);
  454     connect(m_curve, &Histogram::binRangesMaxChanged, this, &HistogramDock::curveBinRangesMaxChanged);
  455     connect(m_curve, &Histogram::visibilityChanged, this, &HistogramDock::curveVisibilityChanged);
  456 
  457     //Line-tab
  458     connect(m_curve, &Histogram::linePenChanged, this, &HistogramDock::curveLinePenChanged);
  459     connect(m_curve, &Histogram::lineOpacityChanged, this, &HistogramDock::curveLineOpacityChanged);
  460 
  461     //Symbol-Tab
  462     connect(m_curve, &Histogram::symbolsStyleChanged, this, &HistogramDock::curveSymbolsStyleChanged);
  463     connect(m_curve, &Histogram::symbolsSizeChanged, this, &HistogramDock::curveSymbolsSizeChanged);
  464     connect(m_curve, &Histogram::symbolsRotationAngleChanged, this, &HistogramDock::curveSymbolsRotationAngleChanged);
  465     connect(m_curve, &Histogram::symbolsOpacityChanged, this, &HistogramDock::curveSymbolsOpacityChanged);
  466     connect(m_curve, &Histogram::symbolsBrushChanged, this, &HistogramDock::curveSymbolsBrushChanged);
  467     connect(m_curve, &Histogram::symbolsPenChanged, this, &HistogramDock::curveSymbolsPenChanged);
  468 
  469     //Values-Tab
  470     connect(m_curve, &Histogram::valuesTypeChanged, this, &HistogramDock::curveValuesTypeChanged);
  471     connect(m_curve, &Histogram::valuesColumnChanged, this, &HistogramDock::curveValuesColumnChanged);
  472     connect(m_curve, &Histogram::valuesPositionChanged, this, &HistogramDock::curveValuesPositionChanged);
  473     connect(m_curve, &Histogram::valuesDistanceChanged, this, &HistogramDock::curveValuesDistanceChanged);
  474     connect(m_curve, &Histogram::valuesOpacityChanged, this, &HistogramDock::curveValuesOpacityChanged);
  475     connect(m_curve, &Histogram::valuesRotationAngleChanged, this, &HistogramDock::curveValuesRotationAngleChanged);
  476     connect(m_curve, &Histogram::valuesNumericFormatChanged, this, &HistogramDock::curveValuesNumericFormatChanged);
  477     connect(m_curve, &Histogram::valuesPrecisionChanged, this, &HistogramDock::curveValuesPrecisionChanged);
  478     connect(m_curve, &Histogram::valuesDateTimeFormatChanged, this, &HistogramDock::curveValuesDateTimeFormatChanged);
  479     connect(m_curve, &Histogram::valuesPrefixChanged, this, &HistogramDock::curveValuesPrefixChanged);
  480     connect(m_curve, &Histogram::valuesSuffixChanged, this, &HistogramDock::curveValuesSuffixChanged);
  481     connect(m_curve, &Histogram::valuesFontChanged, this, &HistogramDock::curveValuesFontChanged);
  482     connect(m_curve, &Histogram::valuesColorChanged, this, &HistogramDock::curveValuesColorChanged);
  483 
  484     //Filling-Tab
  485     connect( m_curve, &Histogram::fillingEnabledChanged, this, &HistogramDock::curveFillingEnabledChanged);
  486     connect( m_curve, &Histogram::fillingTypeChanged, this, &HistogramDock::curveFillingTypeChanged);
  487     connect( m_curve, &Histogram::fillingColorStyleChanged, this, &HistogramDock::curveFillingColorStyleChanged);
  488     connect( m_curve, &Histogram::fillingImageStyleChanged, this, &HistogramDock::curveFillingImageStyleChanged);
  489     connect( m_curve, &Histogram::fillingBrushStyleChanged, this, &HistogramDock::curveFillingBrushStyleChanged);
  490     connect( m_curve, &Histogram::fillingFirstColorChanged, this, &HistogramDock::curveFillingFirstColorChanged);
  491     connect( m_curve, &Histogram::fillingSecondColorChanged, this, &HistogramDock::curveFillingSecondColorChanged);
  492     connect( m_curve, &Histogram::fillingFileNameChanged, this, &HistogramDock::curveFillingFileNameChanged);
  493     connect( m_curve, &Histogram::fillingOpacityChanged, this, &HistogramDock::curveFillingOpacityChanged);
  494 
  495     //"Error bars"-Tab
  496     connect(m_curve, &Histogram::errorTypeChanged, this, &HistogramDock::curveErrorTypeChanged);
  497     connect(m_curve, &Histogram::errorBarsCapSizeChanged, this, &HistogramDock::curveErrorBarsCapSizeChanged);
  498     connect(m_curve, &Histogram::errorBarsTypeChanged, this, &HistogramDock::curveErrorBarsTypeChanged);
  499     connect(m_curve, &Histogram::errorBarsPenChanged, this, &HistogramDock::curveErrorBarsPenChanged);
  500     connect(m_curve, &Histogram::errorBarsOpacityChanged, this, &HistogramDock::curveErrorBarsOpacityChanged);
  501 
  502     m_initializing = false;
  503 }
  504 
  505 void HistogramDock::setModelIndexFromColumn(TreeViewComboBox* cb, const AbstractColumn* column) {
  506     if (column)
  507         cb->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(column));
  508     else
  509         cb->setCurrentModelIndex(QModelIndex());
  510 }
  511 
  512 void HistogramDock::retranslateUi() {
  513     //TODO:
  514 //  ui.lName->setText(i18n("Name"));
  515 //  ui.lComment->setText(i18n("Comment"));
  516 //  ui.chkVisible->setText(i18n("Visible"));
  517 //  ui.lXColumn->setText(i18n("x-data"));
  518 //  ui.lYColumn->setText(i18n("y-data"));
  519 
  520     //TODO updatePenStyles, updateBrushStyles for all comboboxes
  521 }
  522 
  523 //*************************************************************
  524 //**** SLOTs for changes triggered in HistogramDock *****
  525 //*************************************************************
  526 
  527 // "General"-tab
  528 void HistogramDock::visibilityChanged(bool state) {
  529     if (m_initializing)
  530         return;
  531 
  532     for (auto* curve : m_curvesList)
  533         curve->setVisible(state);
  534 }
  535 
  536 void HistogramDock::typeChanged(int index) {
  537     if (m_initializing)
  538         return;
  539 
  540     auto histogramType = Histogram::HistogramType(index);
  541     for (auto* curve : m_curvesList)
  542         curve->setType(histogramType);
  543 }
  544 
  545 void HistogramDock::dataColumnChanged(const QModelIndex& index) {
  546     if (m_initializing)
  547         return;
  548 
  549     auto aspect = static_cast<AbstractAspect*>(index.internalPointer());
  550     AbstractColumn* column(nullptr);
  551     if (aspect) {
  552         column = dynamic_cast<AbstractColumn*>(aspect);
  553         Q_ASSERT(column);
  554     }
  555 
  556     for (auto* curve : m_curvesList)
  557         curve->setDataColumn(column);
  558 }
  559 
  560 void HistogramDock::orientationChanged(int index) {
  561     if (m_initializing)
  562         return;
  563 
  564     auto orientation = Histogram::HistogramOrientation(index);
  565     for (auto* curve : m_curvesList)
  566         curve->setOrientation(orientation);
  567 }
  568 
  569 void HistogramDock::binningMethodChanged(int index) {
  570     const auto binningMethod = Histogram::BinningMethod(index);
  571     if (binningMethod == Histogram::ByNumber) {
  572         ui.lBinCount->show();
  573         ui.sbBinCount->show();
  574         ui.lBinWidth->hide();
  575         ui.leBinWidth->hide();
  576     } else if (binningMethod == Histogram::ByWidth) {
  577         ui.lBinCount->hide();
  578         ui.sbBinCount->hide();
  579         ui.lBinWidth->show();
  580         ui.leBinWidth->show();
  581     } else {
  582         ui.lBinCount->hide();
  583         ui.sbBinCount->hide();
  584         ui.lBinWidth->hide();
  585         ui.leBinWidth->hide();
  586     }
  587 
  588     if (m_initializing)
  589         return;
  590 
  591     for (auto* curve : m_curvesList)
  592         curve->setBinningMethod(binningMethod);
  593 }
  594 
  595 void HistogramDock::binCountChanged(int value) {
  596     if (m_initializing)
  597         return;
  598 
  599     for (auto* curve : m_curvesList)
  600         curve->setBinCount(value);
  601 }
  602 
  603 void HistogramDock::binWidthChanged() {
  604     if (m_initializing)
  605         return;
  606 
  607     const Lock lock(m_initializing);
  608     bool ok;
  609     SET_NUMBER_LOCALE
  610     const double width{numberLocale.toDouble(ui.leBinWidth->text(), &ok)};
  611     if (ok) {
  612         for (auto* curve : m_curvesList)
  613             curve->setBinWidth(width);
  614     }
  615 }
  616 
  617 void HistogramDock::autoBinRangesChanged(int state) {
  618     bool checked = (state == Qt::Checked);
  619     ui.leBinRangesMin->setEnabled(!checked);
  620     ui.leBinRangesMax->setEnabled(!checked);
  621     ui.dteBinRangesMin->setEnabled(!checked);
  622     ui.dteBinRangesMax->setEnabled(!checked);
  623 
  624     if (m_initializing)
  625         return;
  626 
  627     for (auto* hist : m_curvesList)
  628         hist->setAutoBinRanges(checked);
  629 }
  630 
  631 void HistogramDock::binRangesMinChanged(const QString& value) {
  632     if (m_initializing)
  633         return;
  634 
  635     const Lock lock(m_initializing);
  636     bool ok;
  637     SET_NUMBER_LOCALE
  638     const double min{numberLocale.toDouble(value, &ok)};
  639     if (ok) {
  640         for (auto* hist : m_curvesList)
  641             hist->setBinRangesMin(min);
  642     }
  643 }
  644 
  645 void HistogramDock::binRangesMaxChanged(const QString& value) {
  646     if (m_initializing)
  647         return;
  648 
  649     const Lock lock(m_initializing);
  650     bool ok;
  651     SET_NUMBER_LOCALE
  652     const double max{numberLocale.toDouble(value, &ok)};
  653     if (ok) {
  654         for (auto* hist : m_curvesList)
  655             hist->setBinRangesMax(max);
  656     }
  657 }
  658 
  659 void HistogramDock::binRangesMinDateTimeChanged(const QDateTime& dateTime) {
  660     if (m_initializing)
  661         return;
  662 
  663     quint64 min = dateTime.toMSecsSinceEpoch();
  664     for (auto* hist : m_curvesList)
  665         hist->setBinRangesMin(min);
  666 }
  667 
  668 void HistogramDock::binRangesMaxDateTimeChanged(const QDateTime& dateTime) {
  669     if (m_initializing)
  670         return;
  671 
  672     quint64 max = dateTime.toMSecsSinceEpoch();
  673     for (auto* hist : m_curvesList)
  674         hist->setBinRangesMax(max);
  675 }
  676 
  677 //Line tab
  678 void HistogramDock::lineTypeChanged(int index) {
  679     auto lineType = Histogram::LineType(index);
  680 
  681     if ( lineType == Histogram::NoLine) {
  682         ui.cbLineStyle->setEnabled(false);
  683         ui.kcbLineColor->setEnabled(false);
  684         ui.sbLineWidth->setEnabled(false);
  685         ui.sbLineOpacity->setEnabled(false);
  686     } else {
  687         ui.cbLineStyle->setEnabled(true);
  688         ui.kcbLineColor->setEnabled(true);
  689         ui.sbLineWidth->setEnabled(true);
  690         ui.sbLineOpacity->setEnabled(true);
  691     }
  692 
  693     if (m_initializing)
  694         return;
  695 
  696     for (auto* curve : m_curvesList)
  697         curve->setLineType(lineType);
  698 }
  699 
  700 void HistogramDock::lineStyleChanged(int index) {
  701     if (m_initializing)
  702         return;
  703 
  704     auto penStyle = Qt::PenStyle(index);
  705     QPen pen;
  706     for (auto* curve : m_curvesList) {
  707         pen = curve->linePen();
  708         pen.setStyle(penStyle);
  709         curve->setLinePen(pen);
  710     }
  711 }
  712 
  713 void HistogramDock::lineColorChanged(const QColor& color) {
  714     if (m_initializing)
  715         return;
  716 
  717     QPen pen;
  718     for (auto* curve : m_curvesList) {
  719         pen = curve->linePen();
  720         pen.setColor(color);
  721         curve->setLinePen(pen);
  722     }
  723 
  724     m_initializing = true;
  725     GuiTools::updatePenStyles(ui.cbLineStyle, color);
  726     m_initializing = false;
  727 }
  728 
  729 void HistogramDock::lineWidthChanged(double value) {
  730     if (m_initializing)
  731         return;
  732 
  733     QPen pen;
  734     for (auto* curve : m_curvesList) {
  735         pen = curve->linePen();
  736         pen.setWidthF( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) );
  737         curve->setLinePen(pen);
  738     }
  739 }
  740 
  741 void HistogramDock::lineOpacityChanged(int value) {
  742     if (m_initializing)
  743         return;
  744 
  745     qreal opacity = (float)value/100.;
  746     for (auto* curve : m_curvesList)
  747         curve->setLineOpacity(opacity);
  748 }
  749 
  750 //"Symbol"-tab
  751 void HistogramDock::symbolsStyleChanged(int index) {
  752     const auto style = Symbol::Style(index);
  753 
  754     if (style == Symbol::Style::NoSymbols) {
  755         ui.sbSymbolSize->setEnabled(false);
  756         ui.sbSymbolRotation->setEnabled(false);
  757         ui.sbSymbolOpacity->setEnabled(false);
  758 
  759         ui.kcbSymbolFillingColor->setEnabled(false);
  760         ui.cbSymbolFillingStyle->setEnabled(false);
  761 
  762         ui.cbSymbolBorderStyle->setEnabled(false);
  763         ui.kcbSymbolBorderColor->setEnabled(false);
  764         ui.sbSymbolBorderWidth->setEnabled(false);
  765     } else {
  766         ui.sbSymbolSize->setEnabled(true);
  767         ui.sbSymbolRotation->setEnabled(true);
  768         ui.sbSymbolOpacity->setEnabled(true);
  769 
  770         //enable/disable the symbol filling options in the GUI depending on the currently selected symbol.
  771         if (style != Symbol::Style::Line && style != Symbol::Style::Cross) {
  772             ui.cbSymbolFillingStyle->setEnabled(true);
  773             bool noBrush = (Qt::BrushStyle(ui.cbSymbolFillingStyle->currentIndex()) == Qt::NoBrush);
  774             ui.kcbSymbolFillingColor->setEnabled(!noBrush);
  775         } else {
  776             ui.kcbSymbolFillingColor->setEnabled(false);
  777             ui.cbSymbolFillingStyle->setEnabled(false);
  778         }
  779 
  780         ui.cbSymbolBorderStyle->setEnabled(true);
  781         bool noLine = (Qt::PenStyle(ui.cbSymbolBorderStyle->currentIndex()) == Qt::NoPen);
  782         ui.kcbSymbolBorderColor->setEnabled(!noLine);
  783         ui.sbSymbolBorderWidth->setEnabled(!noLine);
  784     }
  785 
  786     if (m_initializing)
  787         return;
  788 
  789     for (auto* curve : m_curvesList)
  790         curve->setSymbolsStyle(style);
  791 }
  792 
  793 void HistogramDock::symbolsSizeChanged(double value) {
  794     if (m_initializing)
  795         return;
  796 
  797     for (auto* curve : m_curvesList)
  798         curve->setSymbolsSize( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) );
  799 }
  800 
  801 void HistogramDock::symbolsRotationChanged(int value) {
  802     if (m_initializing)
  803         return;
  804 
  805     for (auto* curve : m_curvesList)
  806         curve->setSymbolsRotationAngle(value);
  807 }
  808 
  809 void HistogramDock::symbolsOpacityChanged(int value) {
  810     if (m_initializing)
  811         return;
  812 
  813     qreal opacity = (float)value/100.;
  814     for (auto* curve : m_curvesList)
  815         curve->setSymbolsOpacity(opacity);
  816 }
  817 
  818 void HistogramDock::symbolsFillingStyleChanged(int index) {
  819     auto brushStyle = Qt::BrushStyle(index);
  820     ui.kcbSymbolFillingColor->setEnabled(!(brushStyle == Qt::NoBrush));
  821 
  822     if (m_initializing)
  823         return;
  824 
  825     QBrush brush;
  826     for (auto* curve : m_curvesList) {
  827         brush = curve->symbolsBrush();
  828         brush.setStyle(brushStyle);
  829         curve->setSymbolsBrush(brush);
  830     }
  831 }
  832 
  833 void HistogramDock::symbolsFillingColorChanged(const QColor& color) {
  834     if (m_initializing)
  835         return;
  836 
  837     QBrush brush;
  838     for (auto* curve : m_curvesList) {
  839         brush = curve->symbolsBrush();
  840         brush.setColor(color);
  841         curve->setSymbolsBrush(brush);
  842     }
  843 
  844     m_initializing = true;
  845     GuiTools::updateBrushStyles(ui.cbSymbolFillingStyle, color );
  846     m_initializing = false;
  847 }
  848 
  849 void HistogramDock::symbolsBorderStyleChanged(int index) {
  850     auto penStyle = Qt::PenStyle(index);
  851 
  852     if ( penStyle == Qt::NoPen ) {
  853         ui.kcbSymbolBorderColor->setEnabled(false);
  854         ui.sbSymbolBorderWidth->setEnabled(false);
  855     } else {
  856         ui.kcbSymbolBorderColor->setEnabled(true);
  857         ui.sbSymbolBorderWidth->setEnabled(true);
  858     }
  859 
  860     if (m_initializing)
  861         return;
  862 
  863     QPen pen;
  864     for (auto* curve : m_curvesList) {
  865         pen = curve->symbolsPen();
  866         pen.setStyle(penStyle);
  867         curve->setSymbolsPen(pen);
  868     }
  869 }
  870 
  871 void HistogramDock::symbolsBorderColorChanged(const QColor& color) {
  872     if (m_initializing)
  873         return;
  874 
  875     QPen pen;
  876     for (auto* curve : m_curvesList) {
  877         pen = curve->symbolsPen();
  878         pen.setColor(color);
  879         curve->setSymbolsPen(pen);
  880     }
  881 
  882     m_initializing = true;
  883     GuiTools::updatePenStyles(ui.cbSymbolBorderStyle, color);
  884     m_initializing = false;
  885 }
  886 
  887 void HistogramDock::symbolsBorderWidthChanged(double value) {
  888     if (m_initializing)
  889         return;
  890 
  891     QPen pen;
  892     for (auto* curve : m_curvesList) {
  893         pen = curve->symbolsPen();
  894         pen.setWidthF( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) );
  895         curve->setSymbolsPen(pen);
  896     }
  897 }
  898 
  899 //Values tab
  900 /*!
  901   called when the type of the values (none, x, y, (x,y) etc.) was changed.
  902 */
  903 void HistogramDock::valuesTypeChanged(int index) {
  904     if (m_initializing)
  905         return;
  906 
  907     this->updateValuesWidgets();
  908 
  909     auto valuesType = Histogram::ValuesType(index);
  910     for (auto* curve : m_curvesList)
  911         curve->setValuesType(valuesType);
  912 }
  913 
  914 /*!
  915   depending on the currently selected values column type (column mode) updates the widgets for the values column format,
  916   shows/hides the allowed widgets, fills the corresponding combobox with the possible entries.
  917   Called when the values column was changed.
  918 */
  919 void HistogramDock::updateValuesWidgets() {
  920     const auto type = Histogram::ValuesType(ui.cbValuesType->currentIndex());
  921     bool showValues = (type != Histogram::NoValues);
  922 
  923     ui.cbValuesPosition->setEnabled(showValues);
  924     ui.sbValuesDistance->setEnabled(showValues);
  925     ui.sbValuesRotation->setEnabled(showValues);
  926     ui.sbValuesOpacity->setEnabled(showValues);
  927     ui.kfrValuesFont->setEnabled(showValues);
  928     ui.kcbValuesColor->setEnabled(showValues);
  929 
  930     bool hasInteger = false;
  931     bool hasNumeric = false;
  932     bool hasDateTime = false;
  933 
  934     if (type == Histogram::ValuesCustomColumn) {
  935         ui.lValuesColumn->show();
  936         cbValuesColumn->show();
  937 
  938         auto* column = static_cast<Column*>(cbValuesColumn->currentModelIndex().internalPointer());
  939         if (column) {
  940             if (column->columnMode() == AbstractColumn::ColumnMode::Numeric)
  941                 hasNumeric = true;
  942             else if (column->columnMode() == AbstractColumn::ColumnMode::Integer || column->columnMode() == AbstractColumn::ColumnMode::BigInt)
  943                 hasInteger = true;
  944             else if (column->columnMode() == AbstractColumn::ColumnMode::DateTime)
  945                 hasDateTime = true;
  946         }
  947     } else {
  948         ui.lValuesColumn->hide();
  949         cbValuesColumn->hide();
  950 
  951         if (type == Histogram::ValuesBinEntries)
  952             hasInteger = true;
  953     }
  954 
  955     //hide all the format related widgets first and
  956     //then show only what is required depending of the column mode(s)
  957     ui.lValuesFormat->hide();
  958     ui.lValuesNumericFormat->hide();
  959     ui.cbValuesNumericFormat->hide();
  960     ui.lValuesPrecision->hide();
  961     ui.sbValuesPrecision->hide();
  962     ui.lValuesDateTimeFormat->hide();
  963     ui.cbValuesDateTimeFormat->hide();
  964 
  965     if (hasNumeric || hasInteger) {
  966         ui.lValuesFormat->show();
  967         ui.lValuesNumericFormat->show();
  968         ui.cbValuesNumericFormat->show();
  969     }
  970 
  971     //precision is only available for Numeric
  972     if (hasNumeric) {
  973         ui.lValuesPrecision->show();
  974         ui.sbValuesPrecision->show();
  975     }
  976 
  977     if (hasDateTime) {
  978         ui.lValuesFormat->show();
  979         ui.lValuesDateTimeFormat->show();
  980         ui.cbValuesDateTimeFormat->show();
  981     }
  982 }
  983 
  984 /*!
  985   called when the custom column for the values was changed.
  986 */
  987 void HistogramDock::valuesColumnChanged(const QModelIndex& index) {
  988     if (m_initializing)
  989         return;
  990 
  991     this->updateValuesWidgets();
  992 
  993     auto* column = static_cast<Column*>(index.internalPointer());
  994     for (auto* curve : m_curvesList)
  995         curve->setValuesColumn(column);
  996 }
  997 
  998 void HistogramDock::valuesPositionChanged(int index) {
  999     if (m_initializing)
 1000         return;
 1001 
 1002     for (auto* curve : m_curvesList)
 1003         curve->setValuesPosition(Histogram::ValuesPosition(index));
 1004 }
 1005 
 1006 void HistogramDock::valuesDistanceChanged(double  value) {
 1007     if (m_initializing)
 1008         return;
 1009 
 1010     for (auto* curve : m_curvesList)
 1011         curve->setValuesDistance( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) );
 1012 }
 1013 
 1014 void HistogramDock::valuesRotationChanged(int value) {
 1015     if (m_initializing)
 1016         return;
 1017 
 1018     for (auto* curve : m_curvesList)
 1019         curve->setValuesRotationAngle(value);
 1020 }
 1021 
 1022 void HistogramDock::valuesOpacityChanged(int value) {
 1023     if (m_initializing)
 1024         return;
 1025 
 1026     qreal opacity = (float)value/100.;
 1027     for (auto* curve : m_curvesList)
 1028         curve->setValuesOpacity(opacity);
 1029 }
 1030 
 1031 void HistogramDock::valuesNumericFormatChanged(int index) {
 1032     if (m_initializing)
 1033         return;
 1034 
 1035     char format = ui.cbValuesNumericFormat->itemData(index).toChar().toLatin1();
 1036     for (auto* curve : m_curvesList)
 1037         curve->setValuesNumericFormat(format);
 1038 }
 1039 
 1040 void HistogramDock::valuesPrecisionChanged(int precision) {
 1041     if (m_initializing)
 1042         return;
 1043 
 1044     for (auto* curve : m_curvesList)
 1045         curve->setValuesPrecision(precision);
 1046 }
 1047 
 1048 void HistogramDock::valuesDateTimeFormatChanged(const QString& format) {
 1049     if (m_initializing)
 1050         return;
 1051 
 1052     for (auto* curve : m_curvesList)
 1053         curve->setValuesDateTimeFormat(format);
 1054 }
 1055 
 1056 void HistogramDock::valuesPrefixChanged() {
 1057     if (m_initializing)
 1058         return;
 1059 
 1060     QString prefix = ui.leValuesPrefix->text();
 1061     for (auto* curve : m_curvesList)
 1062         curve->setValuesPrefix(prefix);
 1063 }
 1064 
 1065 void HistogramDock::valuesSuffixChanged() {
 1066     if (m_initializing)
 1067         return;
 1068 
 1069     QString suffix = ui.leValuesSuffix->text();
 1070     for (auto* curve : m_curvesList)
 1071         curve->setValuesSuffix(suffix);
 1072 }
 1073 
 1074 void HistogramDock::valuesFontChanged(const QFont& font) {
 1075     if (m_initializing)
 1076         return;
 1077 
 1078     QFont valuesFont = font;
 1079     valuesFont.setPixelSize( Worksheet::convertToSceneUnits(font.pointSizeF(), Worksheet::Unit::Point) );
 1080     for (auto* curve : m_curvesList)
 1081         curve->setValuesFont(valuesFont);
 1082 }
 1083 
 1084 void HistogramDock::valuesColorChanged(const QColor& color) {
 1085     if (m_initializing)
 1086         return;
 1087 
 1088     for (auto* curve : m_curvesList)
 1089         curve->setValuesColor(color);
 1090 }
 1091 
 1092 //Filling-tab
 1093 void HistogramDock::fillingEnabledChanged(int state) {
 1094     ui.cbFillingType->setEnabled(state);
 1095     ui.cbFillingColorStyle->setEnabled(state);
 1096     ui.cbFillingBrushStyle->setEnabled(state);
 1097     ui.cbFillingImageStyle->setEnabled(state);
 1098     ui.kcbFillingFirstColor->setEnabled(state);
 1099     ui.kcbFillingSecondColor->setEnabled(state);
 1100     ui.leFillingFileName->setEnabled(state);
 1101     ui.bFillingOpen->setEnabled(state);
 1102     ui.sbFillingOpacity->setEnabled(state);
 1103 
 1104     if (m_initializing)
 1105         return;
 1106 
 1107     for (auto* curve : m_curvesList)
 1108         curve->setFillingEnabled(state);
 1109 }
 1110 
 1111 void HistogramDock::fillingTypeChanged(int index) {
 1112     auto type = (PlotArea::BackgroundType)index;
 1113 
 1114     if (type == PlotArea::BackgroundType::Color) {
 1115         ui.lFillingColorStyle->show();
 1116         ui.cbFillingColorStyle->show();
 1117         ui.lFillingImageStyle->hide();
 1118         ui.cbFillingImageStyle->hide();
 1119         ui.lFillingBrushStyle->hide();
 1120         ui.cbFillingBrushStyle->hide();
 1121 
 1122         ui.lFillingFileName->hide();
 1123         ui.leFillingFileName->hide();
 1124         ui.bFillingOpen->hide();
 1125 
 1126         ui.lFillingFirstColor->show();
 1127         ui.kcbFillingFirstColor->show();
 1128 
 1129         auto style = (PlotArea::BackgroundColorStyle) ui.cbFillingColorStyle->currentIndex();
 1130         if (style == PlotArea::BackgroundColorStyle::SingleColor) {
 1131             ui.lFillingFirstColor->setText(i18n("Color:"));
 1132             ui.lFillingSecondColor->hide();
 1133             ui.kcbFillingSecondColor->hide();
 1134         } else {
 1135             ui.lFillingFirstColor->setText(i18n("First color:"));
 1136             ui.lFillingSecondColor->show();
 1137             ui.kcbFillingSecondColor->show();
 1138         }
 1139     } else if (type == PlotArea::BackgroundType::Image) {
 1140         ui.lFillingColorStyle->hide();
 1141         ui.cbFillingColorStyle->hide();
 1142         ui.lFillingImageStyle->show();
 1143         ui.cbFillingImageStyle->show();
 1144         ui.lFillingBrushStyle->hide();
 1145         ui.cbFillingBrushStyle->hide();
 1146         ui.lFillingFileName->show();
 1147         ui.leFillingFileName->show();
 1148         ui.bFillingOpen->show();
 1149 
 1150         ui.lFillingFirstColor->hide();
 1151         ui.kcbFillingFirstColor->hide();
 1152         ui.lFillingSecondColor->hide();
 1153         ui.kcbFillingSecondColor->hide();
 1154     } else if (type == PlotArea::BackgroundType::Pattern) {
 1155         ui.lFillingFirstColor->setText(i18n("Color:"));
 1156         ui.lFillingColorStyle->hide();
 1157         ui.cbFillingColorStyle->hide();
 1158         ui.lFillingImageStyle->hide();
 1159         ui.cbFillingImageStyle->hide();
 1160         ui.lFillingBrushStyle->show();
 1161         ui.cbFillingBrushStyle->show();
 1162         ui.lFillingFileName->hide();
 1163         ui.leFillingFileName->hide();
 1164         ui.bFillingOpen->hide();
 1165 
 1166         ui.lFillingFirstColor->show();
 1167         ui.kcbFillingFirstColor->show();
 1168         ui.lFillingSecondColor->hide();
 1169         ui.kcbFillingSecondColor->hide();
 1170     }
 1171 
 1172     if (m_initializing)
 1173         return;
 1174 
 1175     for (auto* curve : m_curvesList)
 1176         curve->setFillingType(type);
 1177 }
 1178 
 1179 void HistogramDock::fillingColorStyleChanged(int index) {
 1180     auto style = (PlotArea::BackgroundColorStyle)index;
 1181 
 1182     if (style == PlotArea::BackgroundColorStyle::SingleColor) {
 1183         ui.lFillingFirstColor->setText(i18n("Color:"));
 1184         ui.lFillingSecondColor->hide();
 1185         ui.kcbFillingSecondColor->hide();
 1186     } else {
 1187         ui.lFillingFirstColor->setText(i18n("First color:"));
 1188         ui.lFillingSecondColor->show();
 1189         ui.kcbFillingSecondColor->show();
 1190         ui.lFillingBrushStyle->hide();
 1191         ui.cbFillingBrushStyle->hide();
 1192     }
 1193 
 1194     if (m_initializing)
 1195         return;
 1196 
 1197     for (auto* curve : m_curvesList)
 1198         curve->setFillingColorStyle(style);
 1199 }
 1200 
 1201 void HistogramDock::fillingImageStyleChanged(int index) {
 1202     if (m_initializing)
 1203         return;
 1204 
 1205     auto style = (PlotArea::BackgroundImageStyle)index;
 1206     for (auto* curve : m_curvesList)
 1207         curve->setFillingImageStyle(style);
 1208 }
 1209 
 1210 void HistogramDock::fillingBrushStyleChanged(int index) {
 1211     if (m_initializing)
 1212         return;
 1213 
 1214     auto style = (Qt::BrushStyle)index;
 1215     for (auto* curve : m_curvesList)
 1216         curve->setFillingBrushStyle(style);
 1217 }
 1218 
 1219 void HistogramDock::fillingFirstColorChanged(const QColor& c) {
 1220     if (m_initializing)
 1221         return;
 1222 
 1223     for (auto* curve : m_curvesList)
 1224         curve->setFillingFirstColor(c);
 1225 }
 1226 
 1227 void HistogramDock::fillingSecondColorChanged(const QColor& c) {
 1228     if (m_initializing)
 1229         return;
 1230 
 1231     for (auto* curve : m_curvesList)
 1232         curve->setFillingSecondColor(c);
 1233 }
 1234 
 1235 //"Error bars"-Tab
 1236 void HistogramDock::errorTypeChanged(int index) const {
 1237     bool b = (index != 0);
 1238     ui.lErrorData->setVisible(b);
 1239     ui.lErrorFormat->setVisible(b);
 1240     ui.lErrorBarsType->setVisible(b);
 1241     ui.cbErrorBarsType->setVisible(b);
 1242     ui.lErrorBarsStyle->setVisible(b);
 1243     ui.cbErrorBarsStyle->setVisible(b);
 1244     ui.lErrorBarsColor->setVisible(b);
 1245     ui.kcbErrorBarsColor->setVisible(b);
 1246     ui.lErrorBarsWidth->setVisible(b);
 1247     ui.sbErrorBarsWidth->setVisible(b);
 1248     ui.lErrorBarsOpacity->setVisible(b);
 1249     ui.sbErrorBarsOpacity->setVisible(b);
 1250 
 1251     if (m_initializing)
 1252         return;
 1253 
 1254     for (auto* curve : m_curvesList)
 1255         curve->setErrorType(Histogram::ErrorType(index));
 1256 }
 1257 
 1258 void HistogramDock::errorBarsTypeChanged(int index) const {
 1259     auto type{XYCurve::ErrorBarsType(index)};
 1260     bool b = (type == XYCurve::ErrorBarsType::WithEnds);
 1261     ui.lErrorBarsCapSize->setVisible(b);
 1262     ui.sbErrorBarsCapSize->setVisible(b);
 1263 
 1264     if (m_initializing)
 1265         return;
 1266 
 1267     for (auto* curve : m_curvesList)
 1268         curve->setErrorBarsType(type);
 1269 }
 1270 
 1271 void HistogramDock::errorBarsCapSizeChanged(double value) const {
 1272     if (m_initializing)
 1273         return;
 1274 
 1275     double size = Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point);
 1276     for (auto* curve : m_curvesList)
 1277         curve->setErrorBarsCapSize(size);
 1278 }
 1279 
 1280 void HistogramDock::errorBarsStyleChanged(int index) const {
 1281     if (m_initializing)
 1282         return;
 1283 
 1284     auto penStyle = Qt::PenStyle(index);
 1285     QPen pen;
 1286     for (auto* curve : m_curvesList) {
 1287         pen = curve->errorBarsPen();
 1288         pen.setStyle(penStyle);
 1289         curve->setErrorBarsPen(pen);
 1290     }
 1291 }
 1292 
 1293 void HistogramDock::errorBarsColorChanged(const QColor& color) {
 1294     if (m_initializing)
 1295         return;
 1296 
 1297     QPen pen;
 1298     for (auto* curve : m_curvesList) {
 1299         pen = curve->errorBarsPen();
 1300         pen.setColor(color);
 1301         curve->setErrorBarsPen(pen);
 1302     }
 1303 
 1304     m_initializing = true;
 1305     GuiTools::updatePenStyles(ui.cbErrorBarsStyle, color);
 1306     m_initializing = false;
 1307 }
 1308 
 1309 void HistogramDock::errorBarsWidthChanged(double value) const {
 1310     if (m_initializing)
 1311         return;
 1312 
 1313     QPen pen;
 1314     for (auto* curve : m_curvesList) {
 1315         pen = curve->errorBarsPen();
 1316         pen.setWidthF( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) );
 1317         curve->setErrorBarsPen(pen);
 1318     }
 1319 }
 1320 
 1321 void HistogramDock::errorBarsOpacityChanged(int value) const {
 1322     if (m_initializing)
 1323         return;
 1324 
 1325     qreal opacity = (double)value/100.;
 1326     for (auto* curve : m_curvesList)
 1327         curve->setErrorBarsOpacity(opacity);
 1328 }
 1329 
 1330 /*!
 1331     opens a file dialog and lets the user select the image file.
 1332 */
 1333 void HistogramDock::selectFile() {
 1334     KConfigGroup conf(KSharedConfig::openConfig(), "HistogramDock");
 1335     QString dir = conf.readEntry("LastImageDir", "");
 1336 
 1337     QString formats;
 1338     for (const QByteArray& format : QImageReader::supportedImageFormats()) {
 1339         QString f = "*." + QString(format.constData());
 1340         if (f == QLatin1String("*.svg"))
 1341             continue;
 1342         formats.isEmpty() ? formats += f : formats += ' ' + f;
 1343     }
 1344 
 1345     QString path = QFileDialog::getOpenFileName(this, i18n("Select the image file"), dir, i18n("Images (%1)", formats));
 1346     if (path.isEmpty())
 1347         return; //cancel was clicked in the file-dialog
 1348 
 1349     int pos = path.lastIndexOf(QLatin1String("/"));
 1350     if (pos != -1) {
 1351         QString newDir = path.left(pos);
 1352         if (newDir != dir)
 1353             conf.writeEntry("LastImageDir", newDir);
 1354     }
 1355 
 1356     ui.leFillingFileName->setText( path );
 1357 
 1358     for (auto* curve : m_curvesList)
 1359         curve->setFillingFileName(path);
 1360 }
 1361 
 1362 void HistogramDock::fileNameChanged() {
 1363     if (m_initializing)
 1364         return;
 1365 
 1366     QString fileName = ui.leFillingFileName->text();
 1367     for (auto* curve : m_curvesList)
 1368         curve->setFillingFileName(fileName);
 1369 }
 1370 
 1371 void HistogramDock::fillingOpacityChanged(int value) {
 1372     if (m_initializing)
 1373         return;
 1374 
 1375     qreal opacity = (double)value/100.;
 1376     for (auto* curve : m_curvesList)
 1377         curve->setFillingOpacity(opacity);
 1378 }
 1379 
 1380 //*************************************************************
 1381 //*********** SLOTs for changes triggered in Histogram *******
 1382 //*************************************************************
 1383 
 1384 //General-Tab
 1385 void HistogramDock::curveDescriptionChanged(const AbstractAspect* aspect) {
 1386     if (m_curve != aspect)
 1387         return;
 1388 
 1389     m_initializing = true;
 1390     if (aspect->name() != ui.leName->text())
 1391         ui.leName->setText(aspect->name());
 1392     else if (aspect->comment() != ui.leComment->text())
 1393         ui.leComment->setText(aspect->comment());
 1394 
 1395     m_initializing = false;
 1396 }
 1397 
 1398 void HistogramDock::curveDataColumnChanged(const AbstractColumn* column) {
 1399     m_initializing = true;
 1400     this->setModelIndexFromColumn(cbDataColumn, column);
 1401     m_initializing = false;
 1402 }
 1403 
 1404 void HistogramDock::curveTypeChanged(Histogram::HistogramType type) {
 1405     m_initializing = true;
 1406     ui.cbType->setCurrentIndex((int)type);
 1407     m_initializing = false;
 1408 }
 1409 
 1410 void HistogramDock::curveOrientationChanged(Histogram::HistogramOrientation orientation) {
 1411     m_initializing = true;
 1412     ui.cbOrientation->setCurrentIndex((int)orientation);
 1413     m_initializing = false;
 1414 }
 1415 
 1416 void HistogramDock::curveBinningMethodChanged(Histogram::BinningMethod method) {
 1417     m_initializing = true;
 1418     ui.cbBinningMethod->setCurrentIndex((int)method);
 1419     m_initializing = false;
 1420 }
 1421 
 1422 void HistogramDock::curveBinCountChanged(int count) {
 1423     m_initializing = true;
 1424     ui.sbBinCount->setValue(count);
 1425     m_initializing = false;
 1426 }
 1427 
 1428 void HistogramDock::curveBinWidthChanged(double width) {
 1429     if (m_initializing)return;
 1430     const Lock lock(m_initializing);
 1431     SET_NUMBER_LOCALE
 1432     ui.leBinWidth->setText(numberLocale.toString(width));
 1433 }
 1434 
 1435 void HistogramDock::curveAutoBinRangesChanged(bool value) {
 1436     m_initializing = true;
 1437     ui.chkAutoBinRanges->setChecked(value);
 1438     m_initializing = false;
 1439 }
 1440 
 1441 void HistogramDock::curveBinRangesMinChanged(double value) {
 1442     if (m_initializing)return;
 1443     const Lock lock(m_initializing);
 1444     SET_NUMBER_LOCALE
 1445     ui.leBinRangesMin->setText(numberLocale.toString(value));
 1446     ui.dteBinRangesMin->setDateTime(QDateTime::fromMSecsSinceEpoch(value));
 1447 }
 1448 
 1449 void HistogramDock::curveBinRangesMaxChanged(double value) {
 1450     if (m_initializing)return;
 1451     const Lock lock(m_initializing);
 1452     SET_NUMBER_LOCALE
 1453     ui.leBinRangesMax->setText(numberLocale.toString(value));
 1454     ui.dteBinRangesMax->setDateTime(QDateTime::fromMSecsSinceEpoch(value));
 1455 }
 1456 
 1457 //Line-Tab
 1458 void HistogramDock::curveLineTypeChanged(Histogram::LineType type) {
 1459     m_initializing = true;
 1460     ui.cbLineType->setCurrentIndex((int)type);
 1461     m_initializing = false;
 1462 }
 1463 void HistogramDock::curveLinePenChanged(const QPen& pen) {
 1464     m_initializing = true;
 1465     ui.cbLineStyle->setCurrentIndex( (int)pen.style());
 1466     ui.kcbLineColor->setColor( pen.color());
 1467     GuiTools::updatePenStyles(ui.cbLineStyle, pen.color());
 1468     ui.sbLineWidth->setValue( Worksheet::convertFromSceneUnits( pen.widthF(), Worksheet::Unit::Point) );
 1469     m_initializing = false;
 1470 }
 1471 void HistogramDock::curveLineOpacityChanged(qreal opacity) {
 1472     m_initializing = true;
 1473     ui.sbLineOpacity->setValue( round(opacity*100.0) );
 1474     m_initializing = false;
 1475 }
 1476 
 1477 //Symbol-Tab
 1478 void HistogramDock::curveSymbolsStyleChanged(Symbol::Style style) {
 1479     m_initializing = true;
 1480     ui.cbSymbolStyle->setCurrentIndex((int)style);
 1481     m_initializing = false;
 1482 }
 1483 void HistogramDock::curveSymbolsSizeChanged(qreal size) {
 1484     m_initializing = true;
 1485     ui.sbSymbolSize->setValue( Worksheet::convertFromSceneUnits(size, Worksheet::Unit::Point) );
 1486     m_initializing = false;
 1487 }
 1488 void HistogramDock::curveSymbolsRotationAngleChanged(qreal angle) {
 1489     m_initializing = true;
 1490     ui.sbSymbolRotation->setValue(angle);
 1491     m_initializing = false;
 1492 }
 1493 void HistogramDock::curveSymbolsOpacityChanged(qreal opacity) {
 1494     m_initializing = true;
 1495     ui.sbSymbolOpacity->setValue( round(opacity*100.0) );
 1496     m_initializing = false;
 1497 }
 1498 void HistogramDock::curveSymbolsBrushChanged(const QBrush& brush) {
 1499     m_initializing = true;
 1500     ui.cbSymbolFillingStyle->setCurrentIndex((int) brush.style());
 1501     ui.kcbSymbolFillingColor->setColor(brush.color());
 1502     GuiTools::updateBrushStyles(ui.cbSymbolFillingStyle, brush.color());
 1503     m_initializing = false;
 1504 }
 1505 void HistogramDock::curveSymbolsPenChanged(const QPen& pen) {
 1506     m_initializing = true;
 1507     ui.cbSymbolBorderStyle->setCurrentIndex( (int) pen.style());
 1508     ui.kcbSymbolBorderColor->setColor( pen.color());
 1509     GuiTools::updatePenStyles(ui.cbSymbolBorderStyle, pen.color());
 1510     ui.sbSymbolBorderWidth->setValue( Worksheet::convertFromSceneUnits(pen.widthF(), Worksheet::Unit::Point));
 1511     m_initializing = false;
 1512 }
 1513 
 1514 //Values-Tab
 1515 void HistogramDock::curveValuesTypeChanged(Histogram::ValuesType type) {
 1516     m_initializing = true;
 1517     ui.cbValuesType->setCurrentIndex((int) type);
 1518     m_initializing = false;
 1519 }
 1520 void HistogramDock::curveValuesColumnChanged(const AbstractColumn* column) {
 1521     m_initializing = true;
 1522     this->setModelIndexFromColumn(cbValuesColumn, column);
 1523     m_initializing = false;
 1524 }
 1525 void HistogramDock::curveValuesPositionChanged(Histogram::ValuesPosition position) {
 1526     m_initializing = true;
 1527     ui.cbValuesPosition->setCurrentIndex((int) position);
 1528     m_initializing = false;
 1529 }
 1530 void HistogramDock::curveValuesDistanceChanged(qreal distance) {
 1531     m_initializing = true;
 1532     ui.sbValuesDistance->setValue( Worksheet::convertFromSceneUnits(distance, Worksheet::Unit::Point) );
 1533     m_initializing = false;
 1534 }
 1535 void HistogramDock::curveValuesRotationAngleChanged(qreal angle) {
 1536     m_initializing = true;
 1537     ui.sbValuesRotation->setValue(angle);
 1538     m_initializing = false;
 1539 }
 1540 void HistogramDock::curveValuesOpacityChanged(qreal opacity) {
 1541     m_initializing = true;
 1542     ui.sbValuesOpacity->setValue( round(opacity*100.0) );
 1543     m_initializing = false;
 1544 }
 1545 void HistogramDock::curveValuesNumericFormatChanged(char format) {
 1546     m_initializing = true;
 1547     ui.cbValuesNumericFormat->setCurrentIndex(ui.cbValuesNumericFormat->findData(format));
 1548     m_initializing = false;
 1549 }
 1550 void HistogramDock::curveValuesPrecisionChanged(int precision) {
 1551     m_initializing = true;
 1552     ui.sbValuesPrecision->setValue(precision);
 1553     m_initializing = false;
 1554 }
 1555 void HistogramDock::curveValuesDateTimeFormatChanged(const QString& format) {
 1556     m_initializing = true;
 1557     ui.cbValuesDateTimeFormat->setCurrentText(format);
 1558     m_initializing = false;
 1559 }
 1560 void HistogramDock::curveValuesPrefixChanged(const QString& prefix) {
 1561     m_initializing = true;
 1562     ui.leValuesPrefix->setText(prefix);
 1563     m_initializing = false;
 1564 }
 1565 void HistogramDock::curveValuesSuffixChanged(const QString& suffix) {
 1566     m_initializing = true;
 1567     ui.leValuesSuffix->setText(suffix);
 1568     m_initializing = false;
 1569 }
 1570 void HistogramDock::curveValuesFontChanged(QFont font) {
 1571     m_initializing = true;
 1572     font.setPointSizeF( round(Worksheet::convertFromSceneUnits(font.pixelSize(), Worksheet::Unit::Point)) );
 1573     ui.kfrValuesFont->setFont(font);
 1574     m_initializing = false;
 1575 }
 1576 void HistogramDock::curveValuesColorChanged(QColor color) {
 1577     m_initializing = true;
 1578     ui.kcbValuesColor->setColor(color);
 1579     m_initializing = false;
 1580 }
 1581 
 1582 void HistogramDock::curveVisibilityChanged(bool on) {
 1583     m_initializing = true;
 1584     ui.chkVisible->setChecked(on);
 1585     m_initializing = false;
 1586 }
 1587 
 1588 //Filling
 1589 void HistogramDock::curveFillingEnabledChanged(bool status) {
 1590     m_initializing = true;
 1591     ui.chkFillingEnabled->setChecked(status);
 1592     m_initializing = false;
 1593 }
 1594 void HistogramDock::curveFillingTypeChanged(PlotArea::BackgroundType type) {
 1595     m_initializing = true;
 1596     ui.cbFillingType->setCurrentIndex(static_cast<int>(type));
 1597     m_initializing = false;
 1598 }
 1599 void HistogramDock::curveFillingColorStyleChanged(PlotArea::BackgroundColorStyle style) {
 1600     m_initializing = true;
 1601     ui.cbFillingColorStyle->setCurrentIndex(static_cast<int>(style));
 1602     m_initializing = false;
 1603 }
 1604 void HistogramDock::curveFillingImageStyleChanged(PlotArea::BackgroundImageStyle style) {
 1605     m_initializing = true;
 1606     ui.cbFillingImageStyle->setCurrentIndex(static_cast<int>(style));
 1607     m_initializing = false;
 1608 }
 1609 void HistogramDock::curveFillingBrushStyleChanged(Qt::BrushStyle style) {
 1610     m_initializing = true;
 1611     ui.cbFillingBrushStyle->setCurrentIndex(style);
 1612     m_initializing = false;
 1613 }
 1614 void HistogramDock::curveFillingFirstColorChanged(QColor& color) {
 1615     m_initializing = true;
 1616     ui.kcbFillingFirstColor->setColor(color);
 1617     m_initializing = false;
 1618 }
 1619 void HistogramDock::curveFillingSecondColorChanged(QColor& color) {
 1620     m_initializing = true;
 1621     ui.kcbFillingSecondColor->setColor(color);
 1622     m_initializing = false;
 1623 }
 1624 void HistogramDock::curveFillingFileNameChanged(QString& filename) {
 1625     m_initializing = true;
 1626     ui.leFillingFileName->setText(filename);
 1627     m_initializing = false;
 1628 }
 1629 void HistogramDock::curveFillingOpacityChanged(double opacity) {
 1630     m_initializing = true;
 1631     ui.sbFillingOpacity->setValue( round(opacity*100.0) );
 1632     m_initializing = false;
 1633 }
 1634 
 1635 //"Error bars"-Tab
 1636 void HistogramDock::curveErrorTypeChanged(Histogram::ErrorType type) {
 1637     m_initializing = true;
 1638     ui.cbErrorType->setCurrentIndex((int)type);
 1639     m_initializing = false;
 1640 }
 1641 void HistogramDock::curveErrorBarsCapSizeChanged(qreal size) {
 1642     m_initializing = true;
 1643     ui.sbErrorBarsCapSize->setValue( Worksheet::convertFromSceneUnits(size, Worksheet::Unit::Point) );
 1644     m_initializing = false;
 1645 }
 1646 void HistogramDock::curveErrorBarsTypeChanged(XYCurve::ErrorBarsType type) {
 1647     m_initializing = true;
 1648     ui.cbErrorBarsType->setCurrentIndex(static_cast<int>(type));
 1649     m_initializing = false;
 1650 }
 1651 void HistogramDock::curveErrorBarsPenChanged(const QPen& pen) {
 1652     m_initializing = true;
 1653     ui.cbErrorBarsStyle->setCurrentIndex( (int) pen.style());
 1654     ui.kcbErrorBarsColor->setColor( pen.color());
 1655     GuiTools::updatePenStyles(ui.cbErrorBarsStyle, pen.color());
 1656     ui.sbErrorBarsWidth->setValue( Worksheet::convertFromSceneUnits(pen.widthF(),Worksheet::Unit::Point) );
 1657     m_initializing = false;
 1658 }
 1659 void HistogramDock::curveErrorBarsOpacityChanged(qreal opacity) {
 1660     m_initializing = true;
 1661     ui.sbErrorBarsOpacity->setValue( round(opacity*100.0) );
 1662     m_initializing = false;
 1663 }
 1664 
 1665 //*************************************************************
 1666 //************************* Settings **************************
 1667 //*************************************************************
 1668 void HistogramDock::loadConfig(KConfig& config) {
 1669     KConfigGroup group = config.group(QLatin1String("Histogram"));
 1670 
 1671     //General
 1672     //we don't load/save the settings in the general-tab, since they are not style related.
 1673     //It doesn't make sense to load/save them in the template.
 1674     //This data is read in HistogramDock::setCurves().
 1675 
 1676     //Line
 1677     ui.cbLineType->setCurrentIndex( group.readEntry("LineType", (int) m_curve->lineType()) );
 1678     ui.cbLineStyle->setCurrentIndex( group.readEntry("LineStyle", (int) m_curve->linePen().style()) );
 1679     ui.kcbLineColor->setColor( group.readEntry("LineColor", m_curve->linePen().color()) );
 1680     ui.sbLineWidth->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LineWidth", m_curve->linePen().widthF()), Worksheet::Unit::Point) );
 1681     ui.sbLineOpacity->setValue( round(group.readEntry("LineOpacity", m_curve->lineOpacity())*100.0) );
 1682 
 1683     //Symbols
 1684     ui.cbSymbolStyle->setCurrentIndex( group.readEntry("SymbolStyle", (int)m_curve->symbolsStyle()) );
 1685     ui.sbSymbolSize->setValue( Worksheet::convertFromSceneUnits(group.readEntry("SymbolSize", m_curve->symbolsSize()), Worksheet::Unit::Point) );
 1686     ui.sbSymbolRotation->setValue( group.readEntry("SymbolRotation", m_curve->symbolsRotationAngle()) );
 1687     ui.sbSymbolOpacity->setValue( round(group.readEntry("SymbolOpacity", m_curve->symbolsOpacity())*100.0) );
 1688     ui.cbSymbolFillingStyle->setCurrentIndex( group.readEntry("SymbolFillingStyle", (int) m_curve->symbolsBrush().style()) );
 1689     ui.kcbSymbolFillingColor->setColor(  group.readEntry("SymbolFillingColor", m_curve->symbolsBrush().color()) );
 1690     ui.cbSymbolBorderStyle->setCurrentIndex( group.readEntry("SymbolBorderStyle", (int) m_curve->symbolsPen().style()) );
 1691     ui.kcbSymbolBorderColor->setColor( group.readEntry("SymbolBorderColor", m_curve->symbolsPen().color()) );
 1692     ui.sbSymbolBorderWidth->setValue( Worksheet::convertFromSceneUnits(group.readEntry("SymbolBorderWidth",m_curve->symbolsPen().widthF()), Worksheet::Unit::Point) );
 1693 
 1694     //Values
 1695     ui.cbValuesType->setCurrentIndex( group.readEntry("ValuesType", (int) m_curve->valuesType()) );
 1696     ui.cbValuesPosition->setCurrentIndex( group.readEntry("ValuesPosition", (int) m_curve->valuesPosition()) );
 1697     ui.sbValuesDistance->setValue( Worksheet::convertFromSceneUnits(group.readEntry("ValuesDistance", m_curve->valuesDistance()), Worksheet::Unit::Point) );
 1698     ui.sbValuesRotation->setValue( group.readEntry("ValuesRotation", m_curve->valuesRotationAngle()) );
 1699     ui.sbValuesOpacity->setValue( round(group.readEntry("ValuesOpacity",m_curve->valuesOpacity())*100.0) );
 1700     this->updateValuesWidgets();
 1701     ui.leValuesPrefix->setText( group.readEntry("ValuesPrefix", m_curve->valuesPrefix()) );
 1702     ui.leValuesSuffix->setText( group.readEntry("ValuesSuffix", m_curve->valuesSuffix()) );
 1703     QFont valuesFont = m_curve->valuesFont();
 1704     valuesFont.setPointSizeF( round(Worksheet::convertFromSceneUnits(valuesFont.pixelSize(), Worksheet::Unit::Point)) );
 1705     ui.kfrValuesFont->setFont( group.readEntry("ValuesFont", valuesFont) );
 1706     ui.kcbValuesColor->setColor( group.readEntry("ValuesColor", m_curve->valuesColor()) );
 1707 
 1708     //Filling
 1709     ui.chkFillingEnabled->setChecked( group.readEntry("FillingEnabled", m_curve->fillingEnabled()) );
 1710     ui.cbFillingType->setCurrentIndex( group.readEntry("FillingType", (int) m_curve->fillingType()) );
 1711     ui.cbFillingColorStyle->setCurrentIndex( group.readEntry("FillingColorStyle", (int) m_curve->fillingColorStyle()) );
 1712     ui.cbFillingImageStyle->setCurrentIndex( group.readEntry("FillingImageStyle", (int) m_curve->fillingImageStyle()) );
 1713     ui.cbFillingBrushStyle->setCurrentIndex( group.readEntry("FillingBrushStyle", (int) m_curve->fillingBrushStyle()) );
 1714     ui.leFillingFileName->setText( group.readEntry("FillingFileName", m_curve->fillingFileName()) );
 1715     ui.kcbFillingFirstColor->setColor( group.readEntry("FillingFirstColor", m_curve->fillingFirstColor()) );
 1716     ui.kcbFillingSecondColor->setColor( group.readEntry("FillingSecondColor", m_curve->fillingSecondColor()) );
 1717     ui.sbFillingOpacity->setValue( round(group.readEntry("FillingOpacity", m_curve->fillingOpacity())*100.0) );
 1718     fillingEnabledChanged(ui.chkFillingEnabled->isChecked()); //update the box filling widgets
 1719 
 1720     //Error bars
 1721     ui.cbErrorType->setCurrentIndex( group.readEntry("ErrorType", (int) m_curve->errorType()) );
 1722     ui.cbErrorBarsType->setCurrentIndex( group.readEntry("ErrorBarsType", (int) m_curve->errorBarsType()) );
 1723     ui.sbErrorBarsCapSize->setValue( Worksheet::convertFromSceneUnits(group.readEntry("ErrorBarsCapSize", m_curve->errorBarsCapSize()), Worksheet::Unit::Point) );
 1724     ui.cbErrorBarsStyle->setCurrentIndex( group.readEntry("ErrorBarsStyle", (int) m_curve->errorBarsPen().style()) );
 1725     ui.kcbErrorBarsColor->setColor( group.readEntry("ErrorBarsColor", m_curve->errorBarsPen().color()) );
 1726     ui.sbErrorBarsWidth->setValue( Worksheet::convertFromSceneUnits(group.readEntry("ErrorBarsWidth", m_curve->errorBarsPen().widthF()),Worksheet::Unit::Point) );
 1727     ui.sbErrorBarsOpacity->setValue( round(group.readEntry("ErrorBarsOpacity", m_curve->errorBarsOpacity())*100.0) );
 1728 }
 1729 
 1730 void HistogramDock::loadConfigFromTemplate(KConfig& config) {
 1731     //extract the name of the template from the file name
 1732     QString name;
 1733     int index = config.name().lastIndexOf(QLatin1String("/"));
 1734     if (index != -1)
 1735         name = config.name().right(config.name().size() - index - 1);
 1736     else
 1737         name = config.name();
 1738 
 1739     int size = m_curvesList.size();
 1740     if (size > 1)
 1741         m_curve->beginMacro(i18n("%1 xy-curves: template \"%2\" loaded", size, name));
 1742     else
 1743         m_curve->beginMacro(i18n("%1: template \"%2\" loaded", m_curve->name(), name));
 1744 
 1745     this->loadConfig(config);
 1746 
 1747     m_curve->endMacro();
 1748 }
 1749 
 1750 void HistogramDock::saveConfigAsTemplate(KConfig& config) {
 1751     KConfigGroup group = config.group( "Histogram" );
 1752 
 1753     //Line
 1754     group.writeEntry("LineType", ui.cbLineType->currentIndex());
 1755     group.writeEntry("LineStyle", ui.cbLineStyle->currentIndex());
 1756     group.writeEntry("LineColor", ui.kcbLineColor->color());
 1757     group.writeEntry("LineWidth", Worksheet::convertToSceneUnits(ui.sbLineWidth->value(), Worksheet::Unit::Point));
 1758     group.writeEntry("LineOpacity", ui.sbLineOpacity->value()/100.0);
 1759 
 1760     //Values
 1761     group.writeEntry("ValuesType", ui.cbValuesType->currentIndex());
 1762     group.writeEntry("ValuesPosition", ui.cbValuesPosition->currentIndex());
 1763     group.writeEntry("ValuesDistance", Worksheet::convertToSceneUnits(ui.sbValuesDistance->value(), Worksheet::Unit::Point));
 1764     group.writeEntry("ValuesRotation", ui.sbValuesRotation->value());
 1765     group.writeEntry("ValuesOpacity", ui.sbValuesOpacity->value()/100.0);
 1766     group.writeEntry("ValuesPrefix", ui.leValuesPrefix->text());
 1767     group.writeEntry("ValuesSuffix", ui.leValuesSuffix->text());
 1768     group.writeEntry("ValuesFont", ui.kfrValuesFont->font());
 1769     group.writeEntry("ValuesColor", ui.kcbValuesColor->color());
 1770 
 1771     //Filling
 1772     group.writeEntry("FillingEnabled", ui.chkFillingEnabled->isChecked());
 1773     group.writeEntry("FillingType", ui.cbFillingType->currentIndex());
 1774     group.writeEntry("FillingColorStyle", ui.cbFillingColorStyle->currentIndex());
 1775     group.writeEntry("FillingImageStyle", ui.cbFillingImageStyle->currentIndex());
 1776     group.writeEntry("FillingBrushStyle", ui.cbFillingBrushStyle->currentIndex());
 1777     group.writeEntry("FillingFileName", ui.leFillingFileName->text());
 1778     group.writeEntry("FillingFirstColor", ui.kcbFillingFirstColor->color());
 1779     group.writeEntry("FillingSecondColor", ui.kcbFillingSecondColor->color());
 1780     group.writeEntry("FillingOpacity", ui.sbFillingOpacity->value()/100.0);
 1781 
 1782     config.sync();
 1783 }