Fix reversed return value logic in QJsonModel::load methods

This commit is contained in:
S David 2024-05-05 19:53:08 -04:00
parent 931009bc38
commit cd6fac3950
3 changed files with 16 additions and 12 deletions

View File

@ -66,10 +66,10 @@ CheckOptions:
- { key: readability-identifier-naming.PrivateMemberCase, value: camelBack } - { key: readability-identifier-naming.PrivateMemberCase, value: camelBack }
# Constants and Enum Values # Constants and Enum Values
- { key: readability-identifier-naming.ConstantPrefix, value: 'k' } - { key: readability-identifier-naming.ConstantPrefix, value: 'k_' }
- { key: readability-identifier-naming.ConstantCase, value: CamelBack } - { key: readability-identifier-naming.ConstantCase, value: CamelBack }
- { key: readability-identifier-naming.EnumConstantPrefix, value: '' } - { key: readability-identifier-naming.EnumConstantPrefix, value: 'k' }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase } - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
# Constant Expression # Constant Expression

View File

@ -32,7 +32,9 @@
#include <QFont> #include <QFont>
namespace { namespace {
using FieldPermissions = QJsonModel::FieldPermissions; using FieldPermissions = QJsonModel::FieldPermissions;
using ErrorFlag = QJsonModel::ErrorFlag;
constexpr int kKeyColumn = 0; constexpr int kKeyColumn = 0;
constexpr int kValueColumn = 1; constexpr int kValueColumn = 1;
@ -86,27 +88,28 @@ QJsonModel::~QJsonModel()
delete rootItem; delete rootItem;
} }
bool QJsonModel::load(const QString& fileName) ErrorFlag QJsonModel::load(const QString& fileName)
{ {
QFile file(fileName); QFile file(fileName);
bool success = false; ErrorFlag result = false;
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
success = load(&file); result = load(&file);
file.close(); file.close();
} else { } else {
success = false; result = true;
} }
return success; return result;
} }
bool QJsonModel::load(QIODevice* device) ErrorFlag QJsonModel::load(QIODevice* device)
{ {
QTextStream content(device); QTextStream content(device);
return loadJson(content.readAll().toUtf8()); return loadJson(content.readAll().toUtf8());
} }
bool QJsonModel::loadJson(const QByteArray& json) ErrorFlag QJsonModel::loadJson(const QByteArray& json)
{ {
auto const& jdoc = QJsonDocument::fromJson(json); auto const& jdoc = QJsonDocument::fromJson(json);

View File

@ -69,9 +69,10 @@ class QJsonModel : public QAbstractItemModel {
~QJsonModel() override; ~QJsonModel() override;
bool load(const QString& fileName); using ErrorFlag = bool;
bool load(QIODevice* file); ErrorFlag load(const QString& fileName);
bool loadJson(const QByteArray& json); ErrorFlag load(QIODevice* file);
ErrorFlag loadJson(const QByteArray& json);
QVariant data(const QModelIndex& index, int role) const override; QVariant data(const QModelIndex& index, int role) const override;
bool setData( bool setData(
const QModelIndex& index, const QVariant& value, const QModelIndex& index, const QVariant& value,