[ fromfile: tablemodels.xml id: sortfilter ]
Don't bother looking for the code creating the QLineEdit, the connect
between the two in Figure 13.10.
Those were all defined in Designer and generated by uic
.
Thanks to QSortFilterProxyModel, you can add sorting/filtering capability to an existing model with fewer than five lines of code. Figure 13.11 shows how the proxy sits between the view and the model.
Example 13.20 shows what is needed to set up the sort filter proxy in the preceding action table example.
Example 13.20. src/libs/actioneditor/actiontableeditor.cpp
[ . . . . ] void ActionTableEditor::setupSortFilter() { m_sortFilterProxy = new QSortFilterProxyModel(this); m_sortFilterProxy->setSourceModel(m_model); m_ui->m_tableView->setModel(m_sortFilterProxy); m_sortFilterProxy->setFilterKeyColumn(-1); } void ActionTableEditor::on_m_filterField_textChanged (const QString& newText) { m_sortFilterProxy->setFilterFixedString(newText); }
<include segid="sortfilter" mode="cpp" href="src/libs/actioneditor/actiontableeditor.cpp" id="sortfilter-setup-cpp" src="src/libs/actioneditor/actiontableeditor.cpp"/>
The filterField_textChanged
is an auto-connected slot that gets called whenever the textChanged
signal is emitted by the filterField
QLineEdit.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |