4

Is there a direct way to pass QAbstractItemModel to QCustomPlot? Currently I am defining two QVector<double> for Xval and yVal. When I have to plot, I update these two vectors from QAbstractItemModel to launch the plot function.

Is there any way that QCustomPlot can accept QAbstractItemModel?

Nejat
  • 31,784
  • 12
  • 106
  • 138
Schwab
  • 91
  • 1
  • 6

1 Answers1

1

AFAIK there is not a direct support for QAbstractItemModel in QCustomPlot. I am not sure how you expect QCustomPlot to draw contents of a QAbstractItemModel. As you know the model could be a simple model or a complex one or even hierarchical. That's two much for a simple 2D plot like QCustomPlot. But there seems to be a way to assign data of a subclass of QAbstractItemModel to QCustomPlot and that's using QCPDataMap.

You should populate the data of your model in QCPDataMap and assign it to plot. That's something like :

QCPDataMap *data = new QCPDataMap();

for(int i=0; i<count; i++)
    data->insertMulti(data->constEnd(), x[i], QCPData(x[i], y[i]));

plot->graph()->setData(data);

You can generate QCPDataMap in your model using x and y values and assign it's pointer to plot.

Nejat
  • 31,784
  • 12
  • 106
  • 138