mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Use QPointer
This commit is contained in:
parent
6685e67176
commit
8fc81d5be7
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ private:
|
||||
bool m_autoscroll;
|
||||
bool m_emulateVt100;
|
||||
bool m_copyAvailable;
|
||||
QPlainTextEdit *m_textEdit;
|
||||
QPointer<QPlainTextEdit> m_textEdit;
|
||||
AnsiEscapeCodeHandler m_escapeCodeHandler;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user