corelib/serialization examples: clang-tidy and coding style clean-up
I overrode clang-tidy where it uglified or obfuscated and did some clean-up provoked or made possible by its changes. Konrad pointed out, in review, a constructor that could be = default; it could, in fact, vanish entirely as a result. Task-number: QTBUG-111228 Change-Id: I9b7744a3abaa29e6f9e0689d0f6985bfd88cd0fd Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io> (cherry picked from commit d8517fb1ab83e7051b1d2c2152014e7ff1760426) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d066497527
commit
ca9a3ba6c8
@ -144,11 +144,7 @@ enum {
|
||||
//! [0]
|
||||
struct CborDumper
|
||||
{
|
||||
enum DumpOption {
|
||||
ShowCompact = 0x01,
|
||||
ShowWidthIndicators = 0x02,
|
||||
ShowAnnotated = 0x04
|
||||
};
|
||||
enum DumpOption { ShowCompact = 0x01, ShowWidthIndicators = 0x02, ShowAnnotated = 0x04 };
|
||||
Q_DECLARE_FLAGS(DumpOptions, DumpOption)
|
||||
|
||||
CborDumper(QFile *f, DumpOptions opts_);
|
||||
@ -185,8 +181,7 @@ static int cborNumberSize(quint64 value)
|
||||
return normalSize;
|
||||
}
|
||||
|
||||
CborDumper::CborDumper(QFile *f, DumpOptions opts_)
|
||||
: opts(opts_)
|
||||
CborDumper::CborDumper(QFile *f, DumpOptions opts_) : opts(opts_)
|
||||
{
|
||||
// try to mmap the file, this is faster
|
||||
char *ptr = reinterpret_cast<char *>(f->map(0, f->size(), QFile::MapPrivateOption));
|
||||
@ -233,7 +228,8 @@ QCborError CborDumper::dump()
|
||||
return err;
|
||||
}
|
||||
|
||||
template <typename T> static inline bool canConvertTo(double v)
|
||||
template<typename T>
|
||||
static inline bool canConvertTo(double v)
|
||||
{
|
||||
using TypeInfo = std::numeric_limits<T>;
|
||||
// The [conv.fpint] (7.10 Floating-integral conversions) section of the
|
||||
@ -688,7 +684,9 @@ void CborDumper::printByteArray(const QByteArray &ba)
|
||||
break;
|
||||
|
||||
case quint8(QCborKnownTags::ExpectedBase64url):
|
||||
printf("b64'%s'", ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals).constData());
|
||||
printf("b64'%s'",
|
||||
ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)
|
||||
.constData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,8 @@ QVariant CborDiagnosticDumper::loadFile(QIODevice *f, Converter *&outputConverte
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
|
||||
void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents,
|
||||
const QStringList &options)
|
||||
{
|
||||
QCborValue::DiagnosticNotationOptions opts = QCborValue::LineWrapped;
|
||||
for (const QString &s : options) {
|
||||
@ -183,8 +184,7 @@ void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents, cons
|
||||
}
|
||||
|
||||
QTextStream out(f);
|
||||
out << convertFromVariant(contents, Double).toDiagnosticNotation(opts)
|
||||
<< Qt::endl;
|
||||
out << convertFromVariant(contents, Double).toDiagnosticNotation(opts) << Qt::endl;
|
||||
}
|
||||
|
||||
CborConverter::CborConverter()
|
||||
@ -320,8 +320,9 @@ void CborConverter::saveFile(QIODevice *f, const QVariant &contents, const QStri
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
//! [4]
|
||||
QCborValue v = convertFromVariant(contents,
|
||||
useFloat16 == Always ? Float16 : useFloat == Always ? Float : Double);
|
||||
QCborValue v =
|
||||
convertFromVariant(contents,
|
||||
useFloat16 == Always ? Float16 : useFloat == Always ? Float : Double);
|
||||
QCborStreamWriter writer(f);
|
||||
if (useSignature)
|
||||
writer.append(QCborKnownTags::Signature);
|
||||
|
@ -32,13 +32,9 @@ protected:
|
||||
public:
|
||||
static Converter *null;
|
||||
|
||||
enum Direction {
|
||||
In = 1, Out = 2, InOut = 3
|
||||
};
|
||||
enum Direction { In = 1, Out = 2, InOut = 3 };
|
||||
|
||||
enum Option {
|
||||
SupportsArbitraryMapKeys = 0x01
|
||||
};
|
||||
enum Option { SupportsArbitraryMapKeys = 0x01 };
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
|
||||
virtual ~Converter() = 0;
|
||||
|
@ -44,7 +44,6 @@ QDataStream &operator>>(QDataStream &ds, VariantOrderedMap &map)
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
||||
static QString dumpVariant(const QVariant &v, const QString &indent = "\n"_L1)
|
||||
{
|
||||
QString result;
|
||||
@ -52,15 +51,14 @@ static QString dumpVariant(const QVariant &v, const QString &indent = "\n"_L1)
|
||||
|
||||
int type = v.userType();
|
||||
if (type == qMetaTypeId<VariantOrderedMap>() || type == QMetaType::QVariantMap) {
|
||||
const auto map = (type == QMetaType::QVariantMap) ?
|
||||
VariantOrderedMap(v.toMap()) : qvariant_cast<VariantOrderedMap>(v);
|
||||
const auto map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap())
|
||||
: qvariant_cast<VariantOrderedMap>(v);
|
||||
|
||||
result = "Map {"_L1;
|
||||
for (const auto &pair : map) {
|
||||
result += indented + dumpVariant(pair.first, indented);
|
||||
result.chop(1); // remove comma
|
||||
result += " => "_L1 + dumpVariant(pair.second, indented);
|
||||
|
||||
}
|
||||
result.chop(1); // remove comma
|
||||
result += indent + "},"_L1;
|
||||
@ -159,8 +157,7 @@ QVariant DataStreamConverter::loadFile(QIODevice *f, Converter *&outputConverter
|
||||
outputConverter = &dataStreamDumper;
|
||||
|
||||
char c;
|
||||
if (f->read(sizeof(signature) -1) != signature ||
|
||||
!f->getChar(&c) || (c != 'l' && c != 'B')) {
|
||||
if (f->read(sizeof(signature) - 1) != signature || !f->getChar(&c) || (c != 'l' && c != 'B')) {
|
||||
fprintf(stderr, "Could not load QDataStream file: invalid signature.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -177,7 +174,8 @@ QVariant DataStreamConverter::loadFile(QIODevice *f, Converter *&outputConverter
|
||||
return result;
|
||||
}
|
||||
|
||||
void DataStreamConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
|
||||
void DataStreamConverter::saveFile(QIODevice *f, const QVariant &contents,
|
||||
const QStringList &options)
|
||||
{
|
||||
QDataStream::Version version = QDataStream::Qt_6_0;
|
||||
auto order = QDataStream::ByteOrder(QSysInfo::ByteOrder);
|
||||
|
@ -13,8 +13,7 @@ using namespace Qt::StringLiterals;
|
||||
|
||||
static JsonConverter jsonConverter;
|
||||
|
||||
static const char jsonOptionHelp[] =
|
||||
"compact=no|yes Use compact JSON form.\n";
|
||||
static const char jsonOptionHelp[] = "compact=no|yes Use compact JSON form.\n";
|
||||
|
||||
static QJsonDocument convertFromVariant(const QVariant &v)
|
||||
{
|
||||
@ -26,10 +25,6 @@ static QJsonDocument convertFromVariant(const QVariant &v)
|
||||
return doc;
|
||||
}
|
||||
|
||||
JsonConverter::JsonConverter()
|
||||
{
|
||||
}
|
||||
|
||||
QString JsonConverter::name()
|
||||
{
|
||||
return "json"_L1;
|
||||
|
@ -8,9 +8,6 @@
|
||||
|
||||
class JsonConverter : public Converter
|
||||
{
|
||||
public:
|
||||
JsonConverter();
|
||||
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() override;
|
||||
|
@ -89,10 +89,12 @@ int main(int argc, char *argv[])
|
||||
for (Converter *conv : std::as_const(*availableConverters)) {
|
||||
if (conv->name() == format) {
|
||||
const char *help = conv->optionsHelp();
|
||||
if (help)
|
||||
printf("The following options are available for format '%s':\n\n%s", qPrintable(format), help);
|
||||
else
|
||||
if (help) {
|
||||
printf("The following options are available for format '%s':\n\n%s",
|
||||
qPrintable(format), help);
|
||||
} else {
|
||||
printf("Format '%s' supports no options.\n", qPrintable(format));
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ QVariant NullConverter::loadFile(QIODevice *f, Converter *&outputConverter)
|
||||
void NullConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
|
||||
{
|
||||
if (!options.isEmpty()) {
|
||||
fprintf(stderr, "Unknown option '%s' to null output. This format has no options.\n", qPrintable(options.first()));
|
||||
fprintf(stderr, "Unknown option '%s' to null output. This format has no options.\n",
|
||||
qPrintable(options.first()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,8 @@ QVariant TextConverter::loadFile(QIODevice *f, Converter *&outputConverter)
|
||||
void TextConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
|
||||
{
|
||||
if (!options.isEmpty()) {
|
||||
fprintf(stderr, "Unknown option '%s' to text output. This format has no options.\n", qPrintable(options.first()));
|
||||
fprintf(stderr, "Unknown option '%s' to text output. This format has no options.\n",
|
||||
qPrintable(options.first()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
class TextConverter : public Converter
|
||||
{
|
||||
|
||||
// Converter interface
|
||||
public:
|
||||
QString name() override;
|
||||
|
@ -15,8 +15,7 @@
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
static const char xmlOptionHelp[] =
|
||||
"compact=no|yes Use compact XML form.\n";
|
||||
static const char xmlOptionHelp[] = "compact=no|yes Use compact XML form.\n";
|
||||
|
||||
static XmlConverter xmlConverter;
|
||||
|
||||
@ -49,8 +48,7 @@ static QVariantList listFromXml(QXmlStreamReader &xml, Converter::Options option
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(),
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n", xml.lineNumber(), xml.columnNumber(),
|
||||
qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -59,7 +57,8 @@ static QVariantList listFromXml(QXmlStreamReader &xml, Converter::Options option
|
||||
return list;
|
||||
}
|
||||
|
||||
static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml, Converter::Options options)
|
||||
static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml,
|
||||
Converter::Options options)
|
||||
{
|
||||
QVariant key, value;
|
||||
while (!xml.atEnd() && !(xml.isEndElement() && xml.name() == "entry"_L1)) {
|
||||
@ -91,8 +90,7 @@ static VariantOrderedMap::value_type mapEntryFromXml(QXmlStreamReader &xml, Conv
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(),
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n", xml.lineNumber(), xml.columnNumber(),
|
||||
qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -136,8 +134,7 @@ static QVariant mapFromXml(QXmlStreamReader &xml, Converter::Options options)
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(),
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n", xml.lineNumber(), xml.columnNumber(),
|
||||
qPrintable(xml.tokenString()), qPrintable(xml.name().toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -171,8 +168,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
|
||||
if (xml.isCDATA() || xml.isCharacters() || xml.isEndElement())
|
||||
break;
|
||||
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(),
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n", xml.lineNumber(), xml.columnNumber(),
|
||||
qPrintable(xml.tokenString()), qPrintable(name.toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -269,8 +265,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
|
||||
} while (xml.isComment() || xml.isWhitespace());
|
||||
|
||||
if (!xml.isEndElement()) {
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(),
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML %s '%s'.\n", xml.lineNumber(), xml.columnNumber(),
|
||||
qPrintable(xml.tokenString()), qPrintable(name.toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -289,9 +284,9 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
|
||||
variantToXml(xml, v);
|
||||
xml.writeEndElement();
|
||||
} else if (type == QMetaType::QVariantMap || type == qMetaTypeId<VariantOrderedMap>()) {
|
||||
const VariantOrderedMap map = (type == QMetaType::QVariantMap) ?
|
||||
VariantOrderedMap(v.toMap()) :
|
||||
qvariant_cast<VariantOrderedMap>(v);
|
||||
const VariantOrderedMap map = (type == QMetaType::QVariantMap)
|
||||
? VariantOrderedMap(v.toMap())
|
||||
: qvariant_cast<VariantOrderedMap>(v);
|
||||
|
||||
xml.writeStartElement("map");
|
||||
for (const auto &pair : map) {
|
||||
|
@ -6,15 +6,10 @@
|
||||
#include <QMetaEnum>
|
||||
#include <QTextStream>
|
||||
|
||||
Character::Character()
|
||||
= default;
|
||||
Character::Character() = default;
|
||||
|
||||
Character::Character(const QString &name,
|
||||
int level,
|
||||
Character::ClassType classType) :
|
||||
mName(name),
|
||||
mLevel(level),
|
||||
mClassType(classType)
|
||||
Character::Character(const QString &name, int level, Character::ClassType classType)
|
||||
: mName(name), mLevel(level), mClassType(classType)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,7 @@ class Character
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
enum ClassType {
|
||||
Warrior, Mage, Archer
|
||||
};
|
||||
enum ClassType { Warrior, Mage, Archer };
|
||||
Q_ENUM(ClassType)
|
||||
|
||||
Character();
|
||||
@ -37,6 +35,7 @@ public:
|
||||
QJsonObject toJson() const;
|
||||
|
||||
void print(QTextStream &s, int indentation = 0) const;
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
int mLevel = 0;
|
||||
|
@ -38,11 +38,9 @@ void Game::newGame()
|
||||
QList<Character> villageNpcs;
|
||||
villageNpcs.reserve(2);
|
||||
villageNpcs.append(Character("Barry the Blacksmith"_L1,
|
||||
QRandomGenerator::global()->bounded(8, 11),
|
||||
Character::Warrior));
|
||||
QRandomGenerator::global()->bounded(8, 11), Character::Warrior));
|
||||
villageNpcs.append(Character("Terry the Trader"_L1,
|
||||
QRandomGenerator::global()->bounded(6, 8),
|
||||
Character::Warrior));
|
||||
QRandomGenerator::global()->bounded(6, 8), Character::Warrior));
|
||||
village.setNpcs(villageNpcs);
|
||||
mLevels.append(village);
|
||||
|
||||
@ -50,14 +48,11 @@ void Game::newGame()
|
||||
QList<Character> dungeonNpcs;
|
||||
dungeonNpcs.reserve(3);
|
||||
dungeonNpcs.append(Character("Eric the Evil"_L1,
|
||||
QRandomGenerator::global()->bounded(18, 26),
|
||||
Character::Mage));
|
||||
QRandomGenerator::global()->bounded(18, 26), Character::Mage));
|
||||
dungeonNpcs.append(Character("Eric's Left Minion"_L1,
|
||||
QRandomGenerator::global()->bounded(5, 7),
|
||||
Character::Warrior));
|
||||
QRandomGenerator::global()->bounded(5, 7), Character::Warrior));
|
||||
dungeonNpcs.append(Character("Eric's Right Minion"_L1,
|
||||
QRandomGenerator::global()->bounded(4, 9),
|
||||
Character::Warrior));
|
||||
QRandomGenerator::global()->bounded(4, 9), Character::Warrior));
|
||||
dungeon.setNpcs(dungeonNpcs);
|
||||
mLevels.append(dungeon);
|
||||
}
|
||||
@ -81,10 +76,8 @@ bool Game::loadGame(Game::SaveFormat saveFormat)
|
||||
|
||||
read(loadDoc.object());
|
||||
|
||||
QTextStream(stdout) << "Loaded save for "
|
||||
<< loadDoc["player"]["name"].toString()
|
||||
<< " using "
|
||||
<< (saveFormat != Json ? "CBOR" : "JSON") << "...\n";
|
||||
QTextStream(stdout) << "Loaded save for " << loadDoc["player"]["name"].toString()
|
||||
<< " using " << (saveFormat != Json ? "CBOR" : "JSON") << "...\n";
|
||||
return true;
|
||||
}
|
||||
//! [loadGame]
|
||||
@ -100,9 +93,8 @@ bool Game::saveGame(Game::SaveFormat saveFormat) const
|
||||
}
|
||||
|
||||
QJsonObject gameObject = toJson();
|
||||
saveFile.write(saveFormat == Json
|
||||
? QJsonDocument(gameObject).toJson()
|
||||
: QCborValue::fromJsonValue(gameObject).toCbor());
|
||||
saveFile.write(saveFormat == Json ? QJsonDocument(gameObject).toJson()
|
||||
: QCborValue::fromJsonValue(gameObject).toCbor());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -16,9 +16,7 @@ QT_FORWARD_DECLARE_CLASS(QTextStream)
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
enum SaveFormat {
|
||||
Json, Binary
|
||||
};
|
||||
enum SaveFormat { Json, Binary };
|
||||
|
||||
Character player() const;
|
||||
QList<Level> levels() const;
|
||||
@ -31,6 +29,7 @@ public:
|
||||
QJsonObject toJson() const;
|
||||
|
||||
void print(QTextStream &s, int indentation = 0) const;
|
||||
|
||||
private:
|
||||
Character mPlayer;
|
||||
QList<Level> mLevels;
|
||||
|
@ -6,9 +6,7 @@
|
||||
#include <QJsonArray>
|
||||
#include <QTextStream>
|
||||
|
||||
Level::Level(const QString &name) : mName(name)
|
||||
{
|
||||
}
|
||||
Level::Level(const QString &name) : mName(name) { }
|
||||
|
||||
QString Level::name() const
|
||||
{
|
||||
@ -61,8 +59,7 @@ void Level::print(QTextStream &s, int indentation) const
|
||||
{
|
||||
const QString indent(indentation * 2, ' ');
|
||||
|
||||
s << indent << "Name:\t" << mName << "\n"
|
||||
<< indent << "NPCs:\n";
|
||||
s << indent << "Name:\t" << mName << "\n" << indent << "NPCs:\n";
|
||||
for (const Character &character : mNpcs)
|
||||
character.print(s, indentation + 1);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
QJsonObject toJson() const;
|
||||
|
||||
void print(QTextStream &s, int indentation = 0) const;
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
QList<Character> mNpcs;
|
||||
|
@ -23,8 +23,7 @@
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
//! [0]
|
||||
MainWindow::MainWindow()
|
||||
: treeWidget(new QTreeWidget)
|
||||
MainWindow::MainWindow() : treeWidget(new QTreeWidget)
|
||||
{
|
||||
treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
treeWidget->setHeaderLabels(QStringList{tr("Title"), tr("Location")});
|
||||
@ -101,21 +100,19 @@ void MainWindow::open()
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
|
||||
tr("Cannot read file %1:\n%2.")
|
||||
.arg(QDir::toNativeSeparators(fileName),
|
||||
file.errorString()));
|
||||
.arg(QDir::toNativeSeparators(fileName), file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
XbelReader reader(treeWidget);
|
||||
if (!reader.read(&file)) {
|
||||
QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
|
||||
tr("Parse error in file %1:\n\n%2")
|
||||
.arg(QDir::toNativeSeparators(fileName),
|
||||
reader.errorString()));
|
||||
QMessageBox::warning(
|
||||
this, tr("QXmlStream Bookmarks"),
|
||||
tr("Parse error in file %1:\n\n%2")
|
||||
.arg(QDir::toNativeSeparators(fileName), reader.errorString()));
|
||||
} else {
|
||||
statusBar()->showMessage(tr("File loaded"), 2000);
|
||||
}
|
||||
|
||||
}
|
||||
//! [3]
|
||||
|
||||
@ -134,8 +131,7 @@ void MainWindow::saveAs()
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
|
||||
tr("Cannot write file %1:\n%2.")
|
||||
.arg(QDir::toNativeSeparators(fileName),
|
||||
file.errorString()));
|
||||
.arg(QDir::toNativeSeparators(fileName), file.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,15 +9,13 @@
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
//! [0]
|
||||
XbelReader::XbelReader(QTreeWidget *treeWidget)
|
||||
: treeWidget(treeWidget)
|
||||
XbelReader::XbelReader(QTreeWidget *treeWidget) : treeWidget(treeWidget)
|
||||
{
|
||||
QStyle *style = treeWidget->style();
|
||||
|
||||
folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon),
|
||||
QIcon::Normal, QIcon::Off);
|
||||
folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon),
|
||||
QIcon::Normal, QIcon::On);
|
||||
folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal,
|
||||
QIcon::Off);
|
||||
folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);
|
||||
bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
|
||||
}
|
||||
//! [0]
|
||||
@ -28,12 +26,10 @@ bool XbelReader::read(QIODevice *device)
|
||||
xml.setDevice(device);
|
||||
|
||||
if (xml.readNextStartElement()) {
|
||||
if (xml.name() == "xbel"_L1
|
||||
&& xml.attributes().value("version"_L1) == "1.0"_L1) {
|
||||
if (xml.name() == "xbel"_L1 && xml.attributes().value("version"_L1) == "1.0"_L1)
|
||||
readXBEL();
|
||||
} else {
|
||||
else
|
||||
xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
|
||||
}
|
||||
}
|
||||
|
||||
return !xml.error();
|
||||
|
@ -9,8 +9,7 @@
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
//! [0]
|
||||
XbelWriter::XbelWriter(const QTreeWidget *treeWidget)
|
||||
: treeWidget(treeWidget)
|
||||
XbelWriter::XbelWriter(const QTreeWidget *treeWidget) : treeWidget(treeWidget)
|
||||
{
|
||||
xml.setAutoFormatting(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user