mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Implement the TagFilter model.
This model accepts check / unchedk. Now, I need to also plug the result of the check / uncheck to the list model. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7a90b9d764
commit
a6e9a1eab5
4 changed files with 71 additions and 0 deletions
|
@ -181,6 +181,7 @@ void MainWindow::refreshDisplay(bool doRecreateDiveList)
|
|||
void MainWindow::recreateDiveList()
|
||||
{
|
||||
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
||||
TagFilterModel::instance()->repopulate();
|
||||
}
|
||||
|
||||
void MainWindow::current_dive_changed(int divenr)
|
||||
|
|
|
@ -2099,3 +2099,54 @@ int LanguageModel::rowCount(const QModelIndex &parent) const
|
|||
{
|
||||
return languages.count();
|
||||
}
|
||||
|
||||
|
||||
TagFilterModel::TagFilterModel(QObject *parent): QStringListModel(parent), checkState(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
TagFilterModel *TagFilterModel::instance()
|
||||
{
|
||||
static TagFilterModel *self = new TagFilterModel();
|
||||
return self;
|
||||
}
|
||||
|
||||
QVariant TagFilterModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(role == Qt::CheckStateRole){
|
||||
return checkState[index.row()] ? Qt::Checked : Qt::Unchecked;
|
||||
} else if (role == Qt::DisplayRole) {
|
||||
return stringList()[index.row()];
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags TagFilterModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
return QStringListModel::flags(index) | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
void TagFilterModel::repopulate()
|
||||
{
|
||||
if (g_tag_list == NULL)
|
||||
return;
|
||||
QStringList list;
|
||||
struct tag_entry *current_tag_entry = g_tag_list->next;
|
||||
while (current_tag_entry != NULL) {
|
||||
list.append(QString(current_tag_entry->tag->name));
|
||||
current_tag_entry = current_tag_entry->next;
|
||||
}
|
||||
setStringList(list);
|
||||
delete[] checkState;
|
||||
checkState = new bool[list.count()];
|
||||
memset(checkState, false, list.count());
|
||||
}
|
||||
|
||||
bool TagFilterModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if(role == Qt::CheckStateRole){
|
||||
checkState[index.row()] = value.toBool();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -417,4 +417,18 @@ private:
|
|||
|
||||
QStringList languages;
|
||||
};
|
||||
|
||||
class TagFilterModel : public QStringListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TagFilterModel *instance();
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
public slots:
|
||||
void repopulate();
|
||||
private:
|
||||
explicit TagFilterModel(QObject *parent = 0);
|
||||
bool *checkState;
|
||||
};
|
||||
#endif // MODELS_H
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QFileDialog>
|
||||
#include <QShortcut>
|
||||
#include <QCalendarWidget>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "exif.h"
|
||||
#include "dive.h"
|
||||
#include "file.h"
|
||||
|
@ -459,4 +460,8 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button)
|
|||
TagFilter::TagFilter(QWidget *parent): QWidget(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
QSortFilterProxyModel *filter = new QSortFilterProxyModel();
|
||||
filter->setSourceModel(TagFilterModel::instance());
|
||||
connect(ui.filterTag, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString)));
|
||||
ui.tagView->setModel(filter);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue