Fix reversed return value logic in QJsonModel::load methods
This commit is contained in:
parent
931009bc38
commit
cd6fac3950
@ -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
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user