diff --git a/qt/qt_common/map_widget.hpp b/qt/qt_common/map_widget.hpp index 8b35876c67..df733e220c 100644 --- a/qt/qt_common/map_widget.hpp +++ b/qt/qt_common/map_widget.hpp @@ -27,7 +27,7 @@ class MapWidget : public QOpenGLWidget public: MapWidget(Framework & framework, QWidget * parent); - ~MapWidget(); + ~MapWidget() override; void BindHotkeys(QWidget & parent); void BindSlider(ScaleSlider & slider); diff --git a/qt/qt_common/proxy_style.cpp b/qt/qt_common/proxy_style.cpp index c9ed436034..62ce541858 100644 --- a/qt/qt_common/proxy_style.cpp +++ b/qt/qt_common/proxy_style.cpp @@ -6,64 +6,64 @@ namespace common { ProxyStyle::ProxyStyle(QStyle * p) : QStyle(), style(p) {} -void ProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex * option, - QPainter * painter, const QWidget * widget) const +void ProxyStyle::drawComplexControl(ComplexControl control, QStyleOptionComplex const * option, + QPainter * painter, QWidget const * widget) const { style->drawComplexControl(control, option, painter, widget); } -void ProxyStyle::drawControl(ControlElement element, const QStyleOption * option, - QPainter * painter, const QWidget * widget) const +void ProxyStyle::drawControl(ControlElement element, QStyleOption const * option, + QPainter * painter, QWidget const * widget) const { style->drawControl(element, option, painter, widget); } -void ProxyStyle::drawItemPixmap(QPainter * painter, const QRect & rect, int alignment, - const QPixmap & pixmap) const +void ProxyStyle::drawItemPixmap(QPainter * painter, QRect const & rect, int alignment, + QPixmap const & pixmap) const { style->drawItemPixmap(painter, rect, alignment, pixmap); } -void ProxyStyle::drawItemText(QPainter * painter, const QRect & rect, int alignment, - const QPalette & pal, bool enabled, const QString & text, +void ProxyStyle::drawItemText(QPainter * painter, QRect const & rect, int alignment, + QPalette const & pal, bool enabled, QString const & text, QPalette::ColorRole textRole) const { style->drawItemText(painter, rect, alignment, pal, enabled, text, textRole); } -void ProxyStyle::drawPrimitive(PrimitiveElement elem, const QStyleOption * option, - QPainter * painter, const QWidget * widget) const +void ProxyStyle::drawPrimitive(PrimitiveElement elem, QStyleOption const * option, + QPainter * painter, QWidget const * widget) const { style->drawPrimitive(elem, option, painter, widget); } -QPixmap ProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap & pixmap, - const QStyleOption * option) const +QPixmap ProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, QPixmap const & pixmap, + QStyleOption const * option) const { return style->generatedIconPixmap(iconMode, pixmap, option); } QStyle::SubControl ProxyStyle::hitTestComplexControl(ComplexControl control, - const QStyleOptionComplex * option, - const QPoint & pos, - const QWidget * widget) const + QStyleOptionComplex const * option, + QPoint const & pos, + QWidget const * widget) const { return style->hitTestComplexControl(control, option, pos, widget); } -QRect ProxyStyle::itemPixmapRect(const QRect & rect, int alignment, const QPixmap & pixmap) const +QRect ProxyStyle::itemPixmapRect(QRect const & rect, int alignment, QPixmap const & pixmap) const { return style->itemPixmapRect(rect, alignment, pixmap); } -QRect ProxyStyle::itemTextRect(const QFontMetrics & metrics, const QRect & rect, int alignment, - bool enabled, const QString & text) const +QRect ProxyStyle::itemTextRect(QFontMetrics const & metrics, QRect const & rect, int alignment, + bool enabled, QString const & text) const { return style->itemTextRect(metrics, rect, alignment, enabled, text); } -int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption * option, - const QWidget * widget) const +int ProxyStyle::pixelMetric(PixelMetric metric, QStyleOption const * option, + QWidget const * widget) const { return style->pixelMetric(metric, option, widget); } @@ -74,40 +74,40 @@ void ProxyStyle::polish(QApplication * app) { style->polish(app); } void ProxyStyle::polish(QPalette & pal) { style->polish(pal); } -QSize ProxyStyle::sizeFromContents(ContentsType type, const QStyleOption * option, - const QSize & contentsSize, const QWidget * widget) const +QSize ProxyStyle::sizeFromContents(ContentsType type, QStyleOption const * option, + QSize const & contentsSize, QWidget const * widget) const { return style->sizeFromContents(type, option, contentsSize, widget); } -QIcon ProxyStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption * option, - const QWidget * widget) const +QIcon ProxyStyle::standardIcon(StandardPixmap standardIcon, QStyleOption const * option, + QWidget const * widget) const { return style->standardIcon(standardIcon, option, widget); } QPalette ProxyStyle::standardPalette() const { return style->standardPalette(); } -QPixmap ProxyStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption * option, - const QWidget * widget) const +QPixmap ProxyStyle::standardPixmap(StandardPixmap standardPixmap, QStyleOption const * option, + QWidget const * widget) const { return style->standardPixmap(standardPixmap, option, widget); } -int ProxyStyle::styleHint(StyleHint hint, const QStyleOption * option, const QWidget * widget, +int ProxyStyle::styleHint(StyleHint hint, QStyleOption const * option, QWidget const * widget, QStyleHintReturn * returnData) const { return style->styleHint(hint, option, widget, returnData); } -QRect ProxyStyle::subControlRect(ComplexControl control, const QStyleOptionComplex * option, - SubControl subControl, const QWidget * widget) const +QRect ProxyStyle::subControlRect(ComplexControl control, QStyleOptionComplex const * option, + SubControl subControl, QWidget const * widget) const { return style->subControlRect(control, option, subControl, widget); } -QRect ProxyStyle::subElementRect(SubElement element, const QStyleOption * option, - const QWidget * widget) const +QRect ProxyStyle::subElementRect(SubElement element, QStyleOption const * option, + QWidget const * widget) const { return style->subElementRect(element, option, widget); } @@ -117,8 +117,8 @@ void ProxyStyle::unpolish(QWidget * widget) { style->unpolish(widget); } void ProxyStyle::unpolish(QApplication * app) { style->unpolish(app); } int ProxyStyle::layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, - Qt::Orientation orientation, const QStyleOption * option, - const QWidget * widget) const + Qt::Orientation orientation, QStyleOption const * option, + QWidget const * widget) const { return style->layoutSpacing(control1, control2, orientation, option, widget); } diff --git a/qt/qt_common/proxy_style.hpp b/qt/qt_common/proxy_style.hpp index c0b3a22ca6..45faffeb2a 100644 --- a/qt/qt_common/proxy_style.hpp +++ b/qt/qt_common/proxy_style.hpp @@ -11,47 +11,48 @@ class ProxyStyle : public QStyle public: explicit ProxyStyle(QStyle * p); - void drawComplexControl(ComplexControl control, const QStyleOptionComplex * option, - QPainter * painter, const QWidget * widget = 0) const; - void drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, - const QWidget * widget = 0) const; - void drawItemPixmap(QPainter * painter, const QRect & rect, int alignment, - const QPixmap & pixmap) const; - void drawItemText(QPainter * painter, const QRect & rect, int alignment, const QPalette & pal, - bool enabled, const QString & text, - QPalette::ColorRole textRole = QPalette::NoRole) const; - void drawPrimitive(PrimitiveElement elem, const QStyleOption * option, QPainter * painter, - const QWidget * widget = 0) const; - QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap & pixmap, - const QStyleOption * option) const; - SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex * option, - const QPoint & pos, const QWidget * widget = 0) const; - QRect itemPixmapRect(const QRect & rect, int alignment, const QPixmap & pixmap) const; - QRect itemTextRect(const QFontMetrics & metrics, const QRect & rect, int alignment, bool enabled, - const QString & text) const; - int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, - const QWidget * widget = 0) const; - void polish(QWidget * widget); - void polish(QApplication * app); - void polish(QPalette & pal); - QSize sizeFromContents(ContentsType type, const QStyleOption * option, const QSize & contentsSize, - const QWidget * widget = 0) const; - QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption * option = 0, - const QWidget * widget = 0) const; - QPalette standardPalette() const; - QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption * option = 0, - const QWidget * widget = 0) const; - int styleHint(StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, - QStyleHintReturn * returnData = 0) const; - QRect subControlRect(ComplexControl control, const QStyleOptionComplex * option, - SubControl subControl, const QWidget * widget = 0) const; - QRect subElementRect(SubElement element, const QStyleOption * option, - const QWidget * widget = 0) const; - void unpolish(QWidget * widget); - void unpolish(QApplication * app); + // QStyle overrides: + void drawComplexControl(ComplexControl control, QStyleOptionComplex const * option, + QPainter * painter, QWidget const * widget = 0) const override; + void drawControl(ControlElement element, QStyleOption const * option, QPainter * painter, + QWidget const * widget = 0) const override; + void drawItemPixmap(QPainter * painter, QRect const & rect, int alignment, + QPixmap const & pixmap) const override; + void drawItemText(QPainter * painter, QRect const & rect, int alignment, QPalette const & pal, + bool enabled, QString const & text, + QPalette::ColorRole textRole = QPalette::NoRole) const override; + void drawPrimitive(PrimitiveElement elem, QStyleOption const * option, QPainter * painter, + QWidget const * widget = 0) const override; + QPixmap generatedIconPixmap(QIcon::Mode iconMode, QPixmap const & pixmap, + QStyleOption const * option) const override; + SubControl hitTestComplexControl(ComplexControl control, QStyleOptionComplex const * option, + QPoint const & pos, QWidget const * widget = 0) const override; + QRect itemPixmapRect(QRect const & rect, int alignment, QPixmap const & pixmap) const override; + QRect itemTextRect(QFontMetrics const & metrics, QRect const & rect, int alignment, bool enabled, + QString const & text) const override; + int pixelMetric(PixelMetric metric, QStyleOption const * option = 0, + QWidget const * widget = 0) const override; + void polish(QWidget * widget) override; + void polish(QApplication * app) override; + void polish(QPalette & pal) override; + QSize sizeFromContents(ContentsType type, QStyleOption const * option, QSize const & contentsSize, + QWidget const * widget = 0) const override; + QIcon standardIcon(StandardPixmap standardIcon, QStyleOption const * option = 0, + QWidget const * widget = 0) const override; + QPalette standardPalette() const override; + QPixmap standardPixmap(StandardPixmap standardPixmap, QStyleOption const * option = 0, + QWidget const * widget = 0) const override; + int styleHint(StyleHint hint, QStyleOption const * option = 0, QWidget const * widget = 0, + QStyleHintReturn * returnData = 0) const override; + QRect subControlRect(ComplexControl control, QStyleOptionComplex const * option, + SubControl subControl, QWidget const * widget = 0) const override; + QRect subElementRect(SubElement element, QStyleOption const * option, + QWidget const * widget = 0) const override; + void unpolish(QWidget * widget) override; + void unpolish(QApplication * app) override; int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, - Qt::Orientation orientation, const QStyleOption * option = 0, - const QWidget * widget = 0) const; + Qt::Orientation orientation, QStyleOption const * option = 0, + QWidget const * widget = 0) const override; private: QStyle * style; diff --git a/qt/qt_common/qtoglcontext.cpp b/qt/qt_common/qtoglcontext.cpp index 9793e2f020..cfc57799e1 100644 --- a/qt/qt_common/qtoglcontext.cpp +++ b/qt/qt_common/qtoglcontext.cpp @@ -4,6 +4,7 @@ #include "base/logging.hpp" #include "base/macros.hpp" #include "base/math.hpp" +#include "base/stl_add.hpp" #include "drape/glfunctions.hpp" @@ -11,23 +12,17 @@ namespace qt { namespace common { +// QtRenderOGLContext ------------------------------------------------------------------------------ QtRenderOGLContext::QtRenderOGLContext(QOpenGLContext * rootContext, QOffscreenSurface * surface) : m_surface(surface) + , m_ctx(my::make_unique()) { - m_ctx = new QOpenGLContext(); m_ctx->setFormat(rootContext->format()); m_ctx->setShareContext(rootContext); m_ctx->create(); ASSERT(m_ctx->isValid(), ()); } -QtRenderOGLContext::~QtRenderOGLContext() -{ - delete m_frontFrame; - delete m_backFrame; - delete m_ctx; -} - void QtRenderOGLContext::present() { if (!m_resizeLock) @@ -63,14 +58,12 @@ void QtRenderOGLContext::resize(int w, int h) lockFrame(); m_resizeLock = true; - delete m_frontFrame; - delete m_backFrame; - QSize size(my::NextPowOf2(w), my::NextPowOf2(h)); - m_texRect = QRectF(0.0, 0.0, w / (float)size.width(), h / (float)size.height()); + m_texRect = + QRectF(0.0, 0.0, w / static_cast(size.width()), h / static_cast(size.height())); - m_frontFrame = new QOpenGLFramebufferObject(size, QOpenGLFramebufferObject::Depth); - m_backFrame = new QOpenGLFramebufferObject(size, QOpenGLFramebufferObject::Depth); + m_frontFrame = my::make_unique(size, QOpenGLFramebufferObject::Depth); + m_backFrame = my::make_unique(size, QOpenGLFramebufferObject::Depth); } void QtRenderOGLContext::lockFrame() @@ -85,7 +78,7 @@ QRectF const & QtRenderOGLContext::getTexRect() const GLuint QtRenderOGLContext::getTextureHandle() const { - if (m_frontFrame == nullptr) + if (!m_frontFrame) return 0; return m_frontFrame->texture(); @@ -96,21 +89,16 @@ void QtRenderOGLContext::unlockFrame() m_lock.unlock(); } +// QtUploadOGLContext ------------------------------------------------------------------------------ QtUploadOGLContext::QtUploadOGLContext(QOpenGLContext * rootContext, QOffscreenSurface * surface) - : m_surface(surface) + : m_surface(surface), m_ctx(my::make_unique()) { - m_ctx = new QOpenGLContext(); m_ctx->setFormat(rootContext->format()); m_ctx->setShareContext(rootContext); m_ctx->create(); ASSERT(m_ctx->isValid(), ()); } -QtUploadOGLContext::~QtUploadOGLContext() -{ - delete m_ctx; -} - void QtUploadOGLContext::makeCurrent() { m_ctx->makeCurrent(m_surface); diff --git a/qt/qt_common/qtoglcontext.hpp b/qt/qt_common/qtoglcontext.hpp index 79e773bd98..ff409ea0dc 100644 --- a/qt/qt_common/qtoglcontext.hpp +++ b/qt/qt_common/qtoglcontext.hpp @@ -7,6 +7,8 @@ #include #include +#include + namespace qt { namespace common @@ -15,8 +17,8 @@ class QtRenderOGLContext : public dp::OGLContext { public: QtRenderOGLContext(QOpenGLContext * rootContext, QOffscreenSurface * surface); - ~QtRenderOGLContext(); + // dp::OGLContext overrides: void present() override; void makeCurrent() override; void doneCurrent() override; @@ -30,10 +32,10 @@ public: private: QOffscreenSurface * m_surface = nullptr; - QOpenGLContext * m_ctx = nullptr; + std::unique_ptr m_ctx; - QOpenGLFramebufferObject * m_frontFrame = nullptr; - QOpenGLFramebufferObject * m_backFrame = nullptr; + std::unique_ptr m_frontFrame; + std::unique_ptr m_backFrame; QRectF m_texRect = QRectF(0.0, 0.0, 0.0, 0.0); mutex m_lock; @@ -44,16 +46,16 @@ class QtUploadOGLContext: public dp::OGLContext { public: QtUploadOGLContext(QOpenGLContext * rootContext, QOffscreenSurface * surface); - ~QtUploadOGLContext(); + // dp::OGLContext overrides: void present() override; void makeCurrent() override; void doneCurrent() override; void setDefaultFramebuffer() override; private: - QOpenGLContext * m_ctx = nullptr; - QOffscreenSurface * m_surface = nullptr; + QOffscreenSurface * m_surface = nullptr; // non-owning ptr + std::unique_ptr m_ctx; }; } // namespace common } // namespace qt diff --git a/qt/qt_common/qtoglcontextfactory.cpp b/qt/qt_common/qtoglcontextfactory.cpp index 4a35517875..e3e1fd6c51 100644 --- a/qt/qt_common/qtoglcontextfactory.cpp +++ b/qt/qt_common/qtoglcontextfactory.cpp @@ -1,35 +1,30 @@ #include "qt/qt_common/qtoglcontextfactory.hpp" #include "base/assert.hpp" +#include "base/stl_add.hpp" namespace qt { namespace common { -QtOGLContextFactory::QtOGLContextFactory(QOpenGLContext * rootContext) - : m_rootContext(rootContext) - , m_drawContext(nullptr) - , m_uploadContext(nullptr) +QtOGLContextFactory::QtOGLContextFactory(QOpenGLContext * rootContext) : m_rootContext(rootContext) { - m_uploadSurface = createSurface(); - m_drawSurface = createSurface(); + m_uploadSurface = CreateSurface(); + m_drawSurface = CreateSurface(); } QtOGLContextFactory::~QtOGLContextFactory() { - delete m_drawContext; - delete m_uploadContext; + m_drawContext.reset(); + m_uploadContext.reset(); m_drawSurface->destroy(); m_uploadSurface->destroy(); - - delete m_drawSurface; - delete m_uploadSurface; } bool QtOGLContextFactory::LockFrame() { - if (m_drawContext == nullptr) + if (!m_drawContext) return false; m_drawContext->lockFrame(); @@ -56,24 +51,24 @@ void QtOGLContextFactory::UnlockFrame() dp::OGLContext * QtOGLContextFactory::getDrawContext() { - if (m_drawContext == nullptr) - m_drawContext = new QtRenderOGLContext(m_rootContext, m_drawSurface); + if (!m_drawContext) + m_drawContext = my::make_unique(m_rootContext, m_drawSurface.get()); - return m_drawContext; + return m_drawContext.get(); } dp::OGLContext * QtOGLContextFactory::getResourcesUploadContext() { - if (m_uploadContext == nullptr) - m_uploadContext = new QtUploadOGLContext(m_rootContext, m_uploadSurface); + if (!m_uploadContext) + m_uploadContext = my::make_unique(m_rootContext, m_uploadSurface.get()); - return m_uploadContext; + return m_uploadContext.get(); } -QOffscreenSurface * QtOGLContextFactory::createSurface() +std::unique_ptr QtOGLContextFactory::CreateSurface() { QSurfaceFormat format = m_rootContext->format(); - QOffscreenSurface * result = new QOffscreenSurface(m_rootContext->screen()); + auto result = my::make_unique(m_rootContext->screen()); result->setFormat(format); result->create(); ASSERT(result->isValid(), ()); diff --git a/qt/qt_common/qtoglcontextfactory.hpp b/qt/qt_common/qtoglcontextfactory.hpp index ef08d6ae08..918be36b81 100644 --- a/qt/qt_common/qtoglcontextfactory.hpp +++ b/qt/qt_common/qtoglcontextfactory.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace qt { namespace common @@ -14,28 +16,27 @@ class QtOGLContextFactory : public dp::OGLContextFactory { public: QtOGLContextFactory(QOpenGLContext * rootContext); - ~QtOGLContextFactory(); + ~QtOGLContextFactory() override; bool LockFrame(); GLuint GetTextureHandle() const; QRectF const & GetTexRect() const; void UnlockFrame(); - virtual dp::OGLContext * getDrawContext(); - virtual dp::OGLContext * getResourcesUploadContext(); - -protected: - virtual bool isDrawContextCreated() const { return m_drawContext != nullptr; } - virtual bool isUploadContextCreated() const { return m_uploadContext != nullptr; } - - QOffscreenSurface * createSurface(); + // dp::OGLContextFactory overrides: + dp::OGLContext * getDrawContext() override; + dp::OGLContext * getResourcesUploadContext() override; + bool isDrawContextCreated() const override { return m_drawContext != nullptr; } + bool isUploadContextCreated() const override { return m_uploadContext != nullptr; } private: + std::unique_ptr CreateSurface(); + QOpenGLContext * m_rootContext; - QtRenderOGLContext * m_drawContext; - QOffscreenSurface * m_drawSurface; - QtUploadOGLContext * m_uploadContext; - QOffscreenSurface * m_uploadSurface; + std::unique_ptr m_drawContext; + std::unique_ptr m_drawSurface; + std::unique_ptr m_uploadContext; + std::unique_ptr m_uploadSurface; }; } // namespace common } // namespace qt