[KPhotoAlbum] Keywords with id=0?

Johannes Zarl-Zierl johannes at zarl-zierl.at
Sun Dec 15 16:31:48 GMT 2019


Hi Robert,

You beat me to it - I had finally untangled this mess for myself and was about 
to start working on a fix when I saw the your mail pop up ;-)

Am Sonntag, 15. Dezember 2019, 17:09:02 CET schrieb Robert Krawitz:
> On Sun, 15 Dec 2019 10:17:34 +0100, Tobias Leupold wrote:
> diff --git a/XMLDB/XMLCategory.cpp b/XMLDB/XMLCategory.cpp
> index 712cc689..30e55cdb 100644
> --- a/XMLDB/XMLCategory.cpp
> +++ b/XMLDB/XMLCategory.cpp
> @@ -20,6 +20,7 @@
>  #include <DB/ImageDB.h>
>  #include <DB/MemberMap.h>
>  #include <Utilities/List.h>
> +#include "Logging.h"
> 
>  XMLDB::XMLCategory::XMLCategory(const QString &name, const QString &icon,
> ViewType type, int thumbnailSize, bool show, bool positionable)
>      : m_name(name)
> 
> @@ -130,7 +131,8 @@ void XMLDB::XMLCategory::renameItem(const QString
> &oldValue, const QString &newV m_idMap.remove(oldValue);
> 
>      addItem(newValue);
> -    setIdMapping(newValue, id);
> +    if ( id != 0)
> +        setIdMapping(newValue, id);
>      emit itemRenamed(oldValue, newValue);
>  }

-> I would leave the call unguarded here. Keeping the special knowledge 
localized to as few functions as possible seems like a good practice to reduce 
the probability of future bugs.


> @@ -179,8 +181,12 @@ void XMLDB::XMLCategory::initIdMap()
> 
>  void XMLDB::XMLCategory::setIdMapping(const QString &name, int id)
>  {
> -    m_nameMap.insert(id, name);
> -    m_idMap.insert(name, id);
> +    if (id == 0) {
> +        qCWarning(XMLDBLog, "XMLDB::XMLCategory::setIdMapping attempting to
> set id for %s to invalid value %d", qPrintable(name), id); +    } else {
> +        m_nameMap.insert(id, name);
> +        m_idMap.insert(name, id);
> +    }
>  }
> 
>  QString XMLDB::XMLCategory::nameForId(int id) const

You can leave the warning out here completely, because now this is expected 
behaviour.

To polish things off, we can also change the check to <=0 as Harald suggested.






More information about the Kphotoalbum mailing list