Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fc68afeb authored by Milian Wolff's avatar Milian Wolff

Make the code compile with older Qt

Sadly, we can't yet use the QMetaObject::invokeMethod
that takes a functor...
parent 8f9f8d1c
......@@ -363,6 +363,8 @@ void MainWindow::initialize()
d->setupGui();
qRegisterMetaType<QPointer<KTextEditor::Document>>();
//Queued so we process it with some delay, to make sure the rest of the UI has already adapted
connect(Core::self()->documentController(), &IDocumentController::documentActivated,
// Use a queued connection, because otherwise the view is not yet fully set up
......@@ -370,16 +372,8 @@ void MainWindow::initialize()
// gets deleted in the meantime
this, [this](IDocument *doc) {
const auto textDocument = QPointer<KTextEditor::Document>(doc->textDocument());
QMetaObject::invokeMethod(this, [this, textDocument](){
updateCaption();
// update active document connection
disconnect(d->activeDocumentReadWriteConnection);
if (textDocument) {
d->activeDocumentReadWriteConnection = connect(textDocument, &KTextEditor::Document::readWriteChanged,
this, &MainWindow::updateCaption);
}
}, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "documentActivated", Qt::QueuedConnection,
Q_ARG(QPointer<KTextEditor::Document>, textDocument));
});
connect(Core::self()->documentController(), &IDocumentController::documentClosed, this, &MainWindow::updateCaption, Qt::QueuedConnection);
......@@ -412,6 +406,18 @@ bool MainWindow::queryClose()
return Sublime::MainWindow::queryClose();
}
void MainWindow::documentActivated(const QPointer<KTextEditor::Document>& textDocument)
{
updateCaption();
// update active document connection
disconnect(d->activeDocumentReadWriteConnection);
if (textDocument) {
d->activeDocumentReadWriteConnection = connect(textDocument, &KTextEditor::Document::readWriteChanged,
this, &MainWindow::updateCaption);
}
}
void MainWindow::updateCaption()
{
const auto activeSession = Core::self()->sessionController()->activeSession();
......
......@@ -29,6 +29,7 @@ Boston, MA 02110-1301, USA.
namespace KTextEditor {
class View;
class Document;
}
namespace KTextEditorIntegration {
......@@ -97,6 +98,7 @@ protected Q_SLOTS:
void newTabRequested() override;
private Q_SLOTS:
void documentActivated(const QPointer<KTextEditor::Document>& textDocument);
void updateCaption();
void updateTabColor(IDocument* doc);
......
......@@ -159,21 +159,21 @@ SourceFormatterController::SourceFormatterController(QObject *parent)
this, &SourceFormatterController::updateFormatTextAction);
connect(Core::self()->documentController(), &IDocumentController::documentClosed,
this, &SourceFormatterController::updateFormatTextAction);
qRegisterMetaType<QPointer<KDevelop::TextDocument>>();
connect(Core::self()->documentController(), &IDocumentController::documentLoaded,
// Use a queued connection, because otherwise the view is not yet fully set up
// but wrap the document in a smart pointer to guard against crashes when it
// gets deleted in the meantime
this, [this](IDocument *doc) {
const auto textDoc = QPointer<TextDocument>(dynamic_cast<TextDocument*>(doc));
QMetaObject::invokeMethod(this, [this, textDoc](){
documentLoaded(textDoc);
}, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "documentLoaded", Qt::QueuedConnection, Q_ARG(QPointer<KDevelop::TextDocument>, textDoc));
});
updateFormatTextAction();
}
void SourceFormatterController::documentLoaded(IDocument* doc)
void SourceFormatterController::documentLoaded(const QPointer<TextDocument>& doc)
{
// NOTE: explicitly check this here to prevent crashes on shutdown
// when this slot gets called (note: delayed connection)
......
......@@ -47,6 +47,7 @@ class Context;
class ContextMenuExtension;
class IDocument;
class TextDocument;
class ISourceFormatter;
class IPlugin;
......@@ -145,7 +146,7 @@ private Q_SLOTS:
void beautifySource();
void beautifyLine();
void formatFiles();
void documentLoaded( KDevelop::IDocument* );
void documentLoaded(const QPointer<KDevelop::TextDocument>& doc);
void pluginLoaded(KDevelop::IPlugin* plugin);
void unloadingPlugin(KDevelop::IPlugin* plugin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment