mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
86 lines
3.0 KiB
C++
86 lines
3.0 KiB
C++
/* Copyright (C) 2015
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
|
* contained in the LICENSE file.
|
|
*/
|
|
|
|
#include "blackmisc/db/dbflags.h"
|
|
#include "blackmisc/verify.h"
|
|
|
|
#include <QStringList>
|
|
#include <QtGlobal>
|
|
|
|
namespace BlackMisc
|
|
{
|
|
namespace Db
|
|
{
|
|
bool CDbFlags::readsFromWeb(CDbFlags::DataRetrievalMode mode)
|
|
{
|
|
return mode.testFlag(DbReading) || mode.testFlag(Shared);
|
|
}
|
|
|
|
QString CDbFlags::flagToString(CDbFlags::DataRetrievalModeFlag flag)
|
|
{
|
|
switch (flag)
|
|
{
|
|
case Unspecified: return "Unspecified";
|
|
case Ignore: return "Ignore";
|
|
case Canceled: return "Canceled";
|
|
case DbReading: return "Direct DB access";
|
|
case Shared: return "Shared data";
|
|
case Cached: return "Cached data";
|
|
default:
|
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags");
|
|
return "wrong flags";
|
|
}
|
|
}
|
|
|
|
QString CDbFlags::flagToString(CDbFlags::DataRetrievalMode mode)
|
|
{
|
|
QStringList list;
|
|
if (mode.testFlag(Unspecified)) list << "Unspecified";
|
|
if (mode.testFlag(Canceled)) list << "Canceled";
|
|
if (mode.testFlag(Ignore)) list << "Ignore";
|
|
|
|
if (mode.testFlag(DbReading)) list << "Direct DB access";
|
|
if (mode.testFlag(Shared)) list << "Shared data";
|
|
if (mode.testFlag(Cached)) list << "Cached data";
|
|
return list.join(", ");
|
|
}
|
|
|
|
CDbFlags::DataRetrievalModeFlag CDbFlags::modeToModeFlag(DataRetrievalMode mode)
|
|
{
|
|
if (mode == Unspecified) return Unspecified;
|
|
if (mode == DbReading) return DbReading;
|
|
if (mode == DbWriting) return DbWriting;
|
|
if (mode == Shared) return Shared;
|
|
if (mode == SharedInfoOnly) return SharedInfoOnly;
|
|
if (mode == Cached) return Cached;
|
|
if (mode == Canceled) return Canceled;
|
|
if (mode == Ignore) return Ignore;
|
|
return Unspecified;
|
|
}
|
|
|
|
CDbFlags::DataRetrievalMode CDbFlags::adjustWhenDbIsDown(DataRetrievalMode mode)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case DbReading: return Canceled;
|
|
case CacheThenDb: return Cached;
|
|
default: return mode;
|
|
}
|
|
}
|
|
|
|
void CDbFlags::registerMetadata()
|
|
{
|
|
// this is no value class and I register enums here,
|
|
// that's why I do not use the Mixins
|
|
qRegisterMetaType<CDbFlags::DataRetrievalModeFlag>();
|
|
qRegisterMetaType<CDbFlags::DataRetrievalMode>();
|
|
}
|
|
} // namespace
|
|
} // namespace
|