diff --git a/cfilterpanel.cpp b/cfilterpanel.cpp index adfd0a3..cbcc25b 100644 --- a/cfilterpanel.cpp +++ b/cfilterpanel.cpp @@ -56,6 +56,34 @@ void cFilterPanel::setPersonList(cPersonList* lpPersonList) m_lpPersonListModel->appendRow(lpItem); } + m_lpPersonListModel->sort(0); + + m_bLoading = false; +} + +void cFilterPanel::updatePersonList() +{ + m_bLoading = true; + + for(cPersonList::iterator i = m_lpPersonList->begin();i != m_lpPersonList->end();i++) + { + if(m_lpPersonListModel->findItems((*i)->name()).isEmpty()) + { + QStandardItem* lpItem = new QStandardItem((*i)->name()); + lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); + lpItem->setCheckable(true); + m_lpPersonListModel->appendRow(lpItem); + } + } + + for(int x = m_lpPersonListModel->rowCount()-1;x >= 0;x--) + { + if(!m_lpPersonList->find(m_lpPersonListModel->item(x, 0)->text())) + m_lpPersonListModel->removeRow(x); + } + + m_lpPersonListModel->sort(0); + m_bLoading = false; } @@ -81,6 +109,32 @@ void cFilterPanel::setLocationList(cLocationList* lpLocationList) m_bLoading = false; } +void cFilterPanel::updateLocationList() +{ + m_bLoading = true; + + for(cLocationList::iterator i = m_lpLocationList->begin();i != m_lpLocationList->end();i++) + { + if(m_lpLocationListModel->findItems((*i)->name()).isEmpty()) + { + QStandardItem* lpItem = new QStandardItem((*i)->name()); + lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); + lpItem->setCheckable(true); + m_lpLocationListModel->appendRow(lpItem); + } + } + + for(int x = m_lpLocationListModel->rowCount()-1;x >= 0;x--) + { + if(!m_lpLocationList->find(m_lpLocationListModel->item(x, 0)->text())) + m_lpLocationListModel->removeRow(x); + } + + m_lpLocationListModel->sort(0); + + m_bLoading = false; +} + void cFilterPanel::clearTagList() { m_lpTagListModel->clear(); @@ -102,3 +156,29 @@ void cFilterPanel::setTagList(cTagList* lpTagList) m_bLoading = false; } + +void cFilterPanel::updateTagList() +{ + m_bLoading = true; + + for(cTagList::iterator i = m_lpTagList->begin();i != m_lpTagList->end();i++) + { + if(m_lpTagListModel->findItems((*i)->name()).isEmpty()) + { + QStandardItem* lpItem = new QStandardItem((*i)->name()); + lpItem->setData(QVariant::fromValue(*i), Qt::UserRole+1); + lpItem->setCheckable(true); + m_lpTagListModel->appendRow(lpItem); + } + } + + for(int x = m_lpTagListModel->rowCount()-1;x >= 0;x--) + { + if(!m_lpTagList->find(m_lpTagListModel->item(x, 0)->text())) + m_lpTagListModel->removeRow(x); + } + + m_lpTagListModel->sort(0); + + m_bLoading = false; +} diff --git a/cfilterpanel.h b/cfilterpanel.h index 96d387b..48cb8eb 100644 --- a/cfilterpanel.h +++ b/cfilterpanel.h @@ -36,6 +36,12 @@ public: \fn setPersonList */ void setPersonList(cPersonList* lpPersonList); + /*! + \brief + + \fn updatePersonList + */ + void updatePersonList(); /*! \brief @@ -50,6 +56,12 @@ public: \fn setLocationList */ void setLocationList(cLocationList* lpLocationList); + /*! + \brief + + \fn updateLocationList + */ + void updateLocationList(); /*! \brief @@ -64,6 +76,12 @@ public: \fn setTagList */ void setTagList(cTagList* lpTagList); + /*! + \brief + + \fn updateTagList + */ + void updateTagList(); private: Ui::cFilterPanel* ui; diff --git a/clocation.cpp b/clocation.cpp index cb74e2e..3955b86 100644 --- a/clocation.cpp +++ b/clocation.cpp @@ -230,6 +230,16 @@ cLocation* cLocationList::find(cLocation* lpLocation) return(nullptr); } +cLocation* cLocationList::find(const QString& szName) +{ + for(cLocationList::iterator i = begin(); i != end(); i++) + { + if(szName == (*i)->name()) + return(*i); + } + return(nullptr); +} + bool cLocationList::remove(cLocation* lpLocation) { if(!find(lpLocation)) diff --git a/clocation.h b/clocation.h index 869014a..f34201c 100644 --- a/clocation.h +++ b/clocation.h @@ -184,6 +184,14 @@ public: /*! \brief + \fn find + \param szName + \return cLocation + */ + cLocation* find(const QString& szLocation); + /*! + \brief + \fn remove \param lpLocation \return bool diff --git a/cmainwindow.cpp b/cmainwindow.cpp index a2e8552..f6eac8d 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -854,8 +854,7 @@ void cMainWindow::onTagEdited(cTag* /*lpTag*/) void cMainWindow::onTagListChanged() { - m_lpFilterPanel->clearTagList(); - m_lpFilterPanel->setTagList(&m_tagList); + m_lpFilterPanel->updateTagList(); } void cMainWindow::onPersonAdded(cPerson* /*lpPerson*/) @@ -872,8 +871,7 @@ void cMainWindow::onPersonEdited(cPerson* /*lpPerson*/) void cMainWindow::onPersonListChanged() { - m_lpFilterPanel->clearPersonList(); - m_lpFilterPanel->setPersonList(&m_personList); + m_lpFilterPanel->updatePersonList(); } void cMainWindow::onLocationAdded(cLocation* /*lpLocation*/) @@ -890,6 +888,5 @@ void cMainWindow::onLocationEdited(cLocation* /*lpLocation*/) void cMainWindow::onLocationListChanged() { - m_lpFilterPanel->clearLocationList(); - m_lpFilterPanel->setLocationList(&m_locationList); + m_lpFilterPanel->updateLocationList(); } diff --git a/cperson.cpp b/cperson.cpp index 9fe8352..7c0835b 100644 --- a/cperson.cpp +++ b/cperson.cpp @@ -237,6 +237,16 @@ cPerson* cPersonList::find(cPerson* lpPerson) return(nullptr); } +cPerson* cPersonList::find(const QString& szName) +{ + for(cPersonList::iterator i = begin(); i != end(); i++) + { + if(szName == (*i)->name()) + return(*i); + } + return(nullptr); +} + bool cPersonList::remove(cPerson* lpPerson) { if(!find(lpPerson)) diff --git a/cperson.h b/cperson.h index 03de22e..d7b8b34 100644 --- a/cperson.h +++ b/cperson.h @@ -177,13 +177,21 @@ public: \brief \fn find - \param iID + \param lpPerson \return cPerson */ cPerson* find(cPerson* lpPerson); /*! \brief + \fn find + \param szName + \return cPerson + */ + cPerson* find(const QString& szName); + /*! + \brief + \fn remove \param lpPerson \return bool diff --git a/ctag.cpp b/ctag.cpp index 12b0912..f751f9a 100644 --- a/ctag.cpp +++ b/ctag.cpp @@ -230,6 +230,16 @@ cTag* cTagList::find(cTag* lpTag) return(nullptr); } +cTag* cTagList::find(const QString& szName) +{ + for(cTagList::iterator i = begin(); i != end(); i++) + { + if(szName == (*i)->name()) + return(*i); + } + return(nullptr); +} + bool cTagList::remove(cTag* lpTag) { if(!find(lpTag)) diff --git a/ctag.h b/ctag.h index b4078e6..a87ca02 100644 --- a/ctag.h +++ b/ctag.h @@ -184,6 +184,14 @@ public: /*! \brief + \fn find + \param szName + \return cTag + */ + cTag* find(const QString& szName); + /*! + \brief + \fn remove \param lpTag \return bool