cleanup: move qstyle getInstance decl inline
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
a04a6f1e0d
commit
0357921284
@ -30,8 +30,6 @@ class NoBigComboBoxStyle : public QProxyStyle {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {}
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
|
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
|
||||||
{
|
{
|
||||||
@ -42,36 +40,40 @@ class NoBigComboBoxStyle : public QProxyStyle {
|
|||||||
}
|
}
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
static NoBigComboBoxStyle* GetInstance(QStyle* style);
|
/**
|
||||||
|
* Something about QProxyStyle and QStyle objects means they can't be free'd just
|
||||||
|
* because all the widgets using them are gone.
|
||||||
|
* They seems to be tied to the QApplicaiton lifecycle.
|
||||||
|
* So make singletons tied to the lifetime of the application to clean them up and ensure they aren't
|
||||||
|
* being remade over and over again, thus leaking memory.
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
static NoBigComboBoxStyle* getInstance(QStyle* style)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(s_singleton_instances_mutex_);
|
||||||
|
auto inst_iter = s_singleton_instances_.constFind(style);
|
||||||
|
NoBigComboBoxStyle* inst = nullptr;
|
||||||
|
if (inst_iter == s_singleton_instances_.constEnd() || *inst_iter == nullptr) {
|
||||||
|
inst = new NoBigComboBoxStyle(style);
|
||||||
|
inst->setParent(APPLICATION);
|
||||||
|
s_singleton_instances_.insert(style, inst);
|
||||||
|
qDebug() << "QProxyStyle NoBigComboBox created for" << style->objectName() << style;
|
||||||
|
} else {
|
||||||
|
inst = *inst_iter;
|
||||||
|
}
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QMap<QStyle*, NoBigComboBoxStyle*> s_singleton_instances_;
|
NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {}
|
||||||
|
|
||||||
|
static QHash<QStyle*, NoBigComboBoxStyle*> s_singleton_instances_;
|
||||||
static std::mutex s_singleton_instances_mutex_;
|
static std::mutex s_singleton_instances_mutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<QStyle*, NoBigComboBoxStyle*> NoBigComboBoxStyle::s_singleton_instances_ = {};
|
QHash<QStyle*, NoBigComboBoxStyle*> NoBigComboBoxStyle::s_singleton_instances_ = {};
|
||||||
std::mutex NoBigComboBoxStyle::s_singleton_instances_mutex_;
|
std::mutex NoBigComboBoxStyle::s_singleton_instances_mutex_;
|
||||||
|
|
||||||
/**
|
|
||||||
* QProxyStyle and QStyle objects object to being freed even if all the widgets using them are gone
|
|
||||||
* so make singlestons tied to the lifetime of the application to clean them up and ensure they arn't
|
|
||||||
* being remade over and over agian leaking memory.
|
|
||||||
* */
|
|
||||||
NoBigComboBoxStyle* NoBigComboBoxStyle::GetInstance(QStyle* style)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(s_singleton_instances_mutex_);
|
|
||||||
auto inst_iter = s_singleton_instances_.constFind(style);
|
|
||||||
NoBigComboBoxStyle* inst = nullptr;
|
|
||||||
if(inst_iter == s_singleton_instances_.constEnd() || *inst_iter == nullptr) {
|
|
||||||
inst = new NoBigComboBoxStyle(style);
|
|
||||||
inst->setParent(APPLICATION);
|
|
||||||
s_singleton_instances_.insert(style, inst);
|
|
||||||
qDebug() << "QProxyStyle NoBigComboBox created for" << style->objectName() << style;
|
|
||||||
} else {
|
|
||||||
inst = *inst_iter;
|
|
||||||
}
|
|
||||||
return inst;
|
|
||||||
}
|
|
||||||
|
|
||||||
ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent)
|
ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent)
|
||||||
{
|
{
|
||||||
@ -93,7 +95,7 @@ ManagedPackPage::ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_wi
|
|||||||
// NOTE: GTK2 themes crash with the proxy style.
|
// NOTE: GTK2 themes crash with the proxy style.
|
||||||
// This seems like an upstream bug, so there's not much else that can be done.
|
// This seems like an upstream bug, so there's not much else that can be done.
|
||||||
if (!QStyleFactory::keys().contains("gtk2")){
|
if (!QStyleFactory::keys().contains("gtk2")){
|
||||||
auto comboStyle = NoBigComboBoxStyle::GetInstance(ui->versionsComboBox->style());
|
auto comboStyle = NoBigComboBoxStyle::getInstance(ui->versionsComboBox->style());
|
||||||
ui->versionsComboBox->setStyle(comboStyle);
|
ui->versionsComboBox->setStyle(comboStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user