Commit 623f96c2 authored by Norby, Tom's avatar Norby, Tom

Reconcile qcustomplot version changes.

parent e144ec26
Pipeline #75867 failed with stages
in 2 minutes and 34 seconds
......@@ -63,7 +63,7 @@ MainWindow::MainWindow(QWidget *parent)
}
void MainWindow::changeDemo(const QModelIndex &current,
const QModelIndex &preivous)
const QModelIndex &previous)
{
int demoIndex = current.row();
// stop timer
......@@ -114,8 +114,8 @@ void MainWindow::setupQuadraticDemo()
{
demoName = "Quadratic Demo";
// generate some data:
std::vector<double> x(101), y(101); // initialize with entries 0..100
for (size_t i = 0; i < 101; ++i)
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
x[i] = i / 50.0 - 1; // x goes from -1 to 1
y[i] = x[i] * x[i]; // let's plot a quadratic function
......@@ -168,8 +168,12 @@ void MainWindow::setupSimpleDemo()
connect(plot->yAxis(), SIGNAL(rangeChanged(QCPRange)), plot->yAxis2(),
SLOT(setRange(QCPRange)));
// pass data points to graphs:
sp_graph0->setData(x, y0);
sp_graph1->setData(x, y1);
QVector<double> qx, qy0, qy1;
qx.fromStdVector(x);
qy0.fromStdVector(y0);
qy1.fromStdVector(y1);
sp_graph0->setData(qx, qy0);
sp_graph1->setData(qx, qy1);
// let the ranges scale themselves so graph 0 fits perfectly
// in the visible area:
sp_graph0->rescaleAxes();
......@@ -186,6 +190,7 @@ void MainWindow::setupSimpleDemo()
void MainWindow::setupSincScatterDemo()
{
demoName = "Sinc Scatter Demo";
plot->legend()->setVisible(true);
plot->legend()->setFont(QFont("Helvetica", 9));
// set locale to english, so we get english decimal separator:
plot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
......@@ -217,17 +222,23 @@ void MainWindow::setupSincScatterDemo()
sp_graph4->setPen(QPen(Qt::blue));
sp_graph4->setLineStyle(QCPGraph::lsNone);
sp_graph4->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4));
sp_graph4->setErrorType(QCPGraph::etValue);
sp_graph4->setErrorPen(QPen(QColor(180, 180, 180)));
// add error bars:
QCPAxis *xaxis = plot->xAxis();
QCPAxis *yaxis = plot->yAxis();
QCPErrorBars *errorBars = new QCPErrorBars(xaxis, yaxis);
errorBars->removeFromLegend();
errorBars->setAntialiased(false);
errorBars->setDataPlottable((QCPAbstractPlottable *) sp_graph4->graph());
errorBars->setPen(QPen(QColor(180,180,180)));
sp_graph4->setName("Measurement");
//
// generate ideal sinc curve data and some randomly perturbed data
// for scatter plot:
//
std::vector<double> x0(250), y0(250);
std::vector<double> yConfUpper(250), yConfLower(250);
for (size_t i = 0; i < 250; ++i)
QVector<double> x0(250), y0(250);
QVector<double> yConfUpper(250), yConfLower(250);
for (int i=0; i<250; ++i)
{
//
// by adding a small offset(0.01) we make sure not do divide by zero
......@@ -238,8 +249,8 @@ void MainWindow::setupSincScatterDemo()
yConfLower[i] = y0[i] - 0.15;
x0[i] *= 1000;
}
std::vector<double> x1(50), y1(50), y1err(50);
for (size_t i = 0; i < 50; ++i)
QVector<double> x1(50), y1(50), y1err(50);
for (int i=0; i<50; ++i)
{
// generate a gaussian distributed random number:
double tmp1 = rand() / (double)RAND_MAX;
......@@ -263,12 +274,12 @@ void MainWindow::setupSincScatterDemo()
sp_graph1->setData(x0, yConfUpper);
sp_graph2->setData(x0, yConfLower);
sp_graph3->setData(x0, y0);
sp_graph4->setDataValueError(x1, y1, y1err);
errorBars->setData(y1err);
sp_graph3->rescaleAxes();
sp_graph4->rescaleAxes(true);
// setup look of bottom tick labels:
plot->xAxis()->setTickLabelRotation(30);
plot->xAxis()->setAutoTickCount(9);
//plot->xAxis()->setAutoTickCount(9);
plot->xAxis()->setNumberFormat("ebc");
plot->xAxis()->setNumberPrecision(1);
plot->xAxis()->moveRange(-10);
......@@ -315,8 +326,8 @@ void MainWindow::setupScatterStyleDemo()
//
// generate data:
//
std::vector<double> x(10), y(10);
for (size_t k = 0; k < 10; ++k)
QVector<double> x(10), y(10);
for (int k=0; k<10; ++k)
{
x[k] = k / 10.0 * 4 * 3.14 + 0.01;
y[k] = 7 * qSin(x[k]) / x[k] + (shapes.size() - i) * 5;
......@@ -396,7 +407,7 @@ void MainWindow::setupLineStyleDemo()
//
// generate data:
//
std::vector<double> x(15), y(15);
QVector<double> x(15), y(15);
for (int j = 0; j < 15; ++j)
{
x[j] = j / 15.0 * 5 * 3.14 + 0.01;
......@@ -476,7 +487,10 @@ void MainWindow::setupDiscontinuousLineDemo()
y[j] = 7 * qSin(x[j]) / x[j] - (i - QCPGraph::lsNone) * 5 +
(QCPGraph::lsImpulse)*5 + 2;
}
graph->setData(x, y);
QVector<double> qx, qy;
qx.fromStdVector(x);
qy.fromStdVector(y);
graph->setData(qx, qy);
graph->rescaleAxes(true);
}
......@@ -516,34 +530,34 @@ void MainWindow::setupDateDemo()
graph->setPen(pen);
graph->setBrush(QBrush(QColor(255 / 4.0 * gi, 160, 50, 150)));
// generate random walk data:
std::vector<double> time(250), value(250);
QVector<QCPGraphData> timeData(250);
for (int i = 0; i < 250; ++i)
{
time[i] = now + 24 * 3600 * i;
timeData[i].key = now + 24*3600*i;
if (i == 0)
value[i] = (i / 50.0 + 1) * (rand() / (double)RAND_MAX - 0.5);
timeData[i].value = (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
else
value[i] = qFabs(value[i - 1]) * (1 + 0.02 / 4.0 * (4 - gi)) +
timeData[i].value = qFabs(timeData[i-1].value)*(1+0.02/4.0*(4-gi)) +
(i / 50.0 + 1) * (rand() / (double)RAND_MAX - 0.5);
}
graph->setData(time, value);
//graph->data->set(timeData);
}
// configure bottom axis to show date and time instead of number:
plot->xAxis()->setTickLabelType(QCPAxis::ltDateTime);
plot->xAxis()->setDateTimeFormat("MMMM\nyyyy");
//plot->xAxis()->setTickLabelType(QCPAxis::ltDateTime);
//plot->xAxis()->setDateTimeFormat("MMMM\nyyyy");
// set a more compact font size for bottom and left axis tick labels:
plot->xAxis()->setTickLabelFont(QFont(QFont().family(), 8));
plot->yAxis()->setTickLabelFont(QFont(QFont().family(), 8));
// set a fixed tick-step to one tick per month:
plot->xAxis()->setAutoTickStep(false);
plot->xAxis()->setTickStep(2628000); // one month in seconds
plot->xAxis()->setSubTickCount(3);
//plot->xAxis()->setAutoTickStep(false);
//plot->xAxis()->setTickStep(2628000); // one month in seconds
//plot->xAxis()->setSubTickCount(3);
// apply manual tick and tick label for left axis:
plot->yAxis()->setAutoTicks(false);
plot->yAxis()->setAutoTickLabels(false);
plot->yAxis()->setTickVector(QVector<double>() << 5 << 55);
plot->yAxis()->setTickVectorLabels(QVector<QString>() << "Not so\nhigh"
<< "Very\nhigh");
//plot->yAxis()->setAutoTicks(false);
//plot->yAxis()->setAutoTickLabels(false);
//plot->yAxis()->setTickVector(QVector<double>() << 5 << 55);
//plot->yAxis()->setTickVectorLabels(QVector<QString>() << "Not so\nhigh"
// << "Very\nhigh");
// set axis labels:
plot->xAxis()->setLabel("Date");
plot->yAxis()->setLabel("Random wobbly lines value");
......
This diff is collapsed.
......@@ -32,14 +32,27 @@ class Graph2D
* @brief qcpgraph pointer to QCPGraph
*/
QCPGraph *qcpgraph;
/**
* @brief qcperrorbar_key pointer to data in QCPErrorBars
*/
QCPErrorBars *qcperrorbar_key;
/**
* @brief qcperrorbar_value pointer to data in QCPErrorBars
*/
QCPErrorBars *qcperrorbar_value;
/**
* @brief dataMap pointer to data in QCPGraph
*/
QCPDataMap *dataMap;
QSharedPointer<QCPGraphDataContainer> dataMap;
/**
* @brief keyUnit QString type
*/
QString keyUnit;
/**
* @brief valueUnit QString type
*/
......@@ -128,9 +141,9 @@ class Graph2D
/**
* @brief setErrorType set the error type
* @param type QCPGraph::ErrorType
* @param type QCPErrorBars::ErrorType
*/
void setErrorType(QCPGraph::ErrorType type);
void setErrorType(QCPErrorBars::ErrorType type);
/**
* @brief setErrorPen set the pen which draws the error
......@@ -140,75 +153,75 @@ class Graph2D
/**
* @brief setData Sets the key and value data
* @param key const VecDouble&
* @param value const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
*/
void setData(const VecDouble &key, const VecDouble &value);
void setData(const QVector<double> keys, const QVector<double> values);
/**
* @brief setDataKeyError Sets the key and value data and keyerror
* @param key const VecDouble&
* @param value const VecDouble&
* @param keyError const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param keyError const QVector<double>&
*/
void setDataKeyError(const VecDouble &key, const VecDouble &value,
const VecDouble &keyError);
void setDataKeyError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &keyError);
/**
* @brief setDataKeyError Sets the key and value data and keyerror - & +
* @param key const VecDouble&
* @param value const VecDouble&
* @param keyErrorMinus const VecDouble&
* @param keyErrorPlus const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param keyErrorMinus const QVector<double>&
* @param keyErrorPlus const QVector<double>&
*/
void setDataKeyError(const VecDouble &key, const VecDouble &value,
const VecDouble &keyErrorMinus,
const VecDouble &keyErrorPlus);
void setDataKeyError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &keyErrorMinus,
const QVector<double> &keyErrorPlus);
/**
* @brief setDataValueError Sets the key and value data and value error
* @param key const VecDouble&
* @param value const VecDouble&
* @param valueError const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param valueError const QVector<double>&
*/
void setDataValueError(const VecDouble &key, const VecDouble &value,
const VecDouble &valueError);
void setDataValueError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &valueError);
/**
* @brief setDataValueError Sets the key and value data and value error - & +
* @param key const VecDouble&
* @param value const VecDouble&
* @param valueErrorMinus const VecDouble&
* @param valueErrorPlus const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param valueErrorMinus const QVector<double>&
* @param valueErrorPlus const QVector<double>&
*/
void setDataValueError(const VecDouble &key, const VecDouble &value,
const VecDouble &valueErrorMinus,
const VecDouble &valueErrorPlus);
void setDataValueError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &valueErrorMinus,
const QVector<double> &valueErrorPlus);
/**
* @brief setDataBothError Sets the key and value data with key error and
* value error
* @param key const VecDouble&
* @param value const VecDouble&
* @param keyError const VecDouble&
* @param valueError const VecDouble&
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param keyError const QVector<double>&
* @param valueError const QVector<double>&
*/
void setDataBothError(const VecDouble &key, const VecDouble &value,
const VecDouble &keyError, const VecDouble &valueError);
void setDataBothError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &keyError, const QVector<double> &valueError);
/**
* @brief setDataBothError Sets the key and value data with key error and
* value error
* @param key const VecDouble&
* @param value const VecDouble&
* @param keyError const VecDouble&
* @param valueError const VecDouble&
*/
void setDataBothError(const VecDouble &key, const VecDouble &value,
const VecDouble &keyErrorMinus,
const VecDouble &keyErrorPlus,
const VecDouble &valueErrorMinus,
const VecDouble &valueErrorPlus);
* @param key const QVector<double>&
* @param value const QVector<double>&
* @param keyError const QVector<double>&
* @param valueError const QVector<double>&
*/
void setDataBothError(const QVector<double> &key, const QVector<double> &value,
const QVector<double> &keyErrorMinus,
const QVector<double> &keyErrorPlus,
const QVector<double> &valueErrorMinus,
const QVector<double> &valueErrorPlus);
/**
* Let Plot access Graph2D members/methods
......
......@@ -46,7 +46,7 @@ Plot::Plot(bool removablePlottables, QWidget *parent)
, mContextMenu(nullptr)
, mLegendDrag(false)
, qcplot(nullptr)
, title(nullptr)
, text(nullptr)
{
initPlot();
......@@ -286,10 +286,10 @@ QCPLegend *Plot::legend()
return qcplot->legend; // Plot::legend
}
QCPPlotTitle *Plot::qcpPlotTitle() const { return title; }
QCPTextElement *Plot::qcpPlotTitle() const { return text; }
void Plot::setPlotTitle(QString title)
{
this->title->setText(title);
this->text->setText(title);
qcplot->replot();
emit titleChanged(this);
}
......@@ -325,7 +325,7 @@ void Plot::addData(const KeyIndexHash &hash, QCPGraph *graph,
QVector<double> &errorHigh)
{
// graph data
QCPDataMap *data = graph->data();
QSharedPointer<QCPGraphDataContainer> data = graph->data();
if (data == nullptr)
{
......@@ -336,7 +336,7 @@ void Plot::addData(const KeyIndexHash &hash, QCPGraph *graph,
bool hasErrors = false;
// add y-values
for (const QCPData &datum : *data)
for (const QCPGraphData &datum : *data)
{
// find key
auto it = hash.find(datum.key);
......@@ -345,7 +345,7 @@ void Plot::addData(const KeyIndexHash &hash, QCPGraph *graph,
if (!hasErrors)
{
hasErrors |= datum.valueErrorMinus > 0 || datum.valueErrorPlus > 0;
//hasErrors |= datum.valueErrorMinus > 0 || datum.valueErrorPlus > 0;
}
}
......@@ -358,13 +358,13 @@ void Plot::addData(const KeyIndexHash &hash, QCPGraph *graph,
errorLow.fill(std::numeric_limits<double>::quiet_NaN());
errorHigh.fill(std::numeric_limits<double>::quiet_NaN());
for (const QCPData &datum : *data)
for (const QCPGraphData &datum : *data)
{
// find key
auto it = hash.find(datum.key);
errorLow[it->second] = datum.value - datum.valueErrorMinus;
errorHigh[it->second] = datum.value + datum.valueErrorPlus;
//errorLow[it->second] = datum.value - datum.valueErrorMinus;
//errorHigh[it->second] = datum.value + datum.valueErrorPlus;
}
}
}
......@@ -372,7 +372,7 @@ void Plot::addData(const KeyIndexHash &hash, QCPGraph *graph,
void Plot::addKeys(std::vector<double> &keys, QCPGraph *graph)
{
// graph data
QCPDataMap *data = graph->data();
QSharedPointer<QCPGraphDataContainer> data = graph->data();
if (data == nullptr)
{
......@@ -380,10 +380,10 @@ void Plot::addKeys(std::vector<double> &keys, QCPGraph *graph)
}
// add x-values to keys
for (const auto key : data->keys())
{
keys.push_back(key);
}
//for (const auto key : data->keys())
//{
// keys.push_back(key);
//}
}
void Plot::initContextMenu()
......@@ -422,7 +422,7 @@ void Plot::initPlot()
// init members
qcplot = new QCustomPlot();
label = new QCPItemText(qcplot);
title = new QCPPlotTitle(qcplot, "");
text = new QCPTextElement(qcplot, "");
// init label
QPen pen;
......@@ -440,7 +440,7 @@ void Plot::initPlot()
qcplot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
qcplot->plotLayout()->insertRow(0);
qcplot->plotLayout()->addElement(0, 0, title);
qcplot->plotLayout()->addElement(0, 0, text);
qcplot->legend->setVisible(true);
setFocusProxy(qcplot);
......@@ -457,8 +457,8 @@ void Plot::initPlot()
SLOT(mousePress(QMouseEvent *)));
connect(qcplot, SIGNAL(mouseRelease(QMouseEvent *)), this,
SLOT(mouseRelease(QMouseEvent *)));
connect(qcplot, SIGNAL(plottableClick(QCPAbstractPlottable *, QMouseEvent *)),
this, SLOT(plottableClicked(QCPAbstractPlottable *, QMouseEvent *)));
//connect(qcplot, SIGNAL(plottableClick(QCPAbstractPlottable *, QMouseEvent *)),
// this, SLOT(plottableClicked(QCPAbstractPlottable *, QMouseEvent *)));
connect(qcplot, SIGNAL(selectionChangedByUser()), this,
SLOT(selectionChanged()));
......@@ -467,28 +467,21 @@ void Plot::initPlot()
bool Plot::addPlottable(QCPAbstractPlottable *plottable)
{
// call default implementation
bool added = qcplot->addPlottable(plottable);
// legend item for the plottable
auto ali = qcplot->legend->itemWithPlottable(plottable);
// added successfully, so signal listeners
if (added)
// connect selection signals/slots
if (ali != nullptr)
{
// legend item for the plottable
auto ali = qcplot->legend->itemWithPlottable(plottable);
// connect selection signals/slots
if (ali != nullptr)
{
connect(plottable, SIGNAL(selectionChanged(bool)), ali,
SLOT(setSelected(bool)));
connect(ali, SIGNAL(selectionChanged(bool)), plottable,
SLOT(setSelected(bool)));
}
dataDirty = true;
connect(plottable, SIGNAL(selectionChanged(bool)), ali,
SLOT(setSelected(bool)));
connect(ali, SIGNAL(selectionChanged(bool)), plottable,
SLOT(setSelected(bool)));
}
return added;
dataDirty = true;
return true;
}
bool Plot::addPlottables(const std::vector<QCPAbstractPlottable *> &plottables)
......@@ -499,11 +492,6 @@ bool Plot::addPlottables(const std::vector<QCPAbstractPlottable *> &plottables)
// call default implementation
for (auto plottable : plottables)
{
if (!qcplot->addPlottable(plottable))
{
continue;
}
// legend item for the plottable
auto ali = qcplot->legend->itemWithPlottable(plottable);
......@@ -699,7 +687,7 @@ void Plot::selectionChanged()
if (item->selected() || graph->selected())
{
item->setSelected(true);
graph->setSelected(true);
//graph->setSelection(true);
}
}
}
......@@ -722,7 +710,7 @@ AxisPropertyManager::AxisPropertyManager(QObject *parent)
void AxisPropertyManager::dateFormatChanged(QtProperty *property, int value)
{
axis->setDateTimeFormat(dateFormatEnumToString.value(value));
//axis->setDateTimeFormat(dateFormatEnumToString.value(value));
axis->parentPlot()->replot();
}
......@@ -922,7 +910,7 @@ void AxisPropertyManager::manage(QtAbstractPropertyBrowser *pb,
subprop = tickLabelType->addProperty("Tick Label Type");
tickLabelType->setEnumNames(subprop, tickLabelNames);
tickLabelType->setValue(subprop, axis->tickLabelType());
//tickLabelType->setValue(subprop, axis->tickLabelType());
property->addSubProperty(subprop);
// axis number precision
......@@ -944,8 +932,8 @@ void AxisPropertyManager::manage(QtAbstractPropertyBrowser *pb,
subprop = dateFormat->addProperty("Tick Label Date/Time Format");
dateFormat->setEnumNames(subprop, dateFormatNames);
dateFormat->setValue(subprop,
stringToDateFormatEnum.value(axis->dateTimeFormat(), 0));
//dateFormat->setValue(subprop,
// stringToDateFormatEnum.value(axis->dateTimeFormat(), 0));
property->addSubProperty(subprop);
// connect signals/slots
......@@ -1033,7 +1021,7 @@ void AxisPropertyManager::tickLabelRotationChanged(QtProperty *property,
void AxisPropertyManager::tickLabelTypeChanged(QtProperty *property, int value)
{
axis->setTickLabelType(static_cast<QCPAxis::LabelType>(value));
//axis->setTickLabelType(static_cast<QCPAxis::LabelType>(value));
axis->parentPlot()->replot();
}
......@@ -1272,7 +1260,7 @@ void GraphPropertyManager::adaptiveSamplingChanged(QtProperty *property,
void GraphPropertyManager::errorBarsChanged(QtProperty *property, int value)
{
graph->setErrorType(static_cast<QCPGraph::ErrorType>(value));
errorBars->setErrorType(static_cast<QCPErrorBars::ErrorType>(value));
graph->parentPlot()->replot();
}
......@@ -1465,7 +1453,7 @@ void GraphPropertyManager::manage(QtAbstractPropertyBrowser *pb,
subprop = errorBars->addProperty("Error Bars");
errorBars->setEnumNames(subprop, errorBarNames);
errorBars->setValue(subprop, graph->errorType());
//errorBars->setValue(subprop, graph->errorType());
property->addSubProperty(subprop);
// connect signals/slots
......
......@@ -120,7 +120,7 @@ class Plot : public QWidget
* @brief qcpPlotTitle
* @return the Plot title for this plot
*/
QCPPlotTitle *qcpPlotTitle() const;
QCPTextElement *qcpPlotTitle() const;
/**
* @brief setPlotTitle Set the title of this plot
......@@ -254,7 +254,7 @@ class Plot : public QWidget
bool mLegendDrag;
QMenu *mSaveAsContextMenu;
QCustomPlot *qcplot;
QCPPlotTitle *title;
QCPTextElement *text;
QMap<QString, std::function<void(Graph2D::SP &)>> unitMappers;
}; // class Plot
......@@ -404,6 +404,8 @@ class GraphPropertyManager : public QObject
QCPGraph *graph;
QCPErrorBars *errorBars;
static QStringList lineStyleNames;
static QStringList penNames;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment