Commit a7363fa5 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Better management of member variables destruction in TerminalDisplay

Always pass a parent to a QObject constructor; this is always a good
idea, as it enforces the parent/child relationship, and it also means
the parent QObject will take care of deleting its children, less manual
'delete' calls.

_terminalPainter already has a TerminalDisplay parent object.

Use a std::unique_ptr to manage _printManager (it's not a QObject).
parent 46b56ecf
......@@ -244,7 +244,6 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _drawOverlay(false)
, _scrollBar(nullptr)
, _terminalColor(nullptr)
, _printManager(nullptr)
{
// terminal applications are not designed with Right-To-Left in mind,
// so the layout is forced to Left-To-Right
......@@ -340,7 +339,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
auto lgetBackgroundColor = [this]() {
return _terminalColor->backgroundColor();
};
_printManager = new KonsolePrintManager(ldrawBackground, ldrawContents, lgetBackgroundColor);
_printManager.reset(new KonsolePrintManager(ldrawBackground, ldrawContents, lgetBackgroundColor));
}
TerminalDisplay::~TerminalDisplay()
......@@ -348,16 +348,8 @@ TerminalDisplay::~TerminalDisplay()
disconnect(_blinkTextTimer);
disconnect(_blinkCursorTimer);
delete _readOnlyMessageWidget;
delete _outputSuspendedMessageWidget;
delete[] _image;
delete _filterChain;
_readOnlyMessageWidget = nullptr;
_outputSuspendedMessageWidget = nullptr;
delete _terminalPainter;
delete _printManager;
}
void TerminalDisplay::setupHeaderVisibility()
......@@ -2447,7 +2439,7 @@ void TerminalDisplay::dismissOutputSuspendedMessage()
}
KMessageWidget* TerminalDisplay::createMessageWidget(const QString &text) {
auto widget = new KMessageWidget(text);
auto *widget = new KMessageWidget(text, this);
widget->setWordWrap(true);
widget->setFocusProxy(this);
widget->setCursor(Qt::ArrowCursor);
......
......@@ -13,6 +13,8 @@
#include <QPointer>
#include <QWidget>
#include <memory>
// Konsole
#include "../characters/Character.h"
#include "konsoleprivate_export.h"
......@@ -751,7 +753,7 @@ private:
TerminalColor *_terminalColor;
TerminalFont *_terminalFont;
KonsolePrintManager *_printManager;
std::unique_ptr<KonsolePrintManager> _printManager;
};
}
......
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