From 17a926c2697143937b0c1700b1d1e8081f727059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Wed, 19 Oct 2016 15:22:31 +0200 Subject: delete useless NewContentModel --- framework/domain/messageparser.h | 25 ------ framework/domain/messageparser_new.cpp | 153 +++++++++------------------------ framework/domain/modeltest.cpp | 2 +- 3 files changed, 44 insertions(+), 136 deletions(-) (limited to 'framework') diff --git a/framework/domain/messageparser.h b/framework/domain/messageparser.h index 55c884f9..559fa6f9 100644 --- a/framework/domain/messageparser.h +++ b/framework/domain/messageparser.h @@ -98,31 +98,6 @@ private: }; -class NewContentModel : public QAbstractItemModel { - Q_OBJECT -public: - NewContentModel (const PartPtr &part, const std::shared_ptr &parser); - -public: - enum Roles { - TypeRole = Qt::UserRole + 1, - ContentRole, - IsEmbededRole, - SecurityLevelRole - }; - - QHash roleNames() const Q_DECL_OVERRIDE; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; - int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - -private: - const PartPtr &mPart; - const std::shared_ptr &mParser; -}; - class NewModel : public QAbstractItemModel { Q_OBJECT public: diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp index da5ab2e7..57f8172f 100644 --- a/framework/domain/messageparser_new.cpp +++ b/framework/domain/messageparser_new.cpp @@ -29,6 +29,11 @@ Q_DECLARE_METATYPE(Encryption *) class Entry { public: + Entry() + : mParent(nullptr) + { + } + ~Entry() { foreach(auto child, mChildren) { @@ -36,7 +41,7 @@ public: } mChildren.clear(); } - + void addChild(Entry *entry) { mChildren.append(entry); @@ -68,6 +73,7 @@ class NewModelPrivate { public: NewModelPrivate(NewModel *q_ptr, const std::shared_ptr &parser); + ~NewModelPrivate(); void createTree(); Entry *addSignatures(Entry *parent, QVector signatures); @@ -88,10 +94,9 @@ public: NewModel *q; QVector mParts; - Entry *mRoot; + std::unique_ptr mRoot; std::shared_ptr mParser; - QMap> mContentMap; private: QMap, QSharedPointer> mSignatureMap; QMap, QSharedPointer> mEncryptionMap; @@ -101,16 +106,18 @@ private: NewModelPrivate::NewModelPrivate(NewModel *q_ptr, const std::shared_ptr &parser) : q(q_ptr) + , mRoot(std::unique_ptr(new Entry)) , mParser(parser) { mParts = mParser->collectContentParts(); - foreach(const auto &part, mParts) { - mContentMap.insert(part.get(), std::shared_ptr(new NewContentModel(part, mParser))); - } createTree(); } -Entry * NewModelPrivate::addSignatures(Entry *parent, QVector signatures) +NewModelPrivate::~NewModelPrivate() +{ +} + +Entry *NewModelPrivate::addSignatures(Entry *parent, QVector signatures) { auto ret = parent; foreach(const auto &sig, signatures) { @@ -160,15 +167,15 @@ Entry * NewModelPrivate::addPart(Entry *parent, Part *part) void NewModelPrivate::createTree() { - mRoot = new Entry(); - auto parent = mRoot; + auto root = mRoot.get(); + auto parent = root; Part *pPart = nullptr; QVector signatures; QVector encryptions; foreach(const auto part, mParts) { auto _parent = parent; if (pPart != part->parent()) { - auto _parent = mRoot; + auto _parent = root; _parent = addEncryptions(_parent, part->parent()->encryptions()); _parent = addSignatures(_parent, part->parent()->signatures()); signatures = part->parent()->signatures(); @@ -202,7 +209,6 @@ QSharedPointer NewModelPrivate::getVar(const std::shared_ptr NewModelPrivate::getVar(const std::shared_ptr &part) { return getVar(part.get()); @@ -259,7 +265,6 @@ int NewModelPrivate::getPos(Encryption *encryption) return i; } - int NewModelPrivate::getPos(Part *part) { int i = 0; @@ -297,20 +302,18 @@ QHash NewModel::roleNames() const { QHash roles; roles[TypeRole] = "type"; - roles[ContentsRole] = "contents"; roles[ContentRole] = "content"; roles[IsEmbededRole] = "embeded"; roles[SecurityLevelRole] = "securityLevel"; return roles; } - QModelIndex NewModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 || column != 0) { return QModelIndex(); } - Entry *entry = d->mRoot; + Entry *entry = d->mRoot.get(); if (parent.isValid()) { entry = static_cast(parent.internalPointer()); } @@ -324,14 +327,27 @@ QModelIndex NewModel::index(int row, int column, const QModelIndex &parent) cons QVariant NewModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { - if (role == Qt::DisplayRole) { + switch (role) { + case Qt::DisplayRole: return QString("root"); + case IsEmbededRole: + return false; } return QVariant(); } + if (index.internalPointer()) { const auto entry = static_cast(index.internalPointer()); const auto _data = entry->mData; + if (entry == d->mRoot.get()|| !_data) { + switch (role) { + case Qt::DisplayRole: + return QString("root"); + case IsEmbededRole: + return false; + } + return QVariant(); + } if (_data->userType() == qMetaTypeId()) { const auto signature = _data->value(); int i = d->getPos(signature); @@ -342,6 +358,8 @@ QVariant NewModel::data(const QModelIndex &index, int role) const return QStringLiteral("Signature"); case SecurityLevelRole: return QStringLiteral("RED"); + case IsEmbededRole: + return data(index.parent(), IsEmbededRole); } } else if (_data->userType() == qMetaTypeId()) { const auto encryption = _data->value(); @@ -353,17 +371,17 @@ QVariant NewModel::data(const QModelIndex &index, int role) const return QStringLiteral("Encryption"); case SecurityLevelRole: return QStringLiteral("GREEN"); + case IsEmbededRole: + return data(index.parent(), IsEmbededRole); } } else if (_data->userType() == qMetaTypeId()) { const auto part = _data->value(); switch (role) { - case Qt::DisplayRole: - case TypeRole: - return QString::fromLatin1(part->type()); - case IsEmbededRole: - return index.parent().isValid(); - case ContentsRole: - return QVariant::fromValue(d->mContentMap.value(part).get()); + case Qt::DisplayRole: + case TypeRole: + return QString::fromLatin1(part->type()); + case IsEmbededRole: + return data(index.parent(), IsEmbededRole); } } else if (_data->userType() == qMetaTypeId()) { const auto content = _data->value(); @@ -374,7 +392,7 @@ QVariant NewModel::data(const QModelIndex &index, int role) const case TypeRole: return QString::fromLatin1(content->type()); case IsEmbededRole: - return false; + return data(index.parent(), IsEmbededRole); case ContentRole: { auto text = content->encodedContent(); if (data(index, TypeRole).toString() == "HtmlContent") { @@ -413,7 +431,7 @@ QModelIndex NewModel::parent(const QModelIndex &index) const return QModelIndex(); } const auto entry = static_cast(index.internalPointer()); - if (entry->mParent) { + if (entry->mParent && entry->mParent != d->mRoot.get()) { return createIndex(entry->pos(), 0, entry->mParent); } return QModelIndex(); @@ -437,88 +455,3 @@ int NewModel::columnCount(const QModelIndex &parent) const { return 1; } - -NewContentModel::NewContentModel(const Part::Ptr &part, const std::shared_ptr &parser) - : mPart(part) - , mParser(parser) -{ -} - -QHash NewContentModel::roleNames() const -{ - QHash roles; - roles[TypeRole] = "type"; - roles[ContentRole] = "content"; - roles[IsEmbededRole] = "embeded"; - roles[SecurityLevelRole] = "securityLevel"; - return roles; -} - -QModelIndex NewContentModel::index(int row, int column, const QModelIndex &parent) const -{ - if (!parent.isValid()) { - if (row < mPart->content().size()) { - auto part = mPart->content().at(row); - return createIndex(row, column, part.get()); - } - } - return QModelIndex(); -} - -QVariant NewContentModel::data(const QModelIndex &index, int role) const -{ - auto content = static_cast(index.internalPointer()); - switch (role) { - case TypeRole: - return QString::fromLatin1(content->type()); - case IsEmbededRole: - return false; - case ContentRole: { - auto text = content->encodedContent(); - if (data(index, TypeRole).toString() == "HtmlContent") { - const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); - int pos = 0; - while ((pos = rx.indexIn(text, pos)) != -1) { - const auto link = QUrl(rx.cap(3).toUtf8()); - pos += rx.matchedLength(); - const auto repl = mParser->getPart(link); - if (!repl) { - continue; - } - const auto content = repl->content(); - if(content.size() < 1) { - continue; - } - const auto mailMime = content.first()->mailMime(); - const auto mimetype = mailMime->mimetype().name(); - if (mimetype.startsWith("image/")) { - const auto data = content.first()->content(); - text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); - } - } - } - return text; - } - case SecurityLevelRole: - return content->encryptions().size() > mPart->encryptions().size() ? "red": "black"; //test for gpg inline - } - return QVariant(); -} - -QModelIndex NewContentModel::parent(const QModelIndex &index) const -{ - return QModelIndex(); -} - -int NewContentModel::rowCount(const QModelIndex &parent) const -{ - if (!parent.isValid()) { - return mPart->content().size(); - } - return 0; -} - -int NewContentModel::columnCount(const QModelIndex &parent) const -{ - return 1; -} diff --git a/framework/domain/modeltest.cpp b/framework/domain/modeltest.cpp index 295ff6d0..9e1d92fa 100644 --- a/framework/domain/modeltest.cpp +++ b/framework/domain/modeltest.cpp @@ -339,7 +339,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) // rowCount() and columnCount() said that it existed... QVERIFY( index.isValid() ); - qWarning() << "\tchild("<< r <<", " << c << ", " << index.column() << "):" << model->data(index).toString(); + qWarning() << "\tchild("<< r <<", " << c << ", " << index.column() << "):" << model->data(index).toString() << index.internalPointer(); // index() should always return the same index when called twice in a row QModelIndex modifiedIndex = model->index ( r, c, parent ); -- cgit v1.2.3