diff --git a/cfilterpanel.cpp b/cfilterpanel.cpp index 227fda0..b652ffe 100644 --- a/cfilterpanel.cpp +++ b/cfilterpanel.cpp @@ -26,6 +26,16 @@ void cFilterPanel::saveSettings() QSettings settings; QStringList szIDs; + for(int x = 0;x < m_lpTitleListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpTitleListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + szIDs.append(lpItem->text()); + } + settings.setValue("filter/title", QVariant::fromValue(szIDs)); + settings.setValue("filter/titleActive", QVariant::fromValue(ui->m_lpTitleFilter->isChecked())); + for(int x = 0;x < m_lpPersonListModel->rowCount();x++) { QStandardItem* lpItem = m_lpPersonListModel->item(x, 0); @@ -78,6 +88,9 @@ void cFilterPanel::initUI() { ui->setupUi(this); + m_lpTitleListModel = new QStandardItemModel; + ui->m_lpTitleList->setModel(m_lpTitleListModel); + m_lpPersonListModel = new QStandardItemModel; ui->m_lpPersonList->setModel(m_lpPersonListModel); @@ -89,6 +102,8 @@ void cFilterPanel::initUI() QSettings settings; + ui->m_lpTitleFilter->setChecked(settings.value("filter/titleActive", true).toBool()); + 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()); @@ -104,6 +119,7 @@ void cFilterPanel::initUI() void cFilterPanel::createActions() { + connect(ui->m_lpTitleFilter, &QGroupBox::toggled, this, &cFilterPanel::onTitleFilter); connect(ui->m_lpPersonFilter, &QGroupBox::toggled, this, &cFilterPanel::onPersonFilter); connect(ui->m_lpLocationFilter, &QGroupBox::toggled, this, &cFilterPanel::onLocationFilter); connect(ui->m_lpTagFilter, &QGroupBox::toggled, this, &cFilterPanel::onTagFilter); @@ -112,11 +128,73 @@ void cFilterPanel::createActions() connect(ui->m_lpLocationAnd, &QRadioButton::toggled, this, &cFilterPanel::onLocationAnd); connect(ui->m_lpTagsAnd, &QRadioButton::toggled, this, &cFilterPanel::onTagAnd); + connect(m_lpTitleListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(onTitleChanged(QModelIndex, QModelIndex, QVector))); connect(m_lpPersonListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(onPersonChanged(QModelIndex, QModelIndex, QVector))); connect(m_lpLocationListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(onLocationChanged(QModelIndex, QModelIndex, QVector))); connect(m_lpTagListModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector)), SLOT(onTagChanged(QModelIndex, QModelIndex, QVector))); } +void cFilterPanel::clearTitleList() +{ + m_lpTitleListModel->clear(); +} + +void cFilterPanel::setTitleList(QStringList titleList) +{ + m_bLoading = true; + + QSettings settings; + QStringList szIDs; + + szIDs = settings.value("filter/title").toStringList(); + + for(QStringList::iterator i = titleList.begin();i != titleList.end();i++) + { + QStandardItem* lpItem = new QStandardItem(*i); + lpItem->setCheckable(true); + m_lpTitleListModel->appendRow(lpItem); + if(szIDs.contains(*i)) + lpItem->setCheckState(Qt::Checked); + } + + m_lpPersonListModel->sort(0); + + m_bLoading = false; +} + +void cFilterPanel::updateTitleList(QStringList& titleList) +{ + m_bLoading = true; + + for(QStringList::iterator i = titleList.begin();i != titleList.end();i++) + { + if(m_lpTitleListModel->findItems(*i).isEmpty()) + { + QStandardItem* lpItem = new QStandardItem(*i); + lpItem->setCheckable(true); + m_lpTitleListModel->appendRow(lpItem); + } + } + + m_lpPersonListModel->sort(0); + + m_bLoading = false; +} + +QStringList cFilterPanel::selectedTitle() +{ + QStringList titleList; + + for(int x = 0;x < m_lpTitleListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpTitleListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + titleList.append(lpItem->text()); + } + return(titleList); +} + void cFilterPanel::clearPersonList() { m_lpPersonListModel->clear(); @@ -339,6 +417,37 @@ QList cFilterPanel::selectedTag() return(idList); } +void cFilterPanel::onTitleFilter(bool bToggle) +{ + if(bToggle) + onTitleChanged(); + else { + emit(titleChanged(QStringList())); + } +} + +void cFilterPanel::onTitleChanged(const QModelIndex& /*topLeft*/, const QModelIndex& /*bottomright*/, const QVector& /*roles*/) +{ + onTitleChanged(); +} + +void cFilterPanel::onTitleChanged() +{ + if(m_bLoading) + return; + + QStringList titleList; + + for(int x = 0;x < m_lpTitleListModel->rowCount();x++) + { + QStandardItem* lpItem = m_lpTitleListModel->item(x, 0); + + if(lpItem->checkState() == Qt::Checked) + titleList.append(lpItem->text()); + } + emit titleChanged(titleList); +} + void cFilterPanel::onPersonChanged() { if(m_bLoading) diff --git a/cfilterpanel.h b/cfilterpanel.h index 69b457b..fb246c8 100644 --- a/cfilterpanel.h +++ b/cfilterpanel.h @@ -30,6 +30,34 @@ public: */ void saveSettings(); + /*! + \brief + + \fn clearTitleList + */ + void clearTitleList(); + /*! + \brief + + \param titleList + \fn setTitleList + */ + void setTitleList(QStringList titleList); + /*! + \brief + + \param titleList + \fn updateTitleList + */ + void updateTitleList(QStringList& titleList); + /*! + \brief + + \fn selectedTitle + \return QStringList + */ + QStringList selectedTitle(); + /*! \brief @@ -111,10 +139,37 @@ public: */ QList selectedTag(); + /*! + \brief + + \fn onTitleChanged + */ + void onTitleChanged(); + /*! + \brief + + \fn onPersonChanged + */ + void onPersonChanged(); + /*! + \brief + + \fn onLocationChanged + */ + void onLocationChanged(); + /*! + \brief + + \fn onTagChanged + */ + void onTagChanged(); + private: Ui::cFilterPanel* ui; bool m_bLoading; /*!< TODO: describe */ + QStandardItemModel* m_lpTitleListModel; /*!< TODO: describe */ + QStandardItemModel* m_lpPersonListModel; /*!< TODO: describe */ cPersonList* m_lpPersonList; /*!< TODO: describe */ @@ -136,26 +191,23 @@ private: \fn createActions */ void createActions(); - - /*! - \brief - - \fn onPersonChanged - */ - void onPersonChanged(); - /*! - \brief - - \fn onLocationChanged - */ - void onLocationChanged(); - /*! - \brief - - \fn onTagChanged - */ - void onTagChanged(); private slots: + /*! + \brief + + \fn onTitleFilter + \param bToggle + */ + void onTitleFilter(bool bToggle); + /*! + \brief + + \fn onTitleChanged + \param topLeft + \param bottomright + \param roles + */ + void onTitleChanged(const QModelIndex& topLeft, const QModelIndex& bottomright, const QVector& roles); /*! \brief @@ -226,6 +278,13 @@ private slots: */ void onTagChanged(const QModelIndex& topLeft, const QModelIndex& bottomright, const QVector& roles); signals: + /*! + \brief + + \fn titleChanged + \param titleList + */ + void titleChanged(QStringList titleList); /*! \brief diff --git a/cfilterpanel.ui b/cfilterpanel.ui index 9709354..69f2cfc 100644 --- a/cfilterpanel.ui +++ b/cfilterpanel.ui @@ -6,27 +6,33 @@ 0 0 - 400 - 189 + 570 + 152 Form - + - + - Person + Title true - - - + + + + + + 16777215 + 100 + + QAbstractItemView::NoEditTriggers @@ -41,7 +47,19 @@ - + + + + + + + Person + + + true + + + @@ -75,6 +93,28 @@ + + + + + 16777215 + 100 + + + + QAbstractItemView::NoEditTriggers + + + true + + + false + + + false + + + @@ -89,6 +129,12 @@ + + + 16777215 + 100 + + QAbstractItemView::NoEditTriggers @@ -151,6 +197,12 @@ + + + 16777215 + 100 + + QAbstractItemView::NoEditTriggers diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 2023932..e8d2b0c 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -175,6 +175,7 @@ void cMainWindow::createActions() connect(ui->m_lpToolBoxLocation, &cToolBoxLocation::locationEdited, this, &cMainWindow::onLocationEdited); connect(ui->m_lpToolBoxLocation, &cToolBoxLocation::locationListChanged, this, &cMainWindow::onLocationListChanged); + connect(m_lpFilterPanel, &cFilterPanel::titleChanged, this, &cMainWindow::onFilterTitleChanged); connect(m_lpFilterPanel, &cFilterPanel::personChanged, this, &cMainWindow::onFilterPersonChanged); connect(m_lpFilterPanel, &cFilterPanel::locationChanged, this, &cMainWindow::onFilterLocationChanged); connect(m_lpFilterPanel, &cFilterPanel::tagChanged, this, &cMainWindow::onFilterTagChanged); @@ -281,6 +282,7 @@ void cMainWindow::displayData() ui->m_lpToolBoxLocation->setLocationList(&m_locationList); ui->m_lpToolBoxTags->setTagList(&m_tagList); + m_lpFilterPanel->setTitleList(m_pictureList.titleList()); m_lpFilterPanel->setPersonList(&m_personList); m_lpFilterPanel->setLocationList(&m_locationList); m_lpFilterPanel->setTagList(&m_tagList); @@ -329,8 +331,15 @@ void cMainWindow::displayData() m_lpFolderSortFilterProxyModel->sort(0); m_lpThumbnailSortFilterProxyModel->sort(0); + m_lpFilterPanel->onTitleChanged(); + m_lpFilterPanel->onPersonChanged(); + m_lpFilterPanel->onLocationChanged(); + m_lpFilterPanel->onTagChanged(); + ui->m_lpStatusBar->showMessage(tr("done."), 3); + m_lpThumbnailSortFilterProxyModel->invalidate(); + showCount(); } @@ -925,6 +934,14 @@ void cMainWindow::onLocationListChanged() m_lpFilterPanel->updateLocationList(); } +void cMainWindow::onFilterTitleChanged(QStringList titleList) +{ + if(m_bLoading) + return; + + m_lpThumbnailSortFilterProxyModel->setTitleList(titleList); +} + void cMainWindow::onFilterPersonChanged(QList idList, bool bAnd) { if(m_bLoading) diff --git a/cmainwindow.h b/cmainwindow.h index 2cbbadb..6818963 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -365,6 +365,13 @@ private slots: */ void onLocationListChanged(); + /*! + \brief + + \fn onFilterTitleChanged + \param titleList + */ + void onFilterTitleChanged(QStringList titleList); /*! \brief diff --git a/cpicture.cpp b/cpicture.cpp index 6b005b6..0ba715e 100644 --- a/cpicture.cpp +++ b/cpicture.cpp @@ -1128,7 +1128,10 @@ QStringList cPictureList::titleList() QStringList szTitleList; for(cPictureList::iterator i = begin(); i != end();i++) - szTitleList.append((*i)->title()); + { + if(!(*i)->title().isEmpty()) + szTitleList.append((*i)->title()); + } szTitleList.removeDuplicates(); szTitleList.sort(Qt::CaseInsensitive); diff --git a/cthumbnailsortfilterproxymodel.cpp b/cthumbnailsortfilterproxymodel.cpp index ee85519..c7921b9 100644 --- a/cthumbnailsortfilterproxymodel.cpp +++ b/cthumbnailsortfilterproxymodel.cpp @@ -25,6 +25,16 @@ QString cThumbnailSortFilterProxyModel::filterPath() return(m_szPath); } +QStringList cThumbnailSortFilterProxyModel::titleList() +{ + return(m_titleList); +} + +void cThumbnailSortFilterProxyModel::setTitleList(const QStringList& titleList) +{ + m_titleList = titleList; +} + QList cThumbnailSortFilterProxyModel::personList() { return(m_personList); @@ -93,6 +103,9 @@ bool cThumbnailSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QMode if(!bValid) return(false); + if(!m_titleList.contains(lpPicture->title())) + return(false); + if(!m_personList.isEmpty()) { if(!lpPicture->personList().contains(m_personList, m_bPersonAnd)) diff --git a/cthumbnailsortfilterproxymodel.h b/cthumbnailsortfilterproxymodel.h index 88cbb71..0796e23 100644 --- a/cthumbnailsortfilterproxymodel.h +++ b/cthumbnailsortfilterproxymodel.h @@ -36,6 +36,20 @@ public: */ void setFilterPath(const QString& szPath); + /*! + \brief + + \fn titleList + */ + QStringList titleList(); + /*! + \brief + + \fn setTitleList + \param titleList + */ + void setTitleList(const QStringList& titleList); + /*! \brief @@ -91,6 +105,7 @@ protected: private: QString m_szPath; /*!< TODO: describe */ + QStringList m_titleList; /*!< TODO: describe */ QList m_personList; /*!< TODO: describe */ QList m_locationList; /*!< TODO: describe */ QList m_tagList; /*!< TODO: describe */