Use QPointer

This commit is contained in:
Alex Spataru 2021-12-17 02:12:48 -05:00
parent 6685e67176
commit 8fc81d5be7
4 changed files with 17 additions and 8 deletions

View File

@ -47,7 +47,6 @@ namespace UI
WidgetLoader::WidgetLoader(QQuickItem *parent)
: QQuickPaintedItem(parent)
, m_index(-1)
, m_widget(nullptr)
, m_widgetVisible(false)
, m_isExternalWindow(false)
{
@ -224,6 +223,14 @@ UI::Dashboard::WidgetType WidgetLoader::widgetType() const
return UI::Dashboard::getInstance()->widgetType(widgetIndex());
}
/**
* Returns a pointer to the current widget
*/
QWidget* WidgetLoader::widget() const
{
return m_widget;
}
/**
* Changes the visibility & enabled status of the widget
*/
@ -381,7 +388,7 @@ void WidgetLoader::processLeaveEvent(QEvent *event)
using QWidget::leaveEvent;
};
auto hack = static_cast<Hack *>(m_widget);
auto hack = static_cast<Hack *>(widget());
hack->leaveEvent(event);
update();
}
@ -400,7 +407,7 @@ void WidgetLoader::processEnterEvent(QEnterEvent *event)
using QWidget::enterEvent;
};
auto hack = static_cast<Hack *>(m_widget);
auto hack = static_cast<Hack *>(widget());
hack->enterEvent(event);
update();
}
@ -422,7 +429,7 @@ void WidgetLoader::processMouseEvents(QMouseEvent *event)
using QWidget::mouseReleaseEvent;
};
auto hack = static_cast<Hack *>(m_widget);
auto hack = static_cast<Hack *>(widget());
switch (event->type())
{
case QEvent::MouseButtonPress:
@ -458,7 +465,7 @@ void WidgetLoader::processWheelEvents(QWheelEvent *event)
using QWidget::wheelEvent;
};
static_cast<Hack *>(m_widget)->wheelEvent(event);
static_cast<Hack *>(widget())->wheelEvent(event);
update();
}
}

View File

@ -107,6 +107,8 @@ public:
bool isExternalWindow() const;
UI::Dashboard::WidgetType widgetType() const;
QWidget *widget() const;
public Q_SLOTS:
void setVisible(const bool visible);
void setWidgetIndex(const int index);
@ -125,8 +127,8 @@ protected:
private:
int m_index;
QWidget *m_widget;
bool m_widgetVisible;
bool m_isExternalWindow;
QPointer<QWidget> m_widget;
};
}

View File

@ -154,7 +154,7 @@ bool Terminal::event(QEvent *event)
*/
void Terminal::paint(QPainter *painter)
{
if (m_textEdit && painter && isVisible())
if (m_textEdit && painter)
textEdit()->render(painter);
}

View File

@ -209,7 +209,7 @@ private:
bool m_autoscroll;
bool m_emulateVt100;
bool m_copyAvailable;
QPlainTextEdit *m_textEdit;
QPointer<QPlainTextEdit> m_textEdit;
AnsiEscapeCodeHandler m_escapeCodeHandler;
};
}