diff --git a/components/Document.h b/components/Document.h --- a/components/Document.h +++ b/components/Document.h @@ -80,7 +80,7 @@ /** * \property textEditor - * \brief The instance of QTextEditor for the currently selected object in the document, or null + * \brief The instance of KoTextEditor for the currently selected object in the document, or null * * \default null * \get textEditor() const diff --git a/components/Document.cpp b/components/Document.cpp --- a/components/Document.cpp +++ b/components/Document.cpp @@ -43,7 +43,7 @@ class Document::Private { public: - Private(Document* qq) : q{qq}, impl{nullptr}, status{DocumentStatus::Unloaded}, textEditor{nullptr} + Private(Document* qq) : q{qq}, impl{nullptr}, status{DocumentStatus::Unloaded} { } void updateImpl(); @@ -53,7 +53,6 @@ QUrl source; DocumentImpl* impl; DocumentStatus::Status status; - KoTextEditor* textEditor; }; Document::Document(QObject* parent) @@ -213,15 +212,7 @@ QObject * Document::textEditor() { if (d->impl && d->impl->canvasController()) { - if (d->textEditor) { - disconnect(d->textEditor, SIGNAL(cursorPositionChanged()), this, SIGNAL(selectionChanged())); - } - d->textEditor = KoTextEditor::getTextEditorFromCanvas(d->impl->canvasController()->canvas()); - if (d->textEditor) { - disconnect(d->textEditor, SIGNAL(cursorPositionChanged()), this, SIGNAL(selectionChanged())); - } -// emit selectionChanged(); - return d->textEditor; + return KoTextEditor::getTextEditorFromCanvas(d->impl->canvasController()->canvas()); } return 0; } @@ -238,28 +229,22 @@ void Document::Private::updateImpl() { - if(impl) { - delete impl; - } - - if(!source.isEmpty()) { - auto type = Global::documentType(source); - switch(type) { - case DocumentType::TextDocument: - impl = new TextDocumentImpl{q}; - break; - case DocumentType::Spreadsheet: - impl = new SpreadsheetImpl{q}; - break; - case DocumentType::Presentation: - impl = new PresentationImpl{q}; - break; - default: - impl = nullptr; - break; - } - } else { - impl = nullptr; + delete impl; + impl = nullptr; + + auto type = Global::documentType(source); + switch(type) { + case DocumentType::TextDocument: + impl = new TextDocumentImpl{q}; + break; + case DocumentType::Spreadsheet: + impl = new SpreadsheetImpl{q}; + break; + case DocumentType::Presentation: + impl = new PresentationImpl{q}; + break; + default: + break; } if(impl) { diff --git a/components/Global.h b/components/Global.h --- a/components/Global.h +++ b/components/Global.h @@ -41,7 +41,6 @@ public: explicit Global(QObject* parent = 0); - static Q_INVOKABLE void loadPlugins(); static Q_INVOKABLE int documentType(const QUrl& document); }; diff --git a/components/Global.cpp b/components/Global.cpp --- a/components/Global.cpp +++ b/components/Global.cpp @@ -45,14 +45,14 @@ { } -void Global::loadPlugins() -{ - -} - int Global::documentType(const QUrl& document) { int result = DocumentType::Unknown; + + if (!document.isValid()) { + return result; + } + const QUrlQuery query(document); // First, check if the URL gives us specific information on this topic (such as asking for a new file) diff --git a/components/ImageDataItem.cpp b/components/ImageDataItem.cpp --- a/components/ImageDataItem.cpp +++ b/components/ImageDataItem.cpp @@ -80,9 +80,7 @@ texNode->setRect(0, 0, w, h); auto texture = window()->createTextureFromImage(d->data); - if(texNode->texture()) { - delete texNode->texture(); - } + delete texNode->texture(); texNode->setTexture(texture); return texNode; diff --git a/components/impl/PresentationImpl.cpp b/components/impl/PresentationImpl.cpp --- a/components/impl/PresentationImpl.cpp +++ b/components/impl/PresentationImpl.cpp @@ -159,10 +159,8 @@ bool PresentationImpl::load(const QUrl& url) { - if(d->part) { - delete d->part; - delete d->document; - } + delete d->part; + delete d->document; d->part = new KPrPart{this}; d->document = new KPrDocument{d->part}; diff --git a/components/impl/SpreadsheetImpl.cpp b/components/impl/SpreadsheetImpl.cpp --- a/components/impl/SpreadsheetImpl.cpp +++ b/components/impl/SpreadsheetImpl.cpp @@ -160,10 +160,8 @@ bool SpreadsheetImpl::load(const QUrl& url) { - if(d->part) { - delete d->part; - delete d->document; - } + delete d->part; + delete d->document; d->part = new Calligra::Sheets::Part{this}; d->document = new Calligra::Sheets::Doc{d->part}; diff --git a/components/impl/TextDocumentImpl.cpp b/components/impl/TextDocumentImpl.cpp --- a/components/impl/TextDocumentImpl.cpp +++ b/components/impl/TextDocumentImpl.cpp @@ -175,10 +175,8 @@ bool TextDocumentImpl::load(const QUrl& url) { - if(d->part) { - delete d->part; - delete d->document; - } + delete d->part; + delete d->document; d->part = new KWPart{this}; d->document = new KWDocument{d->part}; diff --git a/components/models/ContentsModel.cpp b/components/models/ContentsModel.cpp --- a/components/models/ContentsModel.cpp +++ b/components/models/ContentsModel.cpp @@ -142,10 +142,8 @@ void ContentsModel::updateImpl() { beginResetModel(); - - if(d->impl) { - delete d->impl; - } + delete d->impl; + d->impl = nullptr; if(d->document && d->document->status() == DocumentStatus::Loaded) { switch(d->document->documentType()) { @@ -162,11 +160,8 @@ d->impl = new PresentationContentsModelImpl{d->document->koDocument()}; break; default: - d->impl = nullptr; break; } - } else { - d->impl = nullptr; } if(d->impl) {