VTK  9.2.6
QVTKTableModelAdapter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QVTKTableModelAdapter.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
32 #ifndef QVTKTableModelAdapter_h
33 #define QVTKTableModelAdapter_h
34 
35 #include "vtkGUISupportQtModule.h" // For export macro
36 
37 #include <QAbstractItemModel>
38 #include <QObject>
39 #include <QPointer>
40 
41 #include "vtkNew.h" // For vtkNew
42 #include "vtkTable.h" // For vtkTable
43 
44 class VTKGUISUPPORTQT_EXPORT QVTKTableModelAdapter : public QObject
45 {
46  Q_OBJECT
47 public:
48  QVTKTableModelAdapter(QObject* parent = nullptr);
49  QVTKTableModelAdapter(QAbstractItemModel* model, QObject* parent = nullptr);
50 
52 
57  virtual void SetItemModel(QAbstractItemModel* model);
58  QAbstractItemModel* GetItemModel() const;
60 
65  vtkTable* GetTable() const;
66 
67 Q_SIGNALS:
72  void tableChanged();
73 
74 protected:
78  virtual QVariant modelData(int row, int col);
79 
85  virtual vtkAbstractArray* NewArray(const QVariant& type);
86 
90  virtual bool HasCorrectColumnArrays();
91 
95  virtual void SetCellValue(int row, int column, const QVariant& data);
96 
101  virtual void UpdateTable(int row0, int column0, int row1, int column1);
102 
103  QPointer<QAbstractItemModel> ItemModel;
105 
106 protected Q_SLOTS:
107  virtual void onModified();
108  virtual void onModelReset();
109  virtual void onDataChanged(
110  const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
111  virtual void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
112  virtual void onLayoutChanged(
113  const QList<QPersistentModelIndex>& parents, QAbstractItemModel::LayoutChangeHint hint);
114  virtual void onRowsInserted(const QModelIndex& parent, int first, int last);
115  virtual void onRowsRemoved(const QModelIndex& parent, int first, int last);
116  virtual void onRowsMoved(
117  const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
118  virtual void onColumnsInserted(const QModelIndex& parent, int first, int last);
119  virtual void onColumnsRemoved(const QModelIndex& parent, int first, int last);
120  virtual void onColumnsMoved(
121  const QModelIndex& parent, int start, int end, const QModelIndex& destination, int column);
122 };
123 
124 #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 tabel 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)
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:183
@ orientation
Definition: vtkX3D.h:268
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321