Thu, 15 Mar 2018 18:51:58 +0200
begin work on document loading rework
src/documentloader.cpp | file | annotate | diff | comparison | revisions | |
src/documentloader.h | file | annotate | diff | comparison | revisions | |
src/lddocument.h | file | annotate | diff | comparison | revisions |
--- a/src/documentloader.cpp Thu Mar 15 11:31:39 2018 +0200 +++ b/src/documentloader.cpp Thu Mar 15 18:51:58 2018 +0200 @@ -22,13 +22,16 @@ #include "mainwindow.h" #include "dialogs/openprogressdialog.h" -DocumentLoader::DocumentLoader (Model* model, bool onForeground, QObject *parent) : - QObject (parent), - _model(model), - m_warningCount (0), - m_isDone (false), - m_hasAborted (false), - m_isOnForeground (onForeground) {} +DocumentLoader::DocumentLoader( + Model* model, + LDHeader& header, + bool onForeground, + QObject *parent, +) : + QObject {parent}, + _model {model}, + _header {header}, + m_isOnForeground {onForeground} {} bool DocumentLoader::hasAborted() { @@ -65,7 +68,7 @@ if (fp and fp->isOpen()) { while (not fp->atEnd()) - m_lines << QString::fromUtf8 (fp->readLine()); + m_lines << QString::fromUtf8(fp->readLine()).simplified(); } } @@ -87,7 +90,43 @@ connect (m_progressDialog, SIGNAL (rejected()), this, SLOT (abort())); } else + { m_progressDialog = nullptr; + } + + // Parse the header + while (m_progress < m_lines.size()) + { + const QString& line = m_lines[m_progress]; + + if (not line.isEmpty()) + { + if (line.startsWith("0")) + { + if (m_progress == 0) + { + _header.description = line.mid(1).simplified(); + } + else if (line.startsWith("0 !LDRAW_ORG")) + { + QStringList tokens = line.mid(strlen("0 !LDRAW_ORG")); + } + else if (line.startsWith("0 BFC")) + { + ...; + } + else + { + _model->addFromString(line); + } + m_progress += 1; + } + else + { + break; + } + } + } // Begin working work (0); @@ -109,11 +148,7 @@ for (; i < max and i < (int) countof(m_lines); ++i) { - QString line = m_lines[i].trimmed(); - - // Trim the trailing newline - while (line.endsWith ("\n") or line.endsWith ("\r")) - line.chop(1); + const QString& line = m_lines[i]; if (line == "0 BFC INVERTNEXT") {
--- a/src/documentloader.h Thu Mar 15 11:31:39 2018 +0200 +++ b/src/documentloader.h Thu Mar 15 18:51:58 2018 +0200 @@ -20,6 +20,8 @@ #include "main.h" #include "model.h" +struct LDHeader; + // // DocumentLoader // @@ -31,7 +33,12 @@ Q_OBJECT public: - DocumentLoader (Model* model, bool onForeground = false, QObject* parent = 0); + DocumentLoader( + Model* model, + LDHeader& header, + bool onForeground = false, + QObject* parent = nullptr, + ); Q_SLOT void abort(); bool hasAborted(); @@ -46,12 +53,13 @@ private: class OpenProgressDialog* m_progressDialog; Model* _model; + LDHeader& _header; QStringList m_lines; int m_progress; - int m_warningCount; - bool m_isDone; - bool m_hasAborted; - bool m_isOnForeground; + int m_warningCount = 0; + bool m_isDone = false; + bool m_hasAborted = false; + const bool m_isOnForeground = false; private slots: void work (int i);
--- a/src/lddocument.h Thu Mar 15 11:31:39 2018 +0200 +++ b/src/lddocument.h Thu Mar 15 18:51:58 2018 +0200 @@ -28,6 +28,49 @@ struct LDGLData; class DocumentManager; +struct LDHeader +{ + enum FileType + { + Part, + Subpart, + Shortcut, + Primitive, + Primitive_8, + Primitive_48, + Configuration, + } type = Part; + enum Qualifier + { + Alias = 1 << 0, + Physical_Color = 1 << 1, + Flexible_Section = 1 << 2, + }; + QFlags<Qualifier> qualfiers; + QString description; + QString filename; + struct + { + QString realName; + QString userName; + } author; + QString category; + QString cmdline; + QStringList help; + QStringList keywords; + enum + { + NoWinding, + CounterClockwise, + Clockwise, + } winding = NoWinding; + enum + { + CaLicense, + NonCaLicense + } license = CaLicense; +}; + // // This class stores a document either as a editable file for the user or for // subfile caching. @@ -43,49 +86,6 @@ Q_OBJECT public: - struct Header - { - enum FileType - { - Part, - Subpart, - Shortcut, - Primitive, - Primitive_8, - Primitive_48, - Configuration, - } type; - enum Qualifier - { - Alias = 1 << 0, - Physical_Color = 1 << 1, - Flexible_Section = 1 << 2, - }; - QFlags<Qualifier> qualfiers; - QString description; - QString filename; - struct - { - QString realName; - QString userName; - } author; - QString category; - QString cmdline; - QStringList help; - QStringList keywords; - enum - { - NoWinding, - CounterClockwise, - Clockwise, - } winding = NoWinding; - enum - { - CaLicense, - NonCaLicense - } license = CaLicense; - }; - LDDocument (DocumentManager* parent); ~LDDocument(); @@ -127,6 +127,7 @@ LDObject* withdrawAt(int position); private: + LDHeader m_header; QString m_name; QString m_fullPath; QString m_defaultName; @@ -155,7 +156,7 @@ void handleImminentObjectRemoval(const QModelIndex& index); }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<LDDocument::Header::Qualifier>) +Q_DECLARE_OPERATORS_FOR_FLAGS(QFlags<LDHeader::Qualifier>) // Parses a string line containing an LDraw object and returns the object parsed. LDObject* ParseLine (QString line);