VTK  9.3.0
QVTKTableModelAdapter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
20 #ifndef QVTKTableModelAdapter_h
21 #define QVTKTableModelAdapter_h
22 
23 #include "vtkGUISupportQtModule.h" // For export macro
24 
25 #include <QAbstractItemModel>
26 #include <QObject>
27 #include <QPointer>
28 
29 #include "vtkNew.h" // For vtkNew
30 #include "vtkTable.h" // For vtkTable
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class VTKGUISUPPORTQT_EXPORT QVTKTableModelAdapter : public QObject
34 {
35  Q_OBJECT
36 public:
37  QVTKTableModelAdapter(QObject* parent = nullptr);
38  QVTKTableModelAdapter(QAbstractItemModel* model, QObject* parent = nullptr);
39 
41 
46  virtual void SetItemModel(QAbstractItemModel* model);
47  QAbstractItemModel* GetItemModel() const;
49 
54  vtkTable* GetTable() const;
55 
56 Q_SIGNALS:
61  void tableChanged();
62 
63 protected:
67  virtual QVariant modelData(int row, int col);
68 
74  virtual vtkAbstractArray* NewArray(const QVariant& type);
75 
79  virtual bool HasCorrectColumnArrays();
80 
84  virtual void SetCellValue(int row, int column, const QVariant& data);
85 
90  virtual void UpdateTable(int row0, int column0, int row1, int column1);
91 
92  QPointer<QAbstractItemModel> ItemModel;
94 
95 protected Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
96  virtual void onModified();
97  virtual void onModelReset();
98  virtual void onDataChanged(
99  const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
100  virtual void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
101  virtual void onLayoutChanged(
102  const QList<QPersistentModelIndex>& parents, QAbstractItemModel::LayoutChangeHint hint);
103  virtual void onRowsInserted(const QModelIndex& parent, int first, int last);
104  virtual void onRowsRemoved(const QModelIndex& parent, int first, int last);
105  virtual void onRowsMoved(
106  const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
107  virtual void onColumnsInserted(const QModelIndex& parent, int first, int last);
108  virtual void onColumnsRemoved(const QModelIndex& parent, int first, int last);
109  virtual void onColumnsMoved(
110  const QModelIndex& parent, int start, int end, const QModelIndex& destination, int column);
111 };
112 
113 VTK_ABI_NAMESPACE_END
114 #endif
An adapter to create a vtkTable from an QAbstractItemModel.
virtual void onColumnsInserted(const QModelIndex &parent, int first, int last)
void tableChanged()
Signal emitted when the internal vtkTable has changed.
QVTKTableModelAdapter(QObject *parent=nullptr)
virtual void onColumnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
QAbstractItemModel * GetItemModel() const
Get/set the Qt table model.
virtual void SetCellValue(int row, int column, const QVariant &data)
Sets the value of the cell given by row, column using the adequate QVariant type conversion.
virtual void onColumnsRemoved(const QModelIndex &parent, int first, int last)
virtual void onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
virtual void onModelReset()
virtual void UpdateTable(int row0, int column0, int row1, int column1)
Update the internal table from row0 to inclusive row1, and from column0 to inclusive column1 so it re...
virtual void SetItemModel(QAbstractItemModel *model)
Get/set the Qt table model.
virtual QVariant modelData(int row, int col)
The default method for retrieving data for a table entry from the item model.
vtkTable * GetTable() const
Access to the vtkTable.
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
vtkNew< vtkTable > Table
QVTKTableModelAdapter(QAbstractItemModel *model, QObject *parent=nullptr)
virtual void onRowsRemoved(const QModelIndex &parent, int first, int last)
virtual bool HasCorrectColumnArrays()
Check that the correct array types are set for the columns.
virtual void onRowsInserted(const QModelIndex &parent, int first, int last)
virtual void onLayoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
virtual void onModified()
virtual void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
QPointer< QAbstractItemModel > ItemModel
virtual vtkAbstractArray * NewArray(const QVariant &type)
Return a suitable vtk array for the QVariant type.
Abstract superclass for all arrays.
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:68
@ orientation
Definition: vtkX3D.h:262
@ type
Definition: vtkX3D.h:516
@ data
Definition: vtkX3D.h:315