QCustomPlot Discussion and Comments

Missing Feature and BugsReturn to overview

Would it be possible for an insertPlottable function to be added in the future? Like so:

bool insertPlottable(int index, QCPAbstractPlottable *plottable)
    {
        if(mPlottables.contains(plottable))
        {
            qDebug() <<
            Q_FUNC_INFO <<
            "plottable already added to this QCustomPlot:" <<
            reinterpret_cast<quintptr>(plottable);

            return false;
        }

        if(plottable->parentPlot() != this)
        {
            qDebug() <<
            Q_FUNC_INFO <<
            "plottable not created with this QCustomPlot as parent:" <<
            reinterpret_cast<quintptr>(plottable);

            return false;
        }

        mPlottables.insert(index, plottable);

        if(mAutoAddPlottableToLegend)
        {
            plottable->addToLegend();
        }

        if(qobject_cast<QCPGraph *>(plottable))
        {
            mGraphs.insert(index, static_cast<QCPGraph *>(plottable));
        }

        if(!plottable->layer())
        {
            plottable->setLayer(currentLayer());
        }

        return true;
    }

Also, I've noticed that the new layout system doesn't completely remove all the area used by invisible layout items. For example, if I add a title to a plot and then hide that title, the title still causes some area to be taken anyway from the axis rect. For Qt Widgets on the other hand, the layout system completely removes the spacing, margins, etc. required for the hidden item.

Regarding the insertPlottable: What would be the purpose of this? If you want some plottables to be drawn above/below other plottables, the layering system is the right technique for that.

There are some differences between the Qt layout system and the QCustomPlot layout system. I'm not quite sure whether setting a layout element to invisible should collapse the layout, because in QCustomPlot the objects contained in the layout element don't necessarily become invisible with it (although it's like this in most cases due to the parentLayerable property which allows visibility hierarchies). I'll consider it for the next major QCP version though.
The solution right now should be easy though: Just remove it from the layout with QCPLayout::take. Once you need it again, re-insert it.

Having insert lets you treat the QCustomPlot interface more like a map. Using the layering system to insert a plottable is far more work than using the above function. It doesn't make sense to have a layer per plottable.

...

Making the layout collapse just makes coding easier also. Let's say you have a title on each plot that you'd like to dynamically turn off and on. You could delete the title when hiding it and then recreate it when showing it. Or... just make it not visible and collapse it.

---

I'm using QCustomPlot as the backend graphing library for a general purpose plotting tool I'm developing. The user can create create and delete graphs on the fly. Each graph can be addressed by a handle stored in a QMap. There's no restriction on what handles the user gives their graphs... so, they could create graphs with handles 0, 11, and 4. When the user creates a graph with handle value 4 it needs to appear between graphs 0 and 11. This is what I need insert for. The reason for such a handle system is because my tool accepts external commands from remote computers. To minimize handshaking, the external computer chooses the handle it wants to use to address graphs with instead of doing something like an FOpen where my tool has to send the external program the handle value.

Having items collapse in the layout is also useful for hiding legend items when plots have no name. Let's say the user creates a graph with an empty string for a name. If they do that then I hide the legend item. At any time they can set the name to be non-empty and I will show the legend item. Taking and removing items from the legend to support this is painful.

I would also like this feature as explained by Kwabena