Commit fd749229 authored by Gilles Caulier's avatar Gilles Caulier 🗼

Clazy++ : fix missing Q_OBJECT macro. Fix coding style

parent dbc68e86
Pipeline #38029 failed with stage
in 60 minutes and 21 seconds
......@@ -75,7 +75,9 @@ QString ThumbsDb::getSetting(const QString& keyword)
QMap<QString, QVariant> parameters;
parameters.insert(QLatin1String(":keyword"), keyword);
QList<QVariant> values;
// TODO Should really check return status here
BdEngineBackend::QueryState queryStateResult = d->db->execDBAction(d->db->getDBAction(QLatin1String("SelectThumbnailSetting")),
parameters, &values);
......@@ -95,7 +97,9 @@ QString ThumbsDb::getLegacySetting(const QString& keyword)
QMap<QString, QVariant> parameters;
parameters.insert(QLatin1String(":keyword"), keyword);
QList<QVariant> values;
// TODO Should really check return status here
BdEngineBackend::QueryState queryStateResult = d->db->execDBAction(d->db->getDBAction(QLatin1String("SelectThumbnailLegacySetting")),
parameters, &values);
......@@ -167,6 +171,7 @@ ThumbsDbInfo ThumbsDb::findByFilePath(const QString& path, const QString& unique
}
// double check that thumbnail is not referenced by a different hash
QList<QVariant> values;
d->db->execSql(QLatin1String("SELECT uniqueHash FROM UniqueHashes WHERE thumbId=?;"),
info.id, &values);
......@@ -265,6 +270,7 @@ BdEngineBackend::QueryState ThumbsDb::remove(int thumbId)
BdEngineBackend::QueryState ThumbsDb::removeByUniqueHash(const QString& uniqueHash, qlonglong fileSize)
{
// UniqueHashes + FilePaths entries are removed by trigger
QMap<QString, QVariant> parameters;
parameters.insert(QLatin1String(":uniqueHash"), uniqueHash);
parameters.insert(QLatin1String(":filesize"), fileSize);
......@@ -276,6 +282,7 @@ BdEngineBackend::QueryState ThumbsDb::removeByUniqueHash(const QString& uniqueHa
BdEngineBackend::QueryState ThumbsDb::removeByFilePath(const QString& path)
{
// UniqueHashes + FilePaths entries are removed by trigger
QMap<QString, QVariant> parameters;
parameters.insert(QLatin1String(":path"), path);
......@@ -286,6 +293,7 @@ BdEngineBackend::QueryState ThumbsDb::removeByFilePath(const QString& path)
BdEngineBackend::QueryState ThumbsDb::removeByCustomIdentifier(const QString& id)
{
// UniqueHashes + FilePaths entries are removed by trigger
QMap<QString, QVariant> parameters;
parameters.insert(QLatin1String(":identifier"), id);
......@@ -346,18 +354,24 @@ bool ThumbsDb::integrityCheck()
switch (d->db->databaseType())
{
case BdEngineBackend::DbType::SQLite:
// For SQLite the integrity check returns a single row with one string column "ok" on success and multiple rows on error.
return values.size() == 1 && values.first().toString().toLower().compare(QLatin1String("ok")) == 0;
return ((values.size() == 1) && (values.first().toString().toLower().compare(QLatin1String("ok")) == 0));
case BdEngineBackend::DbType::MySQL:
// For MySQL, for every checked table, the table name, operation (check), message type (status) and the message text (ok on success)
// are returned. So we check if there are four elements and if yes, whether the fourth element is "ok".
//qCDebug(DIGIKAM_DATABASE_LOG) << "MySQL check returned " << values.size() << " rows";
/*
qCDebug(DIGIKAM_DATABASE_LOG) << "MySQL check returned " << values.size() << " rows";
*/
if ((values.size() % 4) != 0)
{
return false;
}
for (QList<QVariant>::iterator it = values.begin() ; it != values.end() ;)
for (QList<QVariant>::iterator it = values.begin() ; it != values.end() ; )
{
QString tableName = (*it).toString();
++it;
......@@ -376,13 +390,20 @@ bool ThumbsDb::integrityCheck()
}
else
{
//qCDebug(DIGIKAM_DATABASE_LOG) << "Passed integrity check for table " << tableName;
/*
qCDebug(DIGIKAM_DATABASE_LOG) << "Passed integrity check for table " << tableName;
*/
}
}
// No error conditions. Db passed the integrity check.
return true;
default:
{
return false;
}
}
}
......
......@@ -64,8 +64,8 @@ class DIGIKAM_EXPORT ThumbsDbInfo
public:
explicit ThumbsDbInfo()
: id(-1),
type(DatabaseThumbnail::UndefinedType),
: id (-1),
type (DatabaseThumbnail::UndefinedType),
orientationHint(0)
{
}
......@@ -92,14 +92,16 @@ public:
ThumbsDbInfo findByFilePath(const QString& path);
ThumbsDbInfo findByCustomIdentifier(const QString& id);
/** This is findByFilePath with extra security: Pass the uniqueHash which you have.
* If an entry is found by file path, and the entry is referenced by any uniqueHash,
* which is different from the given hash, a null info is returned.
* If uniqueHash is null, equivalent to the simple findByFilePath.
/**
* This is findByFilePath with extra security: Pass the uniqueHash which you have.
* If an entry is found by file path, and the entry is referenced by any uniqueHash,
* which is different from the given hash, a null info is returned.
* If uniqueHash is null, equivalent to the simple findByFilePath.
*/
ThumbsDbInfo findByFilePath(const QString& path, const QString& uniqueHash);
/** Returns the thumbnail ids of all thumbnails in the database.
/**
* Returns the thumbnail ids of all thumbnails in the database.
*/
QList<int> findAll();
......@@ -108,9 +110,15 @@ public:
BdEngineBackend::QueryState insertCustomIdentifier(const QString& id, int thumbId);
BdEngineBackend::QueryState remove(int thumbId);
/** Removes thumbnail data associated to the given uniqueHash/fileSize */
/**
* Removes thumbnail data associated to the given uniqueHash/fileSize
*/
BdEngineBackend::QueryState removeByUniqueHash(const QString& uniqueHash, qlonglong fileSize);
/** Removes thumbnail data associated to the given file path */
/**
* Removes thumbnail data associated to the given file path
*/
BdEngineBackend::QueryState removeByFilePath(const QString& path);
BdEngineBackend::QueryState removeByCustomIdentifier(const QString& id);
......
......@@ -51,8 +51,8 @@ class Q_DECL_HIDDEN ThumbsDbAccessStaticPriv
public:
explicit ThumbsDbAccessStaticPriv()
: backend(nullptr),
db(nullptr),
: backend (nullptr),
db (nullptr),
initializing(false)
{
}
......@@ -80,7 +80,7 @@ public:
explicit ThumbsDbAccessMutexLocker(ThumbsDbAccessStaticPriv* const d)
: QMutexLocker(&d->lock.mutex),
d(d)
d (d)
{
d->lock.lockCount++;
}
......@@ -100,6 +100,7 @@ public:
ThumbsDbAccess::ThumbsDbAccess()
{
// You will want to call setParameters before constructing ThumbsDbAccess.
Q_ASSERT(d);
d->lock.mutex.lock();
......@@ -108,6 +109,7 @@ ThumbsDbAccess::ThumbsDbAccess()
if (!d->backend->isOpen() && !d->initializing)
{
// avoid endless loops
d->initializing = true;
d->backend->open(d->parameters);
......@@ -126,6 +128,7 @@ ThumbsDbAccess::ThumbsDbAccess(bool)
{
// private constructor, when mutex is locked and
// backend should not be checked
d->lock.mutex.lock();
d->lock.lockCount++;
}
......@@ -161,8 +164,9 @@ void ThumbsDbAccess::initDbEngineErrorHandler(DbEngineErrorHandler* const errorh
{
d = new ThumbsDbAccessStaticPriv();
}
//DbEngineErrorHandler* const errorhandler = new DbEngineGuiErrorHandler(d->parameters);
/*
DbEngineErrorHandler* const errorhandler = new DbEngineGuiErrorHandler(d->parameters);
*/
d->backend->setDbEngineErrorHandler(errorhandler);
}
......@@ -186,6 +190,7 @@ void ThumbsDbAccess::setParameters(const DbEngineParameters& parameters)
}
// Kill the old database error handler
if (d->backend)
{
d->backend->setDbEngineErrorHandler(nullptr);
......@@ -208,6 +213,7 @@ bool ThumbsDbAccess::checkReadyForUse(InitializationObserver* const observer)
return false;
// create an object with private shortcut constructor
ThumbsDbAccess access(false);
if (!d->backend)
......@@ -233,9 +239,11 @@ bool ThumbsDbAccess::checkReadyForUse(InitializationObserver* const observer)
}
// avoid endless loops (if called methods create new ThumbsDbAccess objects)
d->initializing = true;
// update schema
ThumbsDbSchemaUpdater updater(&access);
updater.setObserver(observer);
......
......@@ -37,6 +37,7 @@ class ThumbsDbSchemaUpdater;
class DIGIKAM_EXPORT ThumbsDbBackend : public BdEngineBackend
{
Q_OBJECT
public:
......
......@@ -59,11 +59,11 @@ class Q_DECL_HIDDEN ThumbsDbSchemaUpdater::Private
public:
explicit Private()
: setError(false),
currentVersion(0),
: setError (false),
currentVersion (0),
currentRequiredVersion(0),
dbAccess(nullptr),
observer(nullptr)
dbAccess (nullptr),
observer (nullptr)
{
}
......@@ -95,6 +95,7 @@ bool ThumbsDbSchemaUpdater::update()
bool success = startUpdates();
// even on failure, try to set current version - it may have incremented
if (d->currentVersion)
{
d->dbAccess->db()->setSetting(QLatin1String("DBThumbnailsVersion"),
......@@ -118,16 +119,19 @@ void ThumbsDbSchemaUpdater::setObserver(InitializationObserver* const observer)
bool ThumbsDbSchemaUpdater::startUpdates()
{
// First step: do we have an empty database?
QStringList tables = d->dbAccess->backend()->tables();
if (tables.contains(QLatin1String("Thumbnails"), Qt::CaseInsensitive))
{
// Find out schema version of db file
QString version = d->dbAccess->db()->getSetting(QLatin1String("DBThumbnailsVersion"));
QString versionRequired = d->dbAccess->db()->getSetting(QLatin1String("DBThumbnailsVersionRequired"));
qCDebug(DIGIKAM_THUMBSDB_LOG) << "Thumbs database: have a structure version " << version;
// mini schema update
if (version.isEmpty() && d->dbAccess->parameters().isSQLite())
{
version = d->dbAccess->db()->getSetting(QLatin1String("DBVersion"));
......@@ -140,6 +144,7 @@ bool ThumbsDbSchemaUpdater::startUpdates()
}
// We absolutely require the DBThumbnailsVersion setting
if (version.isEmpty())
{
// Something is damaged. Give up.
......@@ -163,14 +168,17 @@ bool ThumbsDbSchemaUpdater::startUpdates()
// current version describes the current state of the schema in the db,
// schemaVersion is the version required by the program.
d->currentVersion = version.toInt();
if (d->currentVersion > schemaVersion())
{
// trying to open a database with a more advanced than this ThumbsDbSchemaUpdater supports
if (!versionRequired.isEmpty() && versionRequired.toInt() <= schemaVersion())
{
// version required may be less than current version
return true;
}
else
......@@ -202,6 +210,7 @@ bool ThumbsDbSchemaUpdater::startUpdates()
DbEngineParameters parameters = d->dbAccess->parameters();
// No legacy handling: start with a fresh db
if (!createDatabase())
{
QString errorMsg = i18n("Failed to create tables in database.\n ") +
......
......@@ -43,7 +43,7 @@ namespace Digikam
DCategorizedSortFilterProxyModel::DCategorizedSortFilterProxyModel(QObject* const parent)
: QSortFilterProxyModel(parent),
d(new Private())
d (new Private())
{
setDynamicSortFilter(false);
}
......
......@@ -51,6 +51,8 @@ namespace Digikam
*/
class DIGIKAM_EXPORT DCategorizedSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
enum AdditionalRoles
......@@ -192,6 +194,8 @@ private:
class DIGIKAM_EXPORT ActionSortFilterProxyModel : public DCategorizedSortFilterProxyModel
{
Q_OBJECT
public:
explicit ActionSortFilterProxyModel(QObject* const parent = nullptr);
......
......@@ -43,9 +43,9 @@ class Q_DECL_HIDDEN DCategorizedSortFilterProxyModel::Private
public:
explicit Private()
: sortColumn(0),
sortOrder(Qt::AscendingOrder),
categorizedModel(false),
: sortColumn (0),
sortOrder (Qt::AscendingOrder),
categorizedModel (false),
sortCategoriesByNaturalComparison(true)
{
collator.setNumericMode(true);
......
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