QSortFilterProxyModel Class
QSortFilterProxyModel クラスは、別のモデルとビューの間で渡されるデータのソートとフィルタリングのサポートを提供します。詳細...
ヘッダ | #include <QSortFilterProxyModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
継承: | QAbstractProxyModel |
プロパティ
|
|
パブリック関数
QSortFilterProxyModel(QObject *parent = nullptr) | |
virtual | ~QSortFilterProxyModel() |
bool | autoAcceptChildRows() const |
QBindable<bool> | bindableAutoAcceptChildRows() |
QBindable<bool> | bindableDynamicSortFilter() |
QBindable<Qt::CaseSensitivity> | bindableFilterCaseSensitivity() |
QBindable<int> | bindableFilterKeyColumn() |
QBindable<QRegularExpression> | bindableFilterRegularExpression() |
QBindable<int> | bindableFilterRole() |
QBindable<bool> | bindableIsSortLocaleAware() |
QBindable<bool> | bindableRecursiveFilteringEnabled() |
QBindable<Qt::CaseSensitivity> | bindableSortCaseSensitivity() |
QBindable<int> | bindableSortRole() |
bool | dynamicSortFilter() const |
Qt::CaseSensitivity | filterCaseSensitivity() const |
int | filterKeyColumn() const |
QRegularExpression | filterRegularExpression() const |
int | filterRole() const |
bool | isRecursiveFilteringEnabled() const |
bool | isSortLocaleAware() const |
void | setAutoAcceptChildRows(bool accept) |
void | setDynamicSortFilter(bool enable) |
void | setFilterCaseSensitivity(Qt::CaseSensitivity cs) |
void | setFilterKeyColumn(int column) |
void | setFilterRole(int role) |
void | setRecursiveFilteringEnabled(bool recursive) |
void | setSortCaseSensitivity(Qt::CaseSensitivity cs) |
void | setSortLocaleAware(bool on) |
void | setSortRole(int role) |
Qt::CaseSensitivity | sortCaseSensitivity() const |
int | sortColumn() const |
Qt::SortOrder | sortOrder() const |
int | sortRole() const |
再実装パブリック関数
virtual QModelIndex | buddy(const QModelIndex &index) const override |
virtual bool | canFetchMore(const QModelIndex &parent) const override |
virtual int | columnCount(const QModelIndex &parent = QModelIndex()) const override |
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const override |
virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
virtual void | fetchMore(const QModelIndex &parent) override |
virtual Qt::ItemFlags | flags(const QModelIndex &index) const override |
virtual bool | hasChildren(const QModelIndex &parent = QModelIndex()) const override |
virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override |
virtual QModelIndex | index(int row, int column, const QModelIndex &parent = QModelIndex()) const override |
virtual bool | insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override |
virtual bool | insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
virtual QModelIndex | mapFromSource(const QModelIndex &sourceIndex) const override |
virtual QItemSelection | mapSelectionFromSource(const QItemSelection &sourceSelection) const override |
virtual QItemSelection | mapSelectionToSource(const QItemSelection &proxySelection) const override |
virtual QModelIndex | mapToSource(const QModelIndex &proxyIndex) const override |
virtual QModelIndexList | match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const override |
virtual QMimeData * | mimeData(const QModelIndexList &indexes) const override |
virtual QStringList | mimeTypes() const override |
virtual QModelIndex | parent(const QModelIndex &child) const override |
virtual bool | removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override |
virtual bool | removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override |
virtual bool | setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override |
virtual void | setSourceModel(QAbstractItemModel *sourceModel) override |
virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override |
virtual QSize | span(const QModelIndex &index) const override |
virtual Qt::DropActions | supportedDropActions() const override |
パブリック・スロット
void | invalidate() |
void | setFilterFixedString(const QString &pattern) |
void | setFilterRegularExpression(const QString &pattern) |
void | setFilterRegularExpression(const QRegularExpression ®ularExpression) |
void | setFilterWildcard(const QString &pattern) |
シグナル
(since 6.0) void | autoAcceptChildRowsChanged(bool autoAcceptChildRows) |
void | filterCaseSensitivityChanged(Qt::CaseSensitivity filterCaseSensitivity) |
void | filterRoleChanged(int filterRole) |
void | recursiveFilteringEnabledChanged(bool recursiveFilteringEnabled) |
void | sortCaseSensitivityChanged(Qt::CaseSensitivity sortCaseSensitivity) |
void | sortLocaleAwareChanged(bool sortLocaleAware) |
void | sortRoleChanged(int sortRole) |
保護された関数
virtual bool | filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const |
virtual bool | filterAcceptsRow(int source_row, const QModelIndex &source_parent) const |
(since 6.0) void | invalidateColumnsFilter() |
void | invalidateFilter() |
(since 6.0) void | invalidateRowsFilter() |
virtual bool | lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const |
詳しい説明
QSortFilterProxyModel は、アイテムのソート、アイテムのフィルタリング、またはその両方に使用することができます。このモデルは、それが供給するモデルのインデックスを、ビューが使用するための、異なる場所に対応する新しいインデックスにマッピングすることで、ソースモデルの構造を変換します。このアプローチにより、基礎となるデータに対する変換を必要とせず、メモリ内のデータを複製することなく、ビューに関する限り、与えられたソースモデルを再構築することができます。
カスタムモデルによって提供される項目をソートしたりフィルタリングしたりしたいとします。ソートとフィルタリングなしでモデルとビューをセットアップするコードは次のようになります:
QTreeView *treeView = new QTreeView; MyItemModel *model = new MyItemModel(this); treeView->setModel(model);
MyItemModel
にソートとフィルタリングのサポートを追加するには、QSortFilterProxyModel を作成し、MyItemModel
を引数としてsetSourceModel() を呼び出し、ビューに QSortFilterProxyModel をインストールする必要があります:
QTreeView *treeView = new QTreeView; MyItemModel *sourceModel = new MyItemModel(this); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(sourceModel); treeView->setModel(proxyModel);
この時点では、ソートもフィルタリングも有効になっておらず、元のデータがビューに表示されています。QSortFilterProxyModel を通して行われた変更は、元のモデルに適用されます。
QSortFilterProxyModel は、元のモデルのラッパーとして動作します。ソースのQModelIndexes をソート/フィルターされたモデル・インデックスに変換する必要がある場合、またはその逆を行う必要がある場合は、mapToSource()、mapFromSource()、mapSelectionToSource()、mapSelectionFromSource() を使用してください。
注意: デフォルトでは、元のモデルが変更されるたびに、モデルは動的にデータを再ソートし、再フィルタリングします。この動作は、dynamicSortFilter プロパティを設定することで変更できます。
基本的なソート/フィルター・モデルとカスタム・ソート/フィルター・モデルの例では、QSortFilterProxyModel を使用して基本的なソートとフィルターを実行する方法と、それをサブクラス化してカスタム動作を実装する方法を説明します。
ソート
QTableView と には プロパティがあり、ユーザーがビューの水平ヘッダをクリックすることでビューをソートできるかどうかを制御します。例えばQTreeView sortingEnabled
treeView->setSortingEnabled(true);
この機能がオンの場合(デフォルトはオフ)、ヘッダー部分をクリックすると、その列に従って項目がソートされます。繰り返しクリックすることで、昇順と降順を交互に並べ替えることができます。
背後では、ビューはモデル上のsort() 仮想関数を呼び出して、モデル内のデータを並べ替えます。データをソート可能にするには、モデルでsort() を実装するか、QSortFilterProxyModel を使用してモデルをラップします。QSortFilterProxyModel は、アイテムのsortRole() ( デフォルトではQt::DisplayRole ) を操作し、int
、QString 、QDateTime を含むいくつかのデータ型を理解する、一般的なsort() の再実装を提供します。階層モデルの場合、ソートはすべての子アイテムに再帰的に適用されます。文字列の比較は、デフォルトでは大文字と小文字を区別します。これは、sortCaseSensitivity プロパティを設定することで変更できます。
カスタムのソート動作は、QSortFilterProxyModel をサブクラス化し、アイテムの比較に使用されるlessThan() を再実装することで実現できます。例えば、以下のようになります:
bool MySortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { QVariant leftData = sourceModel()->data(left); QVariant rightData = sourceModel()->data(right); if (leftData.userType() == QMetaType::QDateTime) { return leftData.toDateTime() < rightData.toDateTime(); } else { static const QRegularExpression emailPattern("[\\w\\.]*@[\\w\\.]*"); QString leftString = leftData.toString(); if (left.column() == 1) { const QRegularExpressionMatch match = emailPattern.match(leftString); if (match.hasMatch()) leftString = match.captured(0); } QString rightString = rightData.toString(); if (right.column() == 1) { const QRegularExpressionMatch match = emailPattern.match(rightString); if (match.hasMatch()) rightString = match.captured(0); } return QString::localeAwareCompare(leftString, rightString) < 0; } }
(このコードスニペットはCustom Sort/Filter Model の例から来ています)。
ソートの別のアプローチは、ビュー上でソートを無効にし、ユーザーに特定の順序を課すことです。これは、QSortFilterProxyModel (または、sort()を実装している場合は、元のモデル)で、希望する列と順序を引数として、sort()を明示的に呼び出すことによって行われます。例えば
proxyModel->sort(2, Qt::AscendingOrder);
QSortFilterProxyModelはカラム-1でソートすることができ、その場合、基礎となるソースモデルのソート順に戻ります。
注意: sortColumn() は最近使用されたソートカラムを返します。デフォルト値は -1 で、これはこのプロキシモデルがソートしないことを意味します。また、sort() は、sortColumn() を最近使用されたソート・カラムに設定することに注意してください。
フィルタリング
ソートに加えて、QSortFilterProxyModelは特定のフィルタにマッチしないアイテムを非表示にするために使用することができます。フィルターはQRegularExpression オブジェクトを使って指定され、指定された列の各アイテムのfilterRole() ( デフォルトではQt::DisplayRole ) に適用されます。QRegularExpression オブジェクトは、正規表現、ワイルドカード・パターン、または固定文字列にマッチするように使用できます。例えば
proxyModel->setFilterRegularExpression(QRegularExpression("\.png", QRegularExpression::CaseInsensitiveOption)); proxyModel->setFilterKeyColumn(1);
階層モデルの場合、フィルターはすべての子に再帰的に適用されます。親アイテムがフィルタにマッチしない場合、その子アイテムは表示されません。
一般的な使用例としては、QLineEdit でフィルタの正規表現、ワイルドカード・パターン、または固定文字列を指定し、textChanged() シグナルをsetFilterRegularExpression(),setFilterWildcard(),setFilterFixedString() に接続してフィルタを再適用する方法があります。
filterAcceptsRow ()とfilterAcceptsColumn ()関数を再実装することで、カスタム・フィルタリング動作を実現できる。例えば、(カスタム・ソート/フィルター・モデルの例から)以下の実装は、filterKeyColumn プロパティを無視し、列0、1、2に対してフィルタリングを実行します:
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent); QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent); return (sourceModel()->data(index0).toString().contains(filterRegularExpression()) || sourceModel()->data(index1).toString().contains(filterRegularExpression())) && dateInRange(sourceModel()->data(index2).toDate()); }
(このコード・スニペットはCustom Sort/Filter Modelの例から来ています)。
大量のフィルタリングを処理していて、invalidateFilter() を繰り返し呼び出さなければならない場合、モデルの実装によっては、beginResetModel() /endResetModel() を使用する方が効率的かもしれません。しかし、beginResetModel() /endResetModel() は、プロキシモデルを元の状態に戻し、選択情報を失うので、プロキシモデルが再投入されることになります。
サブクラス化
QAbstractProxyModel とそのサブクラスはQAbstractItemModel から派生したものなので、通常のモデルのサブクラス化に関する同じアドバイスの多くが、プロキシモデルにも適用されます。さらに、このクラスの関数のデフォルト実装の多くは、関連するソース・モデルの同等の関数を呼び出すように記述されていることは注目に値します。この単純なプロキシ機構は、より複雑な振る舞いをするソースモデルに対してはオーバーライドする必要があるかもしれません。例えば、ソースモデルがカスタムのhasChildren() 実装を提供する場合、プロキシモデルでもそれを提供する必要があります。
注: モデルのサブクラス化に関する一般的なガイドラインは、モデル・サブクラス化リファレンスにあります。
QAbstractProxyModel 、QAbstractItemModel 、モデル/ビュー・プログラミング、基本ソート/フィルター・モデルの例、カスタム・ソート/フィルター・モデルの例、QIdentityProxyModelも参照してください 。
プロパティーのドキュメント
[bindable, since 6.0]
autoAcceptChildRows : bool
注意: このプロパティはQProperty バインディングをサポートします。
もしtrueであれば、プロキシモデルは受理された行の子をフィルタリングしません。
デフォルト値は false です。
このプロパティは Qt 6.0 で導入されました。
recursiveFilteringEnabled およびfilterAcceptsRow()も参照してください 。
[bindable]
dynamicSortFilter : bool
注: このプロパティはQProperty バインディングをサポートします。
このプロパティは、ソースモデルの内容が変更されるたびに、プロキシモデルが動的にソートおよびフィルタリングされるかどうかを保持します。
dynamicSortFilter が True の場合は、プロキシ・モデルを通じてソース・モデルを更新しないことに注意してください。例えば、プロキシ・モデルをQComboBox に設定した場合、addItem() などのモデルを更新する関数を使用しても、期待どおりに動作しません。別の方法としては、dynamicSortFilter を false に設定し、QComboBox に項目を追加した後にsort() を呼び出す方法がある。
デフォルト値はtrueです。
sortColumn()も参照してください 。
[bindable]
filterCaseSensitivity : Qt::CaseSensitivity
注: このプロパティはQProperty バインディングをサポートしています。
このプロパティは、ソースモデルのコンテンツをフィルタリングするために使用されるQRegularExpression パターンの大文字と小文字の区別を保持します。
デフォルトでは、フィルタは大文字と小文字を区別します。
注釈 このプロパティを設定すると、新しい大文字と小文字の区別がfilterRegularExpression プロパティに伝搬されるため、そのバインディングが壊れます。同様に、filterRegularExpression を明示的に設定すると、現在の大文字と小文字の区別が変更され、バインディングが解除されます。
filterRegularExpression およびsortCaseSensitivityも参照してください 。
[bindable]
filterKeyColumn : int
注: このプロパティはQProperty バインディングに対応しています。
このプロパティは、ソースモデルの内容をフィルタリングするために使用されるキーが読み込まれる列を保持します。
デフォルト値は 0 です。値が -1 の場合、キーはすべての列から読み込まれます。
[bindable]
filterRegularExpression : QRegularExpression
注: このプロパティはQProperty バインディングをサポートしています。
このプロパティは、ソース・モデルのコンテンツのフィルタリングに使用されるQRegularExpression を保持します。
QRegularExpression オーバーロードを使用してこのプロパティを設定すると、現在のfilterCaseSensitivity が上書きされます。デフォルトでは、QRegularExpression は、すべてのコンテンツに一致する空の文字列です。
QRegularExpression が設定されていない場合、または空の文字列が設定されている場合、ソース・モデル内のすべてが受け入れられます。
注釈 このプロパティを設定すると、新しい正規表現の大文字と小文字の区別がfilterCaseSensitivity プロパティに伝搬されるため、そのバインドが解除されます。同様に、filterCaseSensitivity を明示的に設定すると、現在の正規表現の大文字と小文字の区別が変更され、そのバインディングが解除されます。
filterCaseSensitivity 、setFilterWildcard()、setFilterFixedString()も参照のこと 。
[bindable]
filterRole : int
注釈 このプロパティは、QProperty バインディングをサポートします。
このプロパティは、アイテムのフィルタリング時にソースモデルのデータをクエリするために使用されるアイテムのロールを保持します。
デフォルト値はQt::DisplayRole です。
filterAcceptsRow()も参照してください 。
[bindable]
isSortLocaleAware : bool
注意: このプロパティはQProperty バインディングに対応しています。
このプロパティは、ソート時に文字列を比較するために使用される、ローカルを意識した設定を保持します。
デフォルトでは、ソートはローカルアウェアではありません。
sortCaseSensitivity およびlessThan()も参照してください 。
[bindable]
recursiveFilteringEnabled : bool
注意: このプロパティはQProperty バインディングをサポートしています。
このプロパティは、フィルタが子に対して再帰的に適用されるかどうかを保持します。
デフォルト値はfalseです。
autoAcceptChildRows およびfilterAcceptsRow()も参照してください 。
[bindable]
sortCaseSensitivity : Qt::CaseSensitivity
注意: このプロパティはQProperty バインディングに対応しています。
このプロパティは、ソート時に文字列の比較に使用される大文字と小文字の区別設定を保持します。
デフォルトでは、大文字と小文字を区別します。
filterCaseSensitivity およびlessThan()も参照してください 。
[bindable]
sortRole : int
注釈 このプロパティは、QProperty バインディングをサポートします。
このプロパティは、アイテムをソートする際にソースモデルのデータをクエリするために使用されるアイテムのロールを保持します。
既定値はQt::DisplayRole です。
lessThan()も参照してください 。
メンバ関数ドキュメント
[explicit]
QSortFilterProxyModel::QSortFilterProxyModel(QObject *parent = nullptr)
与えられたparent でソートフィルタモデルを構築します。
[virtual noexcept]
QSortFilterProxyModel::~QSortFilterProxyModel()
このソートフィルターモデルを破壊する。
[signal, since 6.0]
void QSortFilterProxyModel::autoAcceptChildRowsChanged(bool autoAcceptChildRows)
このシグナルは、autoAcceptChildRows プロパティの値が変更されたときに発せられる。
注: autoAcceptChildRows プロパティのノーティファイア・シグナル。
この関数は Qt 6.0 で導入されました。
autoAcceptChildRowsも参照してください 。
[override virtual]
QModelIndex QSortFilterProxyModel::buddy(const QModelIndex &index) const
再実装:QAbstractProxyModel::buddy(const QModelIndex &index) const.
[override virtual]
bool QSortFilterProxyModel::canFetchMore(const QModelIndex &parent) const
再実装:QAbstractProxyModel::canFetchMore(const QModelIndex &parent) const.
[override virtual]
int QSortFilterProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const
再実装:QAbstractItemModel::columnCount(const QModelIndex &parent) const.
[override virtual]
QVariant QSortFilterProxyModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
再実装:QAbstractProxyModel::data(const QModelIndex &proxyIndex, int role) const.
setData()も参照してください 。
[override virtual]
bool QSortFilterProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
再実装:QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
[override virtual]
void QSortFilterProxyModel::fetchMore(const QModelIndex &parent)
再実装:QAbstractProxyModel::fetchMore(const QModelIndex &parent).
[virtual protected]
bool QSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const
与えられたsource_column とsource_parent で示される列の項目がモデルに含まれるべきであればtrue
を返し、そうでなければfalse
を返します。
注意: デフォルトの実装では、常にtrue
を返します。注意: デフォルトの実装では、常に を返します。
filterAcceptsRow(),setFilterFixedString(),setFilterRegularExpression(),setFilterWildcard()も参照してください 。
[virtual protected]
bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
与えられたsource_row とsource_parent で示される行の項目がモデルに含まれるべきであればtrue
を返し、そうでなければ false を返します。
デフォルトの実装では、関連項目が持つ値がフィルタ文字列、ワイルドカード文字列、正規表現にマッチする場合、true
を返します。
注意: デフォルトでは、Qt::DisplayRole が行を受け入れるかどうかの判定に使用されます。これは、filterRole プロパティを設定することで変更できます。
filterAcceptsColumn()、setFilterFixedString()、setFilterRegularExpression()、setFilterWildcard()も参照 。
[signal]
void QSortFilterProxyModel::filterCaseSensitivityChanged(Qt::CaseSensitivity filterCaseSensitivity)
このシグナルは、フィルタの大文字小文字の区別がfilterCaseSensitivity に変更されたときに発せられる。
注: filterCaseSensitivity プロパティの通知シグナル。
[signal]
void QSortFilterProxyModel::filterRoleChanged(int filterRole)
このシグナルは、フィルタの役割がfilterRole に変更されたときに発行されます。
注意: プロパティのノーティファイアシグナルfilterRole 。
[override virtual]
Qt::ItemFlags QSortFilterProxyModel::flags(const QModelIndex &index) const
再実装:QAbstractProxyModel::flags(const QModelIndex &index) const.
[override virtual]
bool QSortFilterProxyModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
再実装:QAbstractProxyModel::hasChildren(const QModelIndex &parent) const.
[override virtual]
QVariant QSortFilterProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
再実装:QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const.
setHeaderData()も参照してください 。
[override virtual]
QModelIndex QSortFilterProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
再実装:QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
[override virtual]
bool QSortFilterProxyModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())
再実装:QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent).
[override virtual]
bool QSortFilterProxyModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
再実装:QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent).
[slot]
void QSortFilterProxyModel::invalidate()
現在のソートとフィルタリングを無効にします。
invalidateFilter()も参照 。
[protected, since 6.0]
void QSortFilterProxyModel::invalidateColumnsFilter()
カラムに対する現在のフィルタリングを無効にします。
この関数は、(filterAcceptsColumn() による) カスタムフィルタリングを実装していて、 フィルタのパラメータが変更された場合にコールします。これはinvalidateFilter() とは異なり、filterAcceptsRow() は呼び出さず、filterAcceptsColumn() だけを呼び出します。行が変化しない列を隠したり表示したりしたい場合は、invalidateFilter() の代わりにこれを使用できます。
この関数は Qt 6.0 で導入されました。
invalidate(),invalidateFilter(),invalidateRowsFilter()も参照してください 。
[protected]
void QSortFilterProxyModel::invalidateFilter()
現在のフィルタリングを無効にします。
この関数は、カスタムフィルタリング(たとえばfilterAcceptsRow())を実装していて、 フィルタのパラメータが変更された場合に呼び出す必要があります。
invalidate()、invalidateColumnsFilter()、invalidateRowsFilter()も参照 。
[protected, since 6.0]
void QSortFilterProxyModel::invalidateRowsFilter()
行に対する現在のフィルタリングを無効にします。
この関数は、(filterAcceptsRow() による) カスタムフィルタリングを実装していて、フィルタリングのパラメータが変更された場合にコールします。これはinvalidateFilter() とは異なり、filterAcceptsColumn() は呼び出さず、filterAcceptsRow() だけを呼び出します。列が変化しない行を隠したり表示したりしたい場合は、invalidateFilter() の代わりにこれを使用できます。
この関数は Qt 6.0 で導入されました。
invalidate(),invalidateFilter(),invalidateColumnsFilter()も参照してください 。
[virtual protected]
bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
与えられたインデックスsource_left によって参照される項目の値が、与えられたインデックスsource_right によって参照される項目の値より小さい場合はtrue
を返し、そうでない場合はfalse
を返す。
この関数は、ソート時に<演算子として使用され、以下のQVariant 型を扱う:
- QMetaType::Int
- QMetaType::UInt
- QMetaType::LongLong
- QMetaType::ULongLong
- QMetaType::Float
- QMetaType::Double
- QMetaType::QChar
- QMetaType::QDate
- QMetaType::QTime
- QMetaType::QDateTime
- QMetaType::QString
それ以外の型は、QVariant::toString() を使ってQString に変換される。
QStringの比較は、デフォルトでは大文字と小文字を区別します。これはsortCaseSensitivity プロパティを使用して変更できます。
デフォルトでは、QModelIndexes に関連付けられたQt::DisplayRole が比較に使用されます。これはsortRole プロパティを設定することで変更できる。
注: 渡されるインデックスは、ソース・モデルに対応します。
sortRole 、sortCaseSensitivity 、およびdynamicSortFilterも参照してください 。
[override virtual]
QModelIndex QSortFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
再実装:QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const.
ソースモデルからsourceIndex を指定して、QSortFilterProxyModel 内のモデルインデックスを返します。
mapToSource()も参照してください 。
[override virtual]
QItemSelection QSortFilterProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
再実装:QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const.
[override virtual]
QItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const
再実装:QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const.
[override virtual]
QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const
再実装:QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const.
ソートフィルタモデルから、与えられたproxyIndex に対応するソースモデルインデックスを返します。
mapFromSource()も参照してください 。
[override virtual]
QModelIndexList QSortFilterProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
再実装:QAbstractItemModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const.
[override virtual]
QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const
再実装:QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const.
[override virtual]
QStringList QSortFilterProxyModel::mimeTypes() const
再実装:QAbstractProxyModel::mimeTypes() const.
[override virtual]
QModelIndex QSortFilterProxyModel::parent(const QModelIndex &child) const
再実装:QAbstractItemModel::parent(const QModelIndex &index) const.
[signal]
void QSortFilterProxyModel::recursiveFilteringEnabledChanged(bool recursiveFilteringEnabled)
このシグナルは、再帰フィルタ設定がrecursiveFilteringEnabled に変更されたときに発せられる。
注: プロパティrecursiveFilteringEnabled に対するノーティファイアシグナル。
[override virtual]
bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())
再実装:QAbstractItemModel::removeColumns(int column, int count, const QModelIndex &parent).
[override virtual]
bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
再実装:QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent).
[override virtual]
int QSortFilterProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const
再実装:QAbstractItemModel::rowCount(const QModelIndex &parent) const.
[override virtual]
bool QSortFilterProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
再実装:QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)。
data()も参照してください 。
[slot]
void QSortFilterProxyModel::setFilterFixedString(const QString &pattern)
ソースモデルの内容をフィルタリングするために使用される固定文字列を、与えられたpattern に設定します。
このメソッドは、正規表現のオプションをリセットしますが、大文字と小文字の区別を尊重します。
注意: このメソッドを呼び出すと正規表現が更新されるため、filterRegularExpression のバインディングは解除されます。 ただし、filterCaseSensitivity のバインディングには影響しません。
setFilterCaseSensitivity()、setFilterRegularExpression()、setFilterWildcard() およびfilterRegularExpression()も参照 。
[slot]
void QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern)
ソースモデルの内容をフィルタリングするために使用される正規表現をpattern に設定します。
このメソッドは、内部的にQRegularExpression を使用するため、新しいコードで使用することをお勧めします。
このメソッドは、正規表現のオプションをリセットしますが、大文字と小文字の区別を尊重します。
注意 : このメソッドを呼び出すと、正規表現が更新され、filterRegularExpression のバインディングが壊れます。 しかし、filterCaseSensitivity のバインディングには影響しません。
注意: プロパティfilterRegularExpression のセッター関数です。
setFilterCaseSensitivity(),setFilterWildcard(),setFilterFixedString(),filterRegularExpression()も参照してください 。
[slot]
void QSortFilterProxyModel::setFilterWildcard(const QString &pattern)
ソースモデルの内容をフィルタリングするために使用されるワイルドカード表現を、指定されたpattern に設定します。
このメソッドは、正規表現のオプションをリセットしますが、大文字と小文字の区別は尊重します。
注意: このメソッドを呼び出すと正規表現が更新され、filterRegularExpression のバインディングが解除されます。ただし、filterCaseSensitivity のバインディングには影響しません。
setFilterCaseSensitivity()、setFilterRegularExpression()、setFilterFixedString() およびfilterRegularExpression()も参照 。
[override virtual]
bool QSortFilterProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
再実装:QAbstractProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role).
headerData()も参照してください 。
[override virtual]
void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
再実装:QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel).
[override virtual]
QModelIndex QSortFilterProxyModel::sibling(int row, int column, const QModelIndex &idx) const
再実装:QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) const.
[override virtual]
void QSortFilterProxyModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
を再実装しています:QAbstractProxyModel::sort(int column, Qt::SortOrder order).
与えられたorder のcolumn でモデルをソートします。sortcolumn が 0 より小さい場合、モデルは与えられたorder のソースモデル行でソートされます。
sortColumn()も参照してください 。
[signal]
void QSortFilterProxyModel::sortCaseSensitivityChanged(Qt::CaseSensitivity sortCaseSensitivity)
このシグナルは、ソートの大文字小文字の区別がsortCaseSensitivity に変更されたときに発行される。
注: sortCaseSensitivity プロパティの通知シグナル。
int QSortFilterProxyModel::sortColumn() const
現在ソートに使用されているカラムを返す
これは最近使用されたソートカラムを返します。デフォルト値は -1 で、これはこのプロキシモデルがソートを行わないことを意味します。
sort()も参照してください 。
[signal]
void QSortFilterProxyModel::sortLocaleAwareChanged(bool sortLocaleAware)
このシグナルは、ロケール対応設定がsortLocaleAware に変更されたときに発行される。
注意: isSortLocaleAware プロパティの通知シグナルです。
Qt::SortOrder QSortFilterProxyModel::sortOrder() const
現在使われているソート順を返す
これは、最近使われたソート順を返します。デフォルト値はQt::AscendingOrder です。
sort()も参照 。
[signal]
void QSortFilterProxyModel::sortRoleChanged(int sortRole)
このシグナルは、ソートロールがsortRole に変更されたときに発行されます。
注意: プロパティの通知シグナルsortRole 。
[override virtual]
QSize QSortFilterProxyModel::span(const QModelIndex &index) const
再実装:QAbstractProxyModel::span(const QModelIndex &index) const.
[override virtual]
Qt::DropActions QSortFilterProxyModel::supportedDropActions() const
再実装:QAbstractProxyModel::supportedDropActions() 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.