Skip to content

Commit

Permalink
get rid of Helpers::qVariantTypeId()
Browse files Browse the repository at this point in the history
Not needed anymore after Qt v5.15 support removed.

 - also removed PROJECT_TINYDRIVERS_PRIVATE compile definition, not
   needed anymore as well
  • Loading branch information
silverqx committed Jun 30, 2024
1 parent e116027 commit 3ba1397
Show file tree
Hide file tree
Showing 30 changed files with 368 additions and 443 deletions.
2 changes: 0 additions & 2 deletions drivers/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ target_compile_definitions(${TinyDrivers_target}
$<$<NOT:$<CONFIG:Debug>>:TINYDRIVERS_NO_DEBUG>
# Debug build
$<$<CONFIG:Debug>:TINYDRIVERS_DEBUG>
# Used in common header files (currently in replacebindings.hpp only)
PROJECT_TINYDRIVERS_PRIVATE
# To disable #pragma system_header if compiling TinyORM project itself
TINYORM_PRAGMA_SYSTEM_HEADER_OFF
# TinyDrivers support these strict Qt macros
Expand Down
2 changes: 0 additions & 2 deletions drivers/common/common.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ include($$TINYORM_SOURCE_TREE/qmake/common/common.pri)
DEFINES *= PROJECT_TINYDRIVERS
# Private defines
DEFINES *= TINY_QMAKE_BUILD_PRIVATE
# Used in common header files (currently in replacebindings.hpp only)
DEFINES *= PROJECT_TINYDRIVERS_PRIVATE

# Build as the shared library
CONFIG(shared, dll|shared|static|staticlib) | \
Expand Down
4 changes: 0 additions & 4 deletions include/orm/schema/schemabuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ TINY_SYSTEM_HEADER
// Include the blueprint here so the user doesn't have to (it can be forward declared)
#include "orm/schema/blueprint.hpp"
#include "orm/types/sqlquery.hpp"
#include "orm/utils/helpers.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE

Expand All @@ -28,9 +27,6 @@ namespace Grammars
{
Q_DISABLE_COPY_MOVE(SchemaBuilder)

/*! Alias for the helper utils. */
using Helpers = Orm::Utils::Helpers;

public:
/*! Constructor. */
explicit SchemaBuilder(std::shared_ptr<DatabaseConnection> connection);
Expand Down
17 changes: 0 additions & 17 deletions include/orm/support/replacebindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ TINY_SYSTEM_HEADER

#include "orm/macros/commonnamespace.hpp"

#ifndef PROJECT_TINYDRIVERS_PRIVATE
# include "orm/utils/helpers.hpp"
#endif

TINYORM_BEGIN_COMMON_NAMESPACE

namespace Orm::Support
Expand All @@ -28,11 +24,6 @@ namespace Orm::Support
{
Q_DISABLE_COPY_MOVE(ReplaceBindings)

#ifndef PROJECT_TINYDRIVERS_PRIVATE
/*! Alias for the helper utils. */
using Helpers = Orm::Utils::Helpers;
#endif

public:
/*! Deleted default constructor, this is a pure library class. */
ReplaceBindings() = delete;
Expand Down Expand Up @@ -76,11 +67,7 @@ namespace Orm::Support
bindingValue = Null_;

// Support for binary data (BLOB)
#ifdef PROJECT_TINYDRIVERS_PRIVATE
else if (binding.typeId() == QMetaType::QByteArray) {
#else
else if (Helpers::qVariantTypeId(binding) == QMetaType::QByteArray) {
#endif
const auto binaryData = binding.template value<QByteArray>();
const auto binarySize = binaryData.size();
// Don't overwhelm terminal with a lot of text, 512 characters is enough
Expand All @@ -91,11 +78,7 @@ namespace Orm::Support
binaryData.toHex(' ')));
}
// Support for strings quoting
#ifdef PROJECT_TINYDRIVERS_PRIVATE
else if (binding.typeId() == QMetaType::QString) {
#else
else if (Helpers::qVariantTypeId(binding) == QMetaType::QString) {
#endif
const auto textData = binding.template value<QString>();
const auto textSize = textData.size();
// Don't overwhelm terminal with a lot of text, 1024 characters is enough
Expand Down
22 changes: 11 additions & 11 deletions include/orm/tiny/concerns/hasattributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ namespace Orm::Tiny::Concerns
/* If an attribute is listed as a "date", we'll convert it from a DateTime
instance into a form proper for storage on the database tables using
the connection grammar's date format. We will auto set the values. */
if (const auto typeId = Helpers::qVariantTypeId(value);
if (const auto typeId = value.typeId();
value.isValid() && (isDateAttribute(key) ||
// NOTE api different, if the QDateTime or QDate is detected then take it as datetime silverqx
typeId == QMetaType::QDateTime || typeId == QMetaType::QDate ||
Expand Down Expand Up @@ -1688,7 +1688,7 @@ namespace Orm::Tiny::Concerns
/* If this value is already a QDateTime instance, we shall just return it as is.
This prevents us having to re-parse a QDateTime instance when we know
it already is one. */
if (Helpers::qVariantTypeId(value) == QMetaType::QDateTime)
if (value.typeId() == QMetaType::QDateTime)
return convertTimeZone(value.value<QDateTime>());

// The value has to be convertible to the QString so we can work with it
Expand Down Expand Up @@ -1766,7 +1766,7 @@ namespace Orm::Tiny::Concerns
/* If this value is already a QTime instance, we shall just return it as is.
This prevents us having to re-parse a QTime instance when we know
it already is one. */
if (Helpers::qVariantTypeId(value) == QMetaType::QTime)
if (value.typeId() == QMetaType::QTime)
return value.template value<QTime>();

// The value has to be convertible to the QString so we can work with it
Expand Down Expand Up @@ -1808,7 +1808,7 @@ namespace Orm::Tiny::Concerns
{
// This method is used only for u_dates so no QTime handling is applied

const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

if (typeId == QMetaType::QDate ||
(typeId == QMetaType::QString &&
Expand All @@ -1825,7 +1825,7 @@ namespace Orm::Tiny::Concerns
HasAttributes<Derived, AllRelations...>::asDateOrDateTimeOrTime(
const QVariant &value) const
{
const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

if (typeId == QMetaType::QDate ||
(typeId == QMetaType::QString &&
Expand All @@ -1848,7 +1848,7 @@ namespace Orm::Tiny::Concerns
HasAttributes<Derived, AllRelations...>::fromDateOrDateTimeOrTime(
const QVariant &value, const QString &format) const
{
if (const auto typeId = Helpers::qVariantTypeId(value);
if (const auto typeId = value.typeId();
typeId == QMetaType::QDate ||
(typeId == QMetaType::QString &&
Helpers::isStandardDateFormat(value.value<QString>()))
Expand Down Expand Up @@ -1877,7 +1877,7 @@ namespace Orm::Tiny::Concerns
HasAttributes<Derived, AllRelations...>::nullFor_fromDateTime(
const QVariant &value, const QString &format)
{
const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

if (format == QLatin1Char('U')) T_UNLIKELY
return NullVariant::LongLong();
Expand All @@ -1900,7 +1900,7 @@ namespace Orm::Tiny::Concerns
HasAttributes<Derived, AllRelations...>::nullFor_addCastAttributesTo(
const QVariant &value)
{
const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

if (typeId == QMetaType::QDate ||
(typeId == QMetaType::QString &&
Expand Down Expand Up @@ -2350,7 +2350,7 @@ namespace Orm::Tiny::Concerns
HasAttributes<Derived, AllRelations...>::serializeDateOrDateTimeOrTime(
const QVariant &value)
{
const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

if (typeId == QMetaType::QDate ||
(typeId == QMetaType::QString &&
Expand Down Expand Up @@ -2576,7 +2576,7 @@ namespace Orm::Tiny::Concerns

const auto castedDate = asDateOrDateTimeOrTime(value);

if (const auto typeId = Helpers::qVariantTypeId(castedDate);
if (const auto typeId = castedDate.typeId();
typeId == QMetaType::QDate
) T_UNLIKELY
value = castedDate.template value<QDate>().toString(castModifier);
Expand Down Expand Up @@ -2763,7 +2763,7 @@ namespace Orm::Tiny::Concerns
void HasAttributes<Derived, AllRelations...>::serializeDateOrDateTimeForAccessors(
QVariant &value)
{
const auto typeId = Helpers::qVariantTypeId(value);
const auto typeId = value.typeId();

// Nothing to do, not a datetime
if (typeId != QMetaType::QDateTime && typeId != QMetaType::QDate &&
Expand Down
4 changes: 0 additions & 4 deletions include/orm/tiny/concerns/hastimestamps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ TINY_SYSTEM_HEADER

#include "orm/tiny/macros/crtpmodelwithbase.hpp"
#include "orm/tiny/tinyconcepts.hpp" // IWYU pragma: keep
#include "orm/utils/helpers.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE

Expand All @@ -26,9 +25,6 @@ namespace Concerns
template<typename Derived, AllRelationsConcept ...AllRelations>
class HasTimestamps
{
/*! Alias for the helper utils. */
using Helpers = Orm::Utils::Helpers;

public:
/*! Equality comparison operator for the HasTimestamps concern. */
bool operator==(const HasTimestamps &) const noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion include/orm/tiny/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ namespace Orm::Tiny

for (const auto &[key, value] : attributes)
if (value.isValid() && !value.isNull() &&
Helpers::qVariantTypeId(value) == QMetaType::QDateTime
value.typeId() == QMetaType::QDateTime
)
throw Orm::Exceptions::InvalidArgumentError(
message.arg(TypeUtils::classPureBasename<Derived>(), key));
Expand Down
2 changes: 2 additions & 0 deletions include/orm/tiny/tinybuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ TINY_SYSTEM_HEADER
#include <range/v3/action/transform.hpp>

#include "orm/databaseconnection.hpp"
#include "orm/utils/helpers.hpp"

#include "orm/tiny/concerns/buildsqueries.hpp"
#include "orm/tiny/concerns/buildssoftdeletes.hpp"
#include "orm/tiny/concerns/queriesrelationships.hpp"
Expand Down
3 changes: 0 additions & 3 deletions include/orm/utils/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ namespace Utils
inline static std::size_t &hashCombine(std::size_t &seed, const T &value)
noexcept(IsNothrowHashable<std::remove_const_t<T>>::value);

/*! Get the storage type of the value stored in the QVariant. */
static int qVariantTypeId(const QVariant &value);

/*! Log exception caught in the main exception handler in a current thread. */
[[maybe_unused]]
static void logException(const std::exception &e, bool fatal = false);
Expand Down
4 changes: 0 additions & 4 deletions include/orm/utils/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ TINY_SYSTEM_HEADER
#include "orm/macros/export.hpp"
#include "orm/macros/sqldrivermappings.hpp"
#include "orm/support/replacebindings.hpp"
#include "orm/utils/helpers.hpp"

TINY_FORWARD_DECLARE_TSqlQuery

Expand All @@ -26,9 +25,6 @@ namespace Orm::Utils
{
Q_DISABLE_COPY_MOVE(Query)

/*! Alias for the helper utils. */
using Helpers = Orm::Utils::Helpers;

public:
/*! Deleted default constructor, this is a pure library class. */
Query() = delete;
Expand Down
4 changes: 1 addition & 3 deletions src/orm/concerns/parsessearchpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
#include <range/v3/view/transform.hpp>

#include "orm/schema/schemaconstants.hpp"
#include "orm/utils/helpers.hpp"
#include "orm/utils/string.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE

using Orm::Constants::COMMA_C;

using Orm::SchemaNs::Constants::TRIM_QUOTES;
using Orm::Utils::Helpers;

using StringUtils = Orm::Utils::String;

Expand Down Expand Up @@ -72,7 +70,7 @@ QStringList ParsesSearchPath::parseSearchPath(const QVariant &searchPath)
we can be sure here that it's the QString or QStringList. Also don't use
the QVariant::canConvert() here as there are no benefits from it, only pitfalls,
eg. an empty QString if converting from the QStringList. */
if (Helpers::qVariantTypeId(searchPath) == QMetaType::QString)
if (searchPath.typeId() == QMetaType::QString)
return parseSearchPath(searchPath.value<QString>());

return parseSearchPath(searchPath.value<QStringList>());
Expand Down
9 changes: 2 additions & 7 deletions src/orm/configurations/configurationoptionsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "orm/configurations/configurationparser.hpp"
#include "orm/constants.hpp"
#include "orm/exceptions/invalidargumenterror.hpp"
#include "orm/utils/helpers.hpp"
#include "orm/utils/type.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE
Expand All @@ -14,8 +13,6 @@ using Orm::Constants::EQ_C;
using Orm::Constants::SEMICOLON;
using Orm::Constants::options_;

using Orm::Utils::Helpers;

namespace Orm::Configurations
{

Expand Down Expand Up @@ -83,9 +80,7 @@ void ConfigurationOptionsParser::copyOptionsFromTopLevel(

void ConfigurationOptionsParser::validateConfigOptions(const QVariant &options)
{
if (Helpers::qVariantTypeId(options) == QMetaType::QString ||
options.canConvert<QVariantHash>()
)
if (options.typeId() == QMetaType::QString || options.canConvert<QVariantHash>())
return;

throw Exceptions::InvalidArgumentError(
Expand All @@ -100,7 +95,7 @@ QVariantHash ConfigurationOptionsParser::prepareConfigOptions(const QVariant &op
{
/* Nothing to do, already contains the QVariantHas. Input is already validated, so
we can be sure that the 'options' option type is the QVariantHash. */
if (Helpers::qVariantTypeId(options) != QMetaType::QString)
if (options.typeId() != QMetaType::QString)
return options.value<QVariantHash>();

/* The following algorithm converts the QString defined 'options' to the QVariantHash.
Expand Down
11 changes: 4 additions & 7 deletions src/orm/configurations/postgresconfigurationparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "orm/constants.hpp"
#include "orm/exceptions/invalidargumenterror.hpp"
#include "orm/utils/helpers.hpp"
#include "orm/utils/type.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE
Expand All @@ -17,8 +16,6 @@ using Orm::Constants::sslcert;
using Orm::Constants::sslkey;
using Orm::Constants::sslrootcert;

using Orm::Utils::Helpers;

namespace Orm::Configurations
{

Expand Down Expand Up @@ -72,8 +69,8 @@ void PostgresConfigurationParser::throwIfSearchPathHasWrongType() const
if (!config().contains(search_path))
return;

if (const auto type = Helpers::qVariantTypeId(config()[search_path]);
type == QMetaType::QString || type == QMetaType::QStringList
if (const auto typeId = config()[search_path].typeId();
typeId == QMetaType::QString || typeId == QMetaType::QStringList
)
return;

Expand All @@ -91,8 +88,8 @@ void PostgresConfigurationParser::throwIfDontDropHasWrongType() const
if (!config().contains(dont_drop))
return;

if (const auto type = Helpers::qVariantTypeId(config()[dont_drop]);
type == QMetaType::QString || type == QMetaType::QStringList
if (const auto typeId = config()[dont_drop].typeId();
typeId == QMetaType::QString || typeId == QMetaType::QStringList
)
return;

Expand Down
3 changes: 2 additions & 1 deletion src/orm/databaseconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "orm/exceptions/multiplecolumnsselectederror.hpp"
#include "orm/query/querybuilder.hpp"
#include "orm/utils/configuration.hpp"
#include "orm/utils/helpers.hpp"
#include "orm/utils/type.hpp"

TINYORM_BEGIN_COMMON_NAMESPACE
Expand Down Expand Up @@ -374,7 +375,7 @@ DatabaseConnection::prepareBindings(QVector<QVariant> &bindings) const
if (!binding.isValid() || binding.isNull())
continue;

switch (Helpers::qVariantTypeId(binding)) {
switch (binding.typeId()) {
case QMetaType::QDate:
// QDate doesn't have a time zone
binding = binding.value<QDate>().toString(Qt::ISODate);
Expand Down
6 changes: 2 additions & 4 deletions src/orm/query/grammars/sqlitegrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

TINYORM_BEGIN_COMMON_NAMESPACE

using Orm::Utils::Helpers;

namespace Orm::Query::Grammars
{

Expand Down Expand Up @@ -227,15 +225,15 @@ QString SQLiteGrammar::dateBasedWhereColumn(const QString &type,
// Compare as text types
case WhereType::DATE:
case WhereType::TIME:
Q_ASSERT(Helpers::qVariantTypeId(where.value) == QMetaType::QString);
Q_ASSERT(where.value.typeId() == QMetaType::QString);

return QStringLiteral("strftime('%1', %2)").arg(type, wrap(where.column));

// Compare as integral types
case WhereType::DAY:
case WhereType::MONTH:
case WhereType::YEAR:
Q_ASSERT(Helpers::qVariantTypeId(where.value) == QMetaType::Int);
Q_ASSERT(where.value.typeId() == QMetaType::Int);

return QStringLiteral("cast(strftime('%1', %2) as integer)")
.arg(type, wrap(where.column));
Expand Down
Loading

0 comments on commit 3ba1397

Please sign in to comment.