Skip to content

create QVTKTableModelAdapter

Goal: Provide an adapter for QAbstractItemModel to vtkTable

Qt's QAbstractItemModel provides functionality to connect data from a source to a view, like a table view etc. The Qt library provides plotting features via its QtCharts modules; however these are either GPL or require a commercial license. I have so far not found a good 3rd party library to create charts using widgets in Qt.

The 2D charts/plots in vtk are great though a little bit under-developed. My intention here is to provide a coupling mechanism from a generic QAbstractItemModel to create a vtkTable output. This output can then be used directly in vtkPlot subclasses, or be used as an input to vtkTableAlgorithm to further modify the output prior to plotting or creating other useful data from it.

In order to get this working I had to work on several classes in vtk. While doing so I took the time to cleanup some of theses classes; especially vtkPlot subclasses were quite fragmented and repetitive. I understand that this commit is now rather large; however it passes the current tests so we can think about how to merge it into the main branch by doing it either directly or creating multiple merge requests on parts of this commit.

The major changes:

vtkPlot and subclasses

vtkPlot subclasses want to make use of a cache to generate internal data structures. The handling of these caches and when to update them was quite fragmented. I have unified the handling; the vtkPlot::Update() method now calls on a new method vtkPlot::CacheRequiresUpdate(). If a cache update is required then vtkPlot::UpdateCache() is called. Subclasses now make use of this unified framework where possible.

Further I have added vtkPlot::SetInputConnection() and vtkPlot::GetInputConnection() methods so plots can now make use of vtkAlgorithmOutput from 'vtkTableAlgorithm' to fully make use of a filter pipeline. I have added a test to TestLinePlot to test the pipeline principle.

vtkTable

I added more methods to vtkTable to allow insertion and removal of both rows and columns while preserving the existing data. Removal of a single row was already possible before, but I generalized it to n rows for efficiency. Insertion works similar; to avoid code duplication I introduced a new protected vtkTable::MoveRowData method which handles shifting the data for both removal and insertion cases.

Further I have done some cleanup on both vtkTable and classes which were using it. The basic class documentation says direct access to vtkTable::RowData should be avoided, so I replaced some calls from other classes with the more appropriate methods, like using vtkTable::GetColumn() instead of vtkTable::GetRowData()->GetArray().

QVTKTableModelAdapter

This is the new class to provide a vtkTable output to a QAbstractItemModel. Note I have named this 'QVTKTableModelAdapter' since it links to a 'vtkTable'; however the input is a 'QAbstractItemModel' so it can work with proxy filter models as well.

The new class keeps an internal vtkTable as a buffer which it updates whenever the Qt item model changes.

Todo:

Please have a look over the proposed changes and additions. We should then decide if we want to approach a direct merge or doing it in parts, i.e. I could create new topic branches for each of the changes and we can take it from there.

Also I would like to write some a test for QVTKTableModelAdapter; however that requires a running Qt application which processes the signals. I have not found an existing test involving this, so please point me to the right direction there. Alternatively I have a working example which I could add to the example collection.

Edited by Peter Franz

Merge request reports