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 }
# 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.EnumConstantPrefix, value: '' }
- { key: readability-identifier-naming.EnumConstantPrefix, value: 'k' }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
# Constant Expression

View File

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

View File

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