[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kphotoalbum/area_workflow_improvement] AnnotationDialog: Code cleanup in AnnotationDialog
From: Johannes Zarl-Zierl <johannes () zarl-zierl ! at>
Date: 2016-12-01 22:56:28
Message-ID: E1cCaHE-0000KF-0s () code ! kde ! org
[Download RAW message or body]
Git commit e10a268285f268c7fa5b5ae94e3182e1ca71be60 by Johannes Zarl-Zierl.
Committed on 01/12/2016 at 22:38.
Pushed by johanneszarl into branch 'area_workflow_improvement'.
Code cleanup in AnnotationDialog
M +2 -2 AnnotationDialog/AreaTagSelectDialog.cpp
M +24 -26 AnnotationDialog/Dialog.cpp
M +6 -2 AnnotationDialog/Dialog.h
https://commits.kde.org/kphotoalbum/e10a268285f268c7fa5b5ae94e3182e1ca71be60
diff --git a/AnnotationDialog/AreaTagSelectDialog.cpp \
b/AnnotationDialog/AreaTagSelectDialog.cpp index 0cc9a31..f20b527 100644
--- a/AnnotationDialog/AreaTagSelectDialog.cpp
+++ b/AnnotationDialog/AreaTagSelectDialog.cpp
@@ -43,7 +43,7 @@ AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialog::Res
:QDialog(area)
, m_area(area)
, m_dialog(dialog)
- , m_usedTags(dialog->positionableTags(ls->category()))
+ , m_usedTags(dialog->positionedTags(ls->category()))
, m_category(ls->category())
{
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
@@ -79,7 +79,7 @@ AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialog::Res
void AnnotationDialog::AreaTagSelectDialog::slotSetTag(const QString &tag)
{
QString enteredText = tag.trimmed();
- if (m_dialog->positionableTagValid(m_category, enteredText))
+ if (m_dialog->positionableTagAvailable(m_category, enteredText))
{
m_area->setTagData(m_category, enteredText);
this->accept();
diff --git a/AnnotationDialog/Dialog.cpp b/AnnotationDialog/Dialog.cpp
index d8d9cb8..bc218d2 100644
--- a/AnnotationDialog/Dialog.cpp
+++ b/AnnotationDialog/Dialog.cpp
@@ -463,7 +463,6 @@ void AnnotationDialog::Dialog::slotCopyPrevious()
m_positionableTagCandidates.clear();
m_lastSelectedPositionableTag.first = QString();
m_lastSelectedPositionableTag.second = QString();
- QList<ResizableFrame *> allAreas = \
m_preview->preview()->findChildren<ResizableFrame *>();
Q_FOREACH( ListSelect *ls, m_optionList ) {
ls->setSelection( old_info.itemsOfCategory( ls->category() ) );
@@ -473,25 +472,19 @@ void AnnotationDialog::Dialog::slotCopyPrevious()
if ( ls->positionable() ) {
QString category = ls->category();
QSet<QString> selectedTags = old_info.itemsOfCategory( category );
+ QSet<QString> positionedTagSet = positionedTags( category );
// Add the tag to the positionable candiate list, if no area is already \
associated with it
- for (const auto tag : selectedTags) {
- bool alreadyAssociated = false;
-
- for (ResizableFrame* area : allAreas) {
- if (area->tagData().first == category && area->tagData().second \
== tag) {
- alreadyAssociated = true;
- break;
- }
- }
-
- if (! alreadyAssociated) {
+ Q_FOREACH(const auto &tag, selectedTags)
+ {
+ if (!positionedTagSet.contains(tag))
+ {
addTagToCandidateList(category, tag);
}
}
// Check all areas for a linked tag in this category that is probably \
not selected anymore
- for(ResizableFrame *area : allAreas) {
+ for(ResizableFrame *area : areas()) {
QPair<QString, QString> tagData = area->tagData();
if (tagData.first == category) {
@@ -643,7 +636,8 @@ void AnnotationDialog::Dialog::writeToInfo()
QMap<QString, QMap<QString, QRect>> taggedAreas;
QPair<QString, QString> tagData;
- foreach (ResizableFrame *area, m_preview->preview()->findChildren<ResizableFrame \
*>()) { + foreach (ResizableFrame *area, areas())
+ {
tagData = area->tagData();
if ( !tagData.first.isEmpty() ) {
@@ -681,6 +675,11 @@ void AnnotationDialog::Dialog::ShowHideSearch( bool show )
m_ratingSearchLabel->setVisible( show );
}
+QList<AnnotationDialog::ResizableFrame *> AnnotationDialog::Dialog::areas() const
+{
+ return m_preview->preview()->findChildren<ResizableFrame *>();
+}
+
int AnnotationDialog::Dialog::configure( DB::ImageInfoList list, bool oneAtATime )
{
@@ -1433,7 +1432,8 @@ void AnnotationDialog::Dialog::togglePreview()
void AnnotationDialog::Dialog::tidyAreas()
{
// Remove all areas marked on the preview image
- foreach (ResizableFrame *area, m_preview->preview()->findChildren<ResizableFrame \
*>()) { + foreach (ResizableFrame *area, areas())
+ {
area->deleteLater();
}
}
@@ -1462,8 +1462,7 @@ void \
AnnotationDialog::Dialog::positionableTagDeselected(QString category, QStri if \
(m_setup == InputSingleImageConfigMode) {
QPair<QString, QString> deselectedTag = QPair<QString, QString>(category, \
tag);
- QList<ResizableFrame *> allAreas = \
m_preview->preview()->findChildren<ResizableFrame *>();
- foreach (ResizableFrame *area, allAreas) {
+ foreach (ResizableFrame *area, areas()) {
if (area->tagData() == deselectedTag) {
area->removeTagData();
m_areasChanged = true;
@@ -1505,8 +1504,7 @@ QList<QPair<QString, QString>> \
AnnotationDialog::Dialog::positionableTagCandidat
void AnnotationDialog::Dialog::slotShowAreas(bool showAreas)
{
- QList<ResizableFrame *> allAreas = \
m_preview->preview()->findChildren<ResizableFrame *>();
- foreach (ResizableFrame *area, allAreas) {
+ foreach (ResizableFrame *area, areas()) {
area->setVisible(showAreas);
}
}
@@ -1527,8 +1525,7 @@ void AnnotationDialog::Dialog::positionableTagRenamed(QString \
category, QString }
// Check if an area on the current image contains the changed or proposed tag
- QList<ResizableFrame *> allAreas = \
m_preview->preview()->findChildren<ResizableFrame *>();
- foreach (ResizableFrame *area, allAreas) {
+ foreach (ResizableFrame *area, areas()) {
#ifdef HAVE_KFACE
if (area->proposedTagData() == oldTagData) {
area->setProposedTagData(QPair<QString, QString>(category, newTag));
@@ -1554,7 +1551,8 @@ void AnnotationDialog::Dialog::checkProposedTagData(
QPair<QString, QString> tagData,
ResizableFrame *areaToExclude) const
{
- foreach (ResizableFrame *area, m_preview->preview()->findChildren<ResizableFrame \
*>()) { + foreach (ResizableFrame *area, areas())
+ {
if (area != areaToExclude
and area->proposedTagData() == tagData
and area->tagData().first.isEmpty()) {
@@ -1573,13 +1571,13 @@ void AnnotationDialog::Dialog::areaChanged()
* This checks for empty and duplicate tags.
* @return
*/
-bool AnnotationDialog::Dialog::positionableTagValid(const QString &category, const \
QString &tag) const +bool AnnotationDialog::Dialog::positionableTagAvailable(const \
QString &category, const QString &tag) const {
if (category.isEmpty() || tag.isEmpty())
return false;
// does any area already have that tag?
- foreach (const ResizableFrame *area, \
m_preview->preview()->findChildren<ResizableFrame *>()) + foreach (const \
ResizableFrame *area, areas()) {
const auto tagData = area->tagData();
if (tagData.first == category && tagData.second == tag)
@@ -1594,10 +1592,10 @@ bool AnnotationDialog::Dialog::positionableTagValid(const \
QString &category, con
* @param category
* @return
*/
-QSet<QString> AnnotationDialog::Dialog::positionableTags(const QString &category) \
const +QSet<QString> AnnotationDialog::Dialog::positionedTags(const QString \
&category) const {
QSet<QString> tags;
- foreach (const ResizableFrame *area, \
m_preview->preview()->findChildren<ResizableFrame *>()) + foreach (const \
ResizableFrame *area, areas()) {
const auto tagData = area->tagData();
if (tagData.first == category)
diff --git a/AnnotationDialog/Dialog.h b/AnnotationDialog/Dialog.h
index c4742e2..5b76172 100644
--- a/AnnotationDialog/Dialog.h
+++ b/AnnotationDialog/Dialog.h
@@ -85,8 +85,8 @@ public:
void removeTagFromCandidateList(QString category, QString tag);
void checkProposedTagData(QPair<QString, QString> tagData, ResizableFrame \
*areaToExclude) const; void areaChanged();
- bool positionableTagValid(const QString &category, const QString &tag) const;
- QSet<QString> positionableTags(const QString &category) const;
+ bool positionableTagAvailable(const QString &category, const QString &tag) \
const; + QSet<QString> positionedTags(const QString &category) const;
ListSelect* listSelectForCategory( const QString &category);
protected slots:
@@ -149,6 +149,10 @@ protected:
std::tuple<Utilities::StringSet, Utilities::StringSet> selectionForMultiSelect( \
ListSelect*, const DB::ImageInfoList& images ); void saveAndClose();
void ShowHideSearch( bool show );
+ /**
+ * @return A list of all ResizableFrame objects on the current image
+ */
+ QList<ResizableFrame*> areas() const;
private:
QStackedWidget* m_stack;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic