Tweaking Qt sql-model code got desired results -
diff -r ../../../QtSDK-orig/QtSources/4.8.1/src/sql/models/qsqlrelationaltablemodel.cpp ./src/sql/models/qsqlrelationaltablemodel.cpp
241a242
> setFilter(relation->rel.where()); // This seems to work...
diff -r ../../../QtSDK-orig/QtSources/4.8.1/src/sql/models/qsqlrelationaltablemodel.h ./src/sql/models/qsqlrelationaltablemodel.h
58,59c58,59
< : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
---
> : tName(aTableName), iColumn(indexCol), dColumn(displayCol), _where(where) {}
65a66,67
> { return _where; }
69c71
---
>
QString tName, iColumn, dColumn, _where;
diff -r ../../../QtSDK-orig/QtSources/4.8.1/src/sql/models/qsqlrelationaltablemodel.cpp ./src/sql/models/qsqlrelationaltablemodel.cpp
241a242
> setFilter(relation->rel.where()); // This seems to work...
diff -r ../../../QtSDK-orig/QtSources/4.8.1/src/sql/models/qsqlrelationaltablemodel.h ./src/sql/models/qsqlrelationaltablemodel.h
58,59c58,59
< const QString &displayCol)
< : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
---
> const QString &displayCol, const QString &where = QString())
> : tName(aTableName), iColumn(indexCol), dColumn(displayCol), _where(where) {}
65a66,67
> inline QString where() const
> { return _where; }
69c71
< QString tName, iColumn, dColumn;
---
> QString tName, iColumn, dColumn, _where;
To copy to clipboard, switch view to plain text mode
This allows specifying your WHERE clause to limit the association options for model relations - no special delegate is required.
Game
::m_tmodel->setRelation
(4,
QSqlRelation("team",
"id",
"name",
"team.division_id IN (1,10,11,12)" ));
Game::m_tmodel->setRelation(4, QSqlRelation("team", "id", "name", "team.division_id IN (1,10,11,12)" ));
To copy to clipboard, switch view to plain text mode
Bookmarks