diff --git a/cfilterpanel.cpp b/cfilterpanel.cpp index 27d3e9c..227fda0 100644 --- a/cfilterpanel.cpp +++ b/cfilterpanel.cpp @@ -1,6 +1,8 @@ #include "cfilterpanel.h" #include "ui_cfilterpanel.h" +#include + cFilterPanel::cFilterPanel(QWidget *parent) : QWidget(parent), @@ -19,6 +21,59 @@ cFilterPanel::~cFilterPanel() delete ui; } +void cFilterPanel::saveSettings() +{ + QSettings settings; + QStringList szIDs; + + for(int x = 0;x < m_lpPersonListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpPersonListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cPerson* lpPerson = lpItem->data(Qt::UserRole+1).value(); + if(lpPerson) + szIDs.append(QString::number(lpPerson->id())); + } + } + settings.setValue("filter/person", QVariant::fromValue(szIDs)); + settings.setValue("filter/personActive", QVariant::fromValue(ui->m_lpPersonFilter->isChecked())); + settings.setValue("filter/personAnd", QVariant::fromValue(ui->m_lpPersonAnd->isChecked())); + szIDs.clear(); + + for(int x = 0;x < m_lpLocationListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpLocationListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cLocation* lpLocation = lpItem->data(Qt::UserRole+1).value(); + if(lpLocation) + szIDs.append(QString::number(lpLocation->id())); + } + } + settings.setValue("filter/location", QVariant::fromValue(szIDs)); + settings.setValue("filter/locationActive", QVariant::fromValue(ui->m_lpLocationFilter->isChecked())); + settings.setValue("filter/locationAnd", QVariant::fromValue(ui->m_lpLocationAnd->isChecked())); + szIDs.clear(); + + for(int x = 0;x < m_lpTagListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpTagListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cTag* lpTag = lpItem->data(Qt::UserRole+1).value(); + if(lpTag) + szIDs.append(QString::number(lpTag->id())); + } + } + settings.setValue("filter/tag", QVariant::fromValue(szIDs)); + settings.setValue("filter/tagActive", QVariant::fromValue(ui->m_lpTagFilter->isChecked())); + settings.setValue("filter/tagAnd", QVariant::fromValue(ui->m_lpTagsAnd->isChecked())); +} + void cFilterPanel::initUI() { ui->setupUi(this); @@ -31,6 +86,20 @@ void cFilterPanel::initUI() m_lpTagListModel = new QStandardItemModel; ui->m_lpTagList->setModel(m_lpTagListModel); + + QSettings settings; + + ui->m_lpPersonFilter->setChecked(settings.value("filter/personActive", true).toBool()); + ui->m_lpPersonAnd->setChecked(settings.value("filter/personAnd", true).toBool()); + ui->m_lpPersonOr->setChecked(!settings.value("filter/personAnd", true).toBool()); + + ui->m_lpLocationFilter->setChecked(settings.value("filter/locationActive", true).toBool()); + ui->m_lpLocationAnd->setChecked(settings.value("filter/locationAnd", true).toBool()); + ui->m_lpLocationOr->setChecked(!settings.value("filter/locationAnd", true).toBool()); + + ui->m_lpTagFilter->setChecked(settings.value("filter/tagActive", true).toBool()); + ui->m_lpTagsAnd->setChecked(settings.value("filter/tagAnd", true).toBool()); + ui->m_lpTagsOr->setChecked(!settings.value("filter/tagAnd", true).toBool()); } void cFilterPanel::createActions() @@ -57,6 +126,10 @@ void cFilterPanel::setPersonList(cPersonList* lpPersonList) { m_bLoading = true; + QSettings settings; + QStringList szIDs; + + szIDs = settings.value("filter/person").toStringList(); m_lpPersonList = lpPersonList; for(cPersonList::iterator i = lpPersonList->begin();i != lpPersonList->end();i++) @@ -65,6 +138,8 @@ void cFilterPanel::setPersonList(cPersonList* lpPersonList) lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); lpItem->setCheckable(true); m_lpPersonListModel->appendRow(lpItem); + if(szIDs.contains(QString::number((*i)->id()))) + lpItem->setCheckState(Qt::Checked); } m_lpPersonListModel->sort(0); @@ -98,6 +173,24 @@ void cFilterPanel::updatePersonList() m_bLoading = false; } +QList cFilterPanel::selectedPerson() +{ + QList idList; + + for(int x = 0;x < m_lpPersonListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpPersonListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cPerson* lpPerson = lpItem->data(Qt::UserRole+1).value(); + if(lpPerson) + idList.append(lpPerson->id()); + } + } + return(idList); +} + void cFilterPanel::clearLocationList() { m_lpLocationListModel->clear(); @@ -105,8 +198,12 @@ void cFilterPanel::clearLocationList() void cFilterPanel::setLocationList(cLocationList* lpLocationList) { - m_bLoading = true; + m_bLoading = true; + QSettings settings; + QStringList szIDs; + + szIDs = settings.value("filter/location").toStringList(); m_lpLocationList = lpLocationList; for(cLocationList::iterator i = lpLocationList->begin();i != lpLocationList->end();i++) @@ -115,8 +212,12 @@ void cFilterPanel::setLocationList(cLocationList* lpLocationList) lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); lpItem->setCheckable(true); m_lpLocationListModel->appendRow(lpItem); + if(szIDs.contains(QString::number((*i)->id()))) + lpItem->setCheckState(Qt::Checked); } + m_lpLocationListModel->sort(0); + m_bLoading = false; } @@ -146,6 +247,24 @@ void cFilterPanel::updateLocationList() m_bLoading = false; } +QList cFilterPanel::selectedLocation() +{ + QList idList; + + for(int x = 0;x < m_lpLocationListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpLocationListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cLocation* lpLocation = lpItem->data(Qt::UserRole+1).value(); + if(lpLocation) + idList.append(lpLocation->id()); + } + } + return(idList); +} + void cFilterPanel::clearTagList() { m_lpTagListModel->clear(); @@ -153,8 +272,12 @@ void cFilterPanel::clearTagList() void cFilterPanel::setTagList(cTagList* lpTagList) { - m_bLoading = true; + m_bLoading = true; + QSettings settings; + QStringList szIDs; + + szIDs = settings.value("filter/tag").toStringList(); m_lpTagList = lpTagList; for(cTagList::iterator i = lpTagList->begin();i != lpTagList->end();i++) @@ -163,8 +286,12 @@ void cFilterPanel::setTagList(cTagList* lpTagList) lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); lpItem->setCheckable(true); m_lpTagListModel->appendRow(lpItem); + if(szIDs.contains(QString::number((*i)->id()))) + lpItem->setCheckState(Qt::Checked); } + m_lpTagListModel->sort(0); + m_bLoading = false; } @@ -194,6 +321,24 @@ void cFilterPanel::updateTagList() m_bLoading = false; } +QList cFilterPanel::selectedTag() +{ + QList idList; + + for(int x = 0;x < m_lpTagListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpTagListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + { + cTag* lpTag = lpItem->data(Qt::UserRole+1).value(); + if(lpTag) + idList.append(lpTag->id()); + } + } + return(idList); +} + void cFilterPanel::onPersonChanged() { if(m_bLoading) diff --git a/cfilterpanel.h b/cfilterpanel.h index 7572d48..69b457b 100644 --- a/cfilterpanel.h +++ b/cfilterpanel.h @@ -23,6 +23,13 @@ public: explicit cFilterPanel(QWidget *parent = nullptr); ~cFilterPanel(); + /*! + \brief + + \fn saveSettings + */ + void saveSettings(); + /*! \brief @@ -42,6 +49,13 @@ public: \fn updatePersonList */ void updatePersonList(); + /*! + \brief + + \fn selectedPerson + \return QList + */ + QList selectedPerson(); /*! \brief @@ -62,6 +76,13 @@ public: \fn updateLocationList */ void updateLocationList(); + /*! + \brief + + \fn selectedLocation + \return QList + */ + QList selectedLocation(); /*! \brief @@ -82,6 +103,13 @@ public: \fn updateTagList */ void updateTagList(); + /*! + \brief + + \fn selectedTag + \return QList + */ + QList selectedTag(); private: Ui::cFilterPanel* ui; diff --git a/cfilterpanel.ui b/cfilterpanel.ui index d372a3e..9709354 100644 --- a/cfilterpanel.ui +++ b/cfilterpanel.ui @@ -7,7 +7,7 @@ 0 0 400 - 300 + 189 diff --git a/ctoolboxlocation.cpp b/ctoolboxlocation.cpp index c47cb0d..be800ea 100644 --- a/ctoolboxlocation.cpp +++ b/ctoolboxlocation.cpp @@ -55,7 +55,7 @@ void cToolBoxLocation::createActions() connect(ui->m_lpLocationList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cToolBoxLocation::onLocationSelected); connect(m_lpLocationListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(locationChanged(QModelIndex, QModelIndex, QVector))); - connect(ui->m_lpLocationList, &QTreeView::customContextMenuRequested, this, &cToolBoxLocation::onLocationViewContextMenu); + connect(ui->m_lpLocationList, &QListView::customContextMenuRequested, this, &cToolBoxLocation::onLocationViewContextMenu); connect(m_lpLocationListModel, &QStandardItemModel::itemChanged, this, &cToolBoxLocation::onLocationChanged); } diff --git a/ctoolboxlocation.ui b/ctoolboxlocation.ui index 2d4274e..e5f9532 100644 --- a/ctoolboxlocation.ui +++ b/ctoolboxlocation.ui @@ -17,7 +17,7 @@ - + Qt::CustomContextMenu @@ -30,12 +30,12 @@ QAbstractItemView::ExtendedSelection - - false + + QListView::TopToBottom + + + true - - false - diff --git a/ctoolboxperson.cpp b/ctoolboxperson.cpp index 95108f8..9a04aec 100644 --- a/ctoolboxperson.cpp +++ b/ctoolboxperson.cpp @@ -60,7 +60,7 @@ void cToolBoxPerson::createActions() connect(ui->m_lpPersonList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cToolBoxPerson::onPersonSelected); connect(m_lpPersonListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(personChanged(QModelIndex, QModelIndex, QVector))); - connect(ui->m_lpPersonList, &QTreeView::customContextMenuRequested, this, &cToolBoxPerson::onPersonViewContextMenu); + connect(ui->m_lpPersonList, &QListView::customContextMenuRequested, this, &cToolBoxPerson::onPersonViewContextMenu); connect(m_lpPersonListModel, &QStandardItemModel::itemChanged, this, &cToolBoxPerson::onPersonChanged); } diff --git a/ctoolboxperson.ui b/ctoolboxperson.ui index cb67f1f..f807a50 100644 --- a/ctoolboxperson.ui +++ b/ctoolboxperson.ui @@ -17,7 +17,7 @@ - + Qt::CustomContextMenu @@ -30,12 +30,9 @@ QAbstractItemView::ExtendedSelection - - false + + true - - false - diff --git a/ctoolboxtag.cpp b/ctoolboxtag.cpp index 5b0a6f9..c217629 100644 --- a/ctoolboxtag.cpp +++ b/ctoolboxtag.cpp @@ -60,7 +60,7 @@ void cToolBoxTag::createActions() connect(ui->m_lpTagList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cToolBoxTag::onTagSelected); connect(m_lpTagListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(tagChanged(QModelIndex, QModelIndex, QVector))); - connect(ui->m_lpTagList, &QTreeView::customContextMenuRequested, this, &cToolBoxTag::onTagViewContextMenu); + connect(ui->m_lpTagList, &QListView::customContextMenuRequested, this, &cToolBoxTag::onTagViewContextMenu); connect(m_lpTagListModel, &QStandardItemModel::itemChanged, this, &cToolBoxTag::onTagChanged); } diff --git a/ctoolboxtag.ui b/ctoolboxtag.ui index a44d215..f86edc4 100644 --- a/ctoolboxtag.ui +++ b/ctoolboxtag.ui @@ -17,7 +17,7 @@ - + Qt::CustomContextMenu @@ -30,12 +30,9 @@ QAbstractItemView::ExtendedSelection - - false + + true - - false -