QAbstractTableModel Class
QAbstractTableModel クラスは、テーブルモデルを作成するためにサブクラス化できる抽象モデルを提供します。詳細...
ヘッダ | #include <QAbstractTableModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
を継承する: | QAbstractItemModel |
継承元: |
パブリック関数
QAbstractTableModel(QObject *parent = nullptr) | |
virtual | ~QAbstractTableModel() |
再実装パブリック関数
virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
virtual Qt::ItemFlags | flags(const QModelIndex &index) const override |
virtual QModelIndex | index(int row, int column, const QModelIndex &parent = QModelIndex()) const override |
virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
詳細説明
QAbstractTableModel は、データを項目の二次元配列として表現するモデルのための標準インターフェースを提供します。これは直接は使用されませんが、サブクラス化する必要があります。
このモデルは、QAbstractItemModel よりも特殊なインタフェースを提供するため、QListView にデータを提供するために使用することはできますが、ツリー・ビューでの使用には適していません。単純な項目のリストを表現する必要があり、単一の列のデータを含むモデルのみが必要な場合は、QAbstractListModel をサブクラス化する方が適切な場合があります。
rowCount() およびcolumnCount() 関数は、テーブルの次元を返します。モデル内の項目に対応するモデルのインデックスを取得するには、index() を使用し、行番号と列番号のみを指定します。
サブクラス化
QAbstractTableModel をサブクラス化する際には、rowCount()、columnCount()、data() を実装する必要があります。index() およびparent() 関数のデフォルト実装は QAbstractTableModel によって提供されます。お行儀の良いモデルはheaderData() も実装します。
編集可能なモデルはsetData() を実装し、flags() を実装してQt::ItemIsEditable を含む値を返す必要があります。
サイズ変更可能なデータ構造へのインタフェースを提供するモデルは、insertRows()、removeRows()、insertColumns()、removeColumns() を実装することができます。これらの関数を実装する場合は、接続されているすべてのビューが変更を認識できるように、適切な関数を呼び出すことが重要です:
- insertRows() の実装では、データ構造に新しい行を挿入する前に beginInsertRows() を呼び出し、その直後に endInsertRows() を呼び出す必要があります。
- insertColumns() の実装では、データ構造に新しい列を挿入する前に beginInsertColumns() を呼び出す必要があり、その直後に endInsertColumns() を呼び出す必要があります。
- removeRows() の実装では、データ構造から行を削除する前に beginRemoveRows() を呼び出す必要があり、 その直後に endRemoveRows() を呼び出す必要がある。
- removeColumns() の実装では、データ構造から列が削除される前に beginRemoveColumns() を呼び出し、その直後に endRemoveColumns() を呼び出さなければならない。
注釈 モデルのサブクラス化に関する一般的なガイドラインは、モデル・サブクラス化リファレンスにあります。
スレッドの安全性
QObject のサブクラスであるため、QAbstractTableModel はthread-safe ではありません。QAbstractTableModel のモデル関連の API は、モデルオブジェクトが存在するスレッドからのみ呼び出される必要があります。QAbstractTableModel がビューと接続されている場合、それは GUI スレッドを意味します。バックグラウンドスレッドを使用してモデルの内容を入力したり変更したりすることは可能ですが、バックグラウンドスレッドはモデル関連の API を直接呼び出すことができないため、注意が必要です。代わりに、更新をキューに入れ、メインスレッドで適用する必要があります。これはキュー接続で行うことができます。
モデルクラス、QAbstractItemModel 、QAbstractListModelも参照してください 。
メンバ関数ドキュメント
[explicit]
QAbstractTableModel::QAbstractTableModel(QObject *parent = nullptr)
与えられたparent に対して抽象テーブルモデルを構築する。
[virtual noexcept]
QAbstractTableModel::~QAbstractTableModel()
抽象テーブル・モデルを破棄する。
[override virtual]
bool QAbstractTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
再実装:QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
[override virtual]
Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const
再実装:QAbstractItemModel::flags(const QModelIndex &index) const.
[override virtual]
QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
再実装:QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
row とcolumn のデータのインデックスをparent と共に返します。
parent()も参照してください 。
[override virtual]
QModelIndex QAbstractTableModel::sibling(int row, int column, const QModelIndex &idx) const
再実装:QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.