logic: fixed some memory leaks in gui code
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
|
||||
QtFocusInFilter::QtFocusInFilter()
|
||||
QtFocusInFilter::QtFocusInFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ QtScreenSearchBox::QtScreenSearchBox(ControllerProxy<ScreenSearchController>* co
|
||||
connect(m_searchBox, &QLineEdit::textChanged, this, &QtScreenSearchBox::searchQueryChanged);
|
||||
connect(m_searchBox, &QLineEdit::returnPressed, this, &QtScreenSearchBox::returnPressed);
|
||||
|
||||
QtFocusInFilter* filter = new QtFocusInFilter();
|
||||
QtFocusInFilter* filter = new QtFocusInFilter(m_searchBox);
|
||||
m_searchBox->installEventFilter(filter);
|
||||
connect(filter, &QtFocusInFilter::focusIn, this, &QtScreenSearchBox::findMatches);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class QtFocusInFilter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtFocusInFilter();
|
||||
QtFocusInFilter(QObject* parent = Q_NULLPTR);
|
||||
|
||||
signals:
|
||||
void focusIn();
|
||||
|
||||
@@ -13,15 +13,15 @@ QtStatusBar::QtStatusBar()
|
||||
{
|
||||
addWidget(new QWidget()); // add some space
|
||||
|
||||
QMovie* movie = new QMovie((ResourcePaths::getGuiPath().str() + "statusbar_view/loader.gif").c_str());
|
||||
m_movie = std::make_shared<QMovie>((ResourcePaths::getGuiPath().str() + "statusbar_view/loader.gif").c_str());
|
||||
// if movie doesn't loop forever, force it to.
|
||||
if (movie->loopCount() != -1)
|
||||
if (m_movie->loopCount() != -1)
|
||||
{
|
||||
connect(movie, &QMovie::finished, movie, &QMovie::start);
|
||||
connect(m_movie.get(), &QMovie::finished, m_movie.get(), &QMovie::start);
|
||||
}
|
||||
movie->start();
|
||||
m_movie->start();
|
||||
|
||||
m_loader.setMovie(movie);
|
||||
m_loader.setMovie(m_movie.get());
|
||||
m_loader.hide();
|
||||
addWidget(&m_loader);
|
||||
|
||||
@@ -49,10 +49,6 @@ QtStatusBar::QtStatusBar()
|
||||
connect(&m_errorButton, &QPushButton::clicked, this, &QtStatusBar::showErrors);
|
||||
}
|
||||
|
||||
QtStatusBar::~QtStatusBar()
|
||||
{
|
||||
}
|
||||
|
||||
void QtStatusBar::setText(const std::string& text, bool isError, bool showLoader)
|
||||
{
|
||||
if (isError)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef QT_STATUS_BAR_H
|
||||
#define QT_STATUS_BAR_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <QPushButton>
|
||||
@@ -15,8 +16,7 @@ class QtStatusBar
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtStatusBar(void);
|
||||
virtual ~QtStatusBar(void);
|
||||
QtStatusBar();
|
||||
|
||||
void setText(const std::string& text, bool isError, bool showLoader);
|
||||
void setErrorCount(ErrorCountInfo errorCount);
|
||||
@@ -31,6 +31,8 @@ private slots:
|
||||
void showErrors();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QMovie> m_movie;
|
||||
|
||||
std::string m_textString;
|
||||
|
||||
QPushButton m_text;
|
||||
|
||||
@@ -13,9 +13,15 @@
|
||||
|
||||
class SelectableCellDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
SelectableCellDelegate(QObject* parent = Q_NULLPTR);
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
SelectableCellDelegate::SelectableCellDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget* SelectableCellDelegate::createEditor(
|
||||
QWidget* parent,
|
||||
@@ -39,7 +45,7 @@ QtTable::QtTable(QWidget* parent)
|
||||
setShowGrid(false);
|
||||
setMouseTracking(true);
|
||||
|
||||
this->setItemDelegate(new SelectableCellDelegate());
|
||||
this->setItemDelegate(new SelectableCellDelegate(this));
|
||||
|
||||
verticalHeader()->sectionResizeMode(QHeaderView::Fixed);
|
||||
verticalHeader()->setDefaultAlignment(Qt::AlignRight);
|
||||
|
||||
@@ -28,9 +28,17 @@ QIcon QtErrorView::s_errorIcon;
|
||||
class SelectableDelegate
|
||||
: public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
SelectableDelegate(QObject* parent = Q_NULLPTR);
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
SelectableDelegate::SelectableDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QWidget* SelectableDelegate::createEditor(
|
||||
QWidget* parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
@@ -73,7 +81,7 @@ void QtErrorView::initView()
|
||||
m_table = new QtTable(this);
|
||||
m_model = new QStandardItemModel(this);
|
||||
m_table->setModel(m_model);
|
||||
m_table->setItemDelegate(new SelectableDelegate());
|
||||
m_table->setItemDelegate(new SelectableDelegate(m_table));
|
||||
|
||||
// Setup Table Headers
|
||||
m_model->setColumnCount(COLUMN_MAX + 1);
|
||||
|
||||
@@ -85,6 +85,10 @@ void QtRecentProjectButton::handleButtonClick()
|
||||
|
||||
QtStartScreen::QtStartScreen(QWidget *parent)
|
||||
: QtWindow(true, parent)
|
||||
, m_cppIcon((ResourcePaths::getGuiPath().str() + "icon/cpp_icon.png").c_str())
|
||||
, m_cIcon((ResourcePaths::getGuiPath().str() + "icon/c_icon.png").c_str())
|
||||
, m_javaIcon((ResourcePaths::getGuiPath().str() + "icon/java_icon.png").c_str())
|
||||
, m_projectIcon((ResourcePaths::getGuiPath().str() + "icon/empty_icon.png").c_str())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,7 +100,7 @@ QSize QtStartScreen::sizeHint() const
|
||||
void QtStartScreen::updateButtons()
|
||||
{
|
||||
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
|
||||
size_t i = 0;
|
||||
size_t i = 0;
|
||||
for (QtRecentProjectButton* button : m_recentProjectsButtons)
|
||||
{
|
||||
button->disconnect();
|
||||
@@ -107,16 +111,16 @@ size_t i = 0;
|
||||
switch (lang)
|
||||
{
|
||||
case LanguageType::LANGUAGE_C:
|
||||
button->setIcon(*m_cIcon);
|
||||
button->setIcon(m_cIcon);
|
||||
break;
|
||||
case LANGUAGE_CPP:
|
||||
button->setIcon(*m_cppIcon);
|
||||
button->setIcon(m_cppIcon);
|
||||
break;
|
||||
case LANGUAGE_JAVA:
|
||||
button->setIcon(*m_javaIcon);
|
||||
button->setIcon(m_javaIcon);
|
||||
break;
|
||||
default:
|
||||
button->setIcon(*m_projectIcon);
|
||||
button->setIcon(m_projectIcon);
|
||||
break;
|
||||
}
|
||||
button->setFixedWidth(button->fontMetrics().width(button->text()) + 45);
|
||||
@@ -223,17 +227,13 @@ void QtStartScreen::setupStartScreen()
|
||||
|
||||
col->addSpacing(20);
|
||||
|
||||
m_cppIcon = new QIcon((ResourcePaths::getGuiPath().str() + "icon/cpp_icon.png").c_str());
|
||||
m_cIcon = new QIcon((ResourcePaths::getGuiPath().str() + "icon/c_icon.png").c_str());
|
||||
m_javaIcon = new QIcon((ResourcePaths::getGuiPath().str() + "icon/java_icon.png").c_str());
|
||||
m_projectIcon = new QIcon((ResourcePaths::getGuiPath().str() + "icon/empty_icon.png").c_str());
|
||||
for (int i = 0
|
||||
; i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount()
|
||||
; i++)
|
||||
{
|
||||
QtRecentProjectButton* button = new QtRecentProjectButton(this);
|
||||
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
button->setIcon(*m_projectIcon);
|
||||
button->setIcon(m_projectIcon);
|
||||
button->setIconSize(QSize(30, 30));
|
||||
button->setMinimumSize(button->fontMetrics().width(button->text()) + 45, 40);
|
||||
button->setObjectName("recentButtonMissing");
|
||||
|
||||
@@ -50,10 +50,10 @@ private slots:
|
||||
|
||||
private:
|
||||
std::vector<QtRecentProjectButton*> m_recentProjectsButtons;
|
||||
QIcon* m_cppIcon;
|
||||
QIcon* m_cIcon;
|
||||
QIcon* m_javaIcon;
|
||||
QIcon* m_projectIcon;
|
||||
QIcon m_cppIcon;
|
||||
QIcon m_cIcon;
|
||||
QIcon m_javaIcon;
|
||||
QIcon m_projectIcon;
|
||||
};
|
||||
|
||||
#endif // QT_START_SCREEN_H
|
||||
|
||||
Reference in New Issue
Block a user