Commit 3e403c56 authored by Maik Qualmann's avatar Maik Qualmann

port ItemInfo class to QSharedData

the DSharedData class is now unused and can be removed
parent 175b20c6
Pipeline #10648 failed with stage
in 60 minutes
......@@ -29,16 +29,16 @@
// Qt includes
#include <QString>
#include <QDateTime>
#include <QUrl>
#include <QList>
#include <QSize>
#include <QUrl>
#include <QString>
#include <QDateTime>
#include <QExplicitlySharedDataPointer>
// Local includes
#include "digikam_export.h"
#include "dshareddata.h"
#include "coredbalbuminfo.h"
#include "coredburl.h"
#include "coredbfields.h"
......@@ -528,7 +528,7 @@ private:
friend class ItemInfoCache;
friend class ItemInfoList;
DSharedDataPointer<ItemInfoData> m_data;
QExplicitlySharedDataPointer<ItemInfoData> m_data;
};
inline uint qHash(const ItemInfo& info)
......
......@@ -65,12 +65,12 @@ ItemInfoCache::~ItemInfoCache()
}
template <class T>
DSharedDataPointer<T> toStrongRef(T* weakRef)
QExplicitlySharedDataPointer<T> toStrongRef(T* weakRef)
{
// Called under read lock
if (!weakRef)
{
return DSharedDataPointer<T>();
return QExplicitlySharedDataPointer<T>();
}
// The weak ref is a data object which is not deleted
// (because deletion is done under mutex protection)
......@@ -88,11 +88,11 @@ DSharedDataPointer<T> toStrongRef(T* weakRef)
{
// drop weakRef
weakRef->ref.deref();
return DSharedDataPointer<T>();
return QExplicitlySharedDataPointer<T>();
}
// Convert to a strong reference. Will ref() the weakRef once again
DSharedDataPointer<ItemInfoData> ptr(weakRef);
QExplicitlySharedDataPointer<ItemInfoData> ptr(weakRef);
// decrease counter, which we incremented twice now
weakRef->ref.deref();
......@@ -132,11 +132,11 @@ int ItemInfoCache::getImageGroupedCount(qlonglong id)
return m_grouped.count(id);
}
DSharedDataPointer<ItemInfoData> ItemInfoCache::infoForId(qlonglong id)
QExplicitlySharedDataPointer<ItemInfoData> ItemInfoCache::infoForId(qlonglong id)
{
{
ItemInfoReadLocker lock;
DSharedDataPointer<ItemInfoData> ptr = toStrongRef(m_infos.value(id));
QExplicitlySharedDataPointer<ItemInfoData> ptr = toStrongRef(m_infos.value(id));
if (ptr)
{
......@@ -149,7 +149,7 @@ DSharedDataPointer<ItemInfoData> ItemInfoCache::infoForId(qlonglong id)
data->id = id;
m_infos[id] = data;
return DSharedDataPointer<ItemInfoData>(data);
return QExplicitlySharedDataPointer<ItemInfoData>(data);
}
void ItemInfoCache::cacheByName(ItemInfoData* const data)
......@@ -167,7 +167,8 @@ void ItemInfoCache::cacheByName(ItemInfoData* const data)
m_dataHash.insert(data, data->name);
}
DSharedDataPointer<ItemInfoData> ItemInfoCache::infoForPath(int albumRootId, const QString& relativePath, const QString& name)
QExplicitlySharedDataPointer<ItemInfoData> ItemInfoCache::infoForPath(int albumRootId,
const QString& relativePath, const QString& name)
{
ItemInfoReadLocker lock;
// We check all entries in the multi hash with matching file name
......@@ -193,7 +194,7 @@ DSharedDataPointer<ItemInfoData> ItemInfoCache::infoForPath(int albumRootId, con
return toStrongRef(it.value());
}
return DSharedDataPointer<ItemInfoData>();
return QExplicitlySharedDataPointer<ItemInfoData>();
}
void ItemInfoCache::dropInfo(ItemInfoData* const infodata)
......@@ -210,7 +211,6 @@ void ItemInfoCache::dropInfo(ItemInfoData* const infodata)
m_nameHash.remove(m_dataHash.value(infodata), infodata);
m_nameHash.remove(infodata->name, infodata);
m_dataHash.remove(infodata);
delete infodata;
}
QList<AlbumShortInfo>::const_iterator ItemInfoCache::findAlbum(int id)
......@@ -253,7 +253,7 @@ void ItemInfoCache::invalidate()
for (it = m_infos.begin() ; it != m_infos.end() ; ++it)
{
if ((*it)->isReferenced())
if ((*it)->ref > 0)
{
(*it)->invalid = true;
(*it)->id = -1;
......
......@@ -27,14 +27,14 @@
// Qt includes
#include <QMultiHash>
#include <QHash>
#include <QObject>
#include <QMultiHash>
#include <QExplicitlySharedDataPointer>
// Local includes
#include "coredbwatch.h"
#include "dshareddata.h"
namespace Digikam
{
......@@ -57,7 +57,7 @@ public:
* A new object is created, or an existing object is returned.
* If a new object is created, the id field will be initialized.
*/
DSharedDataPointer<ItemInfoData> infoForId(qlonglong id);
QExplicitlySharedDataPointer<ItemInfoData> infoForId(qlonglong id);
/**
* Call this when the data has been dereferenced,
......@@ -77,7 +77,8 @@ public:
* Works if previously cached with cacheByName.
* Returns 0 if not found.
*/
DSharedDataPointer<ItemInfoData> infoForPath(int albumRootId, const QString& relativePath, const QString& name);
QExplicitlySharedDataPointer<ItemInfoData> infoForPath(int albumRootId,
const QString& relativePath, const QString& name);
/**
* Returns the cached relativePath for the given album id.
......@@ -110,10 +111,10 @@ private:
QHash<qlonglong, ItemInfoData*> m_infos;
QHash<ItemInfoData*, QString> m_dataHash;
QMultiHash<QString, ItemInfoData*> m_nameHash;
volatile bool m_needUpdateAlbums;
volatile bool m_needUpdateGrouped;
QList<qlonglong> m_grouped;
QList<AlbumShortInfo> m_albums;
volatile bool m_needUpdateAlbums;
volatile bool m_needUpdateGrouped;
QList<qlonglong> m_grouped;
QList<AlbumShortInfo> m_albums;
};
} // namespace Digikam
......
......@@ -28,17 +28,17 @@
// Qt includes
#include <QDateTime>
#include <QList>
#include <QSize>
#include <QDateTime>
#include <QSharedData>
#include <QReadWriteLock>
#include <QReadLocker>
#include <QWriteLocker>
#include <QReadLocker>
// Local includes
#include "coredburl.h"
#include "dshareddata.h"
#include "coredbalbuminfo.h"
#include "iteminfocache.h"
......@@ -57,7 +57,7 @@ public:
public:
ItemInfoCache m_cache;
QReadWriteLock m_lock;
QReadWriteLock m_lock;
static ItemInfoStatic* m_instance;
};
......@@ -88,7 +88,7 @@ public:
// -----------------------------------------------------------------------------------
class ItemInfoData : public DSharedData
class ItemInfoData : public QSharedData
{
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment