diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 3c9eae4616..061981e332 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -15,6 +15,11 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) mDataFilesModel = new QStandardItemModel(); // Contains all plugins with masters mPluginsModel = new QStandardItemModel(); // Contains selectable plugins + mPluginsProxyModel = new QSortFilterProxyModel(); + mPluginsProxyModel->setDynamicSortFilter(true); + mPluginsProxyModel->setSourceModel(mPluginsModel); + + // TODO: decide what to do with the selection model mPluginsSelectModel = new QItemSelectionModel(mPluginsModel); QLabel *filterLabel = new QLabel(tr("Filter:"), this); @@ -40,7 +45,7 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) mMastersWidget->verticalHeader()->hide(); mMastersWidget->insertColumn(0); - mPluginsTable->setModel(mPluginsModel); + mPluginsTable->setModel(mPluginsProxyModel); mPluginsTable->setSelectionModel(mPluginsSelectModel); mPluginsTable->setSelectionBehavior(QAbstractItemView::SelectRows); mPluginsTable->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -113,6 +118,8 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(masterSelectionChanged(const QItemSelection&, const QItemSelection&))); + connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(const QString))); + connect(mPluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex))); connect(mPluginsModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(resizeRows())); @@ -531,6 +538,13 @@ void DataFilesPage::resizeRows() mPluginsTable->resizeRowsToContents(); } +void DataFilesPage::filterChanged(const QString filter) +{ + QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::FixedString); + mPluginsProxyModel->setFilterRegExp(regExp); + +} + void DataFilesPage::profileChanged(const QString &previous, const QString ¤t) { qDebug() << "Profile changed " << current << previous; @@ -544,7 +558,6 @@ void DataFilesPage::profileChanged(const QString &previous, const QString &curre // Deselect the masters mMastersWidget->selectionModel()->clearSelection(); readConfig(); - } void DataFilesPage::readConfig() diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 9127797acb..9573541a8d 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -11,6 +11,7 @@ class ComboBox; class QStandardItemModel; class QItemSelection; class QItemSelectionModel; +class QSortFilterProxyModel; class QStringListModel; class QSettings; class QPushButton; @@ -23,7 +24,6 @@ public: DataFilesPage(QWidget *parent = 0); ComboBox *mProfilesComboBox; - //QStringListModel *mProfilesModel; QSettings *mLauncherConfig; const QStringList checkedPlugins(); @@ -38,6 +38,7 @@ public slots: void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void setCheckstate(QModelIndex index); void resizeRows(); + void filterChanged(const QString filter); void profileChanged(const QString &previous, const QString ¤t); void newProfile(); void copyProfile(); @@ -50,6 +51,7 @@ private: QStandardItemModel *mDataFilesModel; QStandardItemModel *mPluginsModel; + QSortFilterProxyModel *mPluginsProxyModel; QItemSelectionModel *mPluginsSelectModel; QPushButton *mNewProfileButton;