Added nullptr check in the event QStyle factory fails.

This commit is contained in:
harry 2024-01-29 20:19:36 -05:00
parent a85f348e50
commit 813d4c0c4b
4 changed files with 57 additions and 34 deletions

View File

@ -43,7 +43,7 @@
static int writeQPaletteToFile( const char *path, QPalette *pal );
static int readQPaletteFromFile( const char *path, QPalette *pal );
static GuiPaletteEditDialog_t *editDialog = NULL;
static GuiPaletteEditDialog_t *editDialog = nullptr;
//----------------------------------------------------
GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
: QDialog(parent)
@ -590,8 +590,15 @@ fceuStyle::fceuStyle(QStyle *style) : QProxyStyle(style)
{
//printf("New Style!!!\n");
if (style != nullptr)
{
setObjectName( style->objectName() );
}
else
{
setObjectName("fusion");
}
}
fceuStyle::~fceuStyle(void)
{
@ -609,33 +616,29 @@ fceuStyle::~fceuStyle(void)
QStyle *fceuStyle::styleBase(QStyle *style) const
{
std::string s;
static QStyle *base;
if ( g_config != NULL )
{
g_config->getOption("SDL.GuiStyle", &s );
}
if ( s.size() == 0 )
{
int i, idx = -1;
static QStyle *base = nullptr;
#ifdef WIN32
//QString defaultStyle("windows"); // fusion is much more stable and consistent.
QString defaultStyle("fusion");
#elif __APPLE__
QString defaultStyle("fusion");
QString styleName("fusion");
#else
QString defaultStyle("fusion");
QString styleName("fusion");
#endif
if ( g_config != nullptr )
{
g_config->getOption("SDL.GuiStyle", &styleName );
}
{
int i, idx = -1;
QStringList styleKeys = QStyleFactory::keys();
for (i=0; i<styleKeys.size(); i++)
{
//printf("Style: '%s'\n", styleKeys[i].toStdString().c_str() );
if ( defaultStyle.compare( styleKeys[i], Qt::CaseInsensitive ) == 0 )
if ( styleName.compare( styleKeys[i], Qt::CaseInsensitive ) == 0 )
{
//printf("Style Match: %s\n", styleKeys[i].toStdString().c_str() );
idx = i;
@ -645,17 +648,13 @@ QStyle *fceuStyle::styleBase(QStyle *style) const
if ( (idx >= 0) && (idx < styleKeys.size()) )
{
s = styleKeys[idx].toStdString();
}
else
{
s.assign("fusion");
styleName = styleKeys[idx];
}
}
if ( style == NULL )
if ( style == nullptr )
{
base = QStyleFactory::create(QString::fromStdString(s));
base = QStyleFactory::create(styleName);
}
else
{
@ -772,7 +771,7 @@ void fceuStyle::polish(QApplication *app)
}
else
{
app->setStyleSheet(NULL);
app->setStyleSheet(nullptr);
}
}
//----------------------------------------------------
@ -852,7 +851,7 @@ static const char *getRoleText( QPalette::ColorRole role )
rTxt = "NoRole";
break;
default:
rTxt = NULL;
rTxt = nullptr;
break;
}
return rTxt;
@ -869,7 +868,7 @@ static int writeQPaletteToFile( const char *path, QPalette *pal )
fp = fopen( path, "w");
if ( fp == NULL )
if ( fp == nullptr )
{
printf("Error: Failed to Open File for writing: '%s'\n", path );
return -1;
@ -928,7 +927,7 @@ static int readQPaletteFromFile( const char *path, QPalette *pal )
fp = fopen( path, "r");
if ( fp == NULL )
if ( fp == nullptr )
{
printf("Error: Failed to Open File for writing: '%s'\n", path );
return -1;
@ -987,7 +986,7 @@ static int readQPaletteFromFile( const char *path, QPalette *pal )
continue;
}
rTxtMatch = NULL;
rTxtMatch = nullptr;
r = QPalette::WindowText;
@ -1006,7 +1005,7 @@ static int readQPaletteFromFile( const char *path, QPalette *pal )
}
}
if ( rTxtMatch == NULL ) continue;
if ( rTxtMatch == nullptr ) continue;
color = pal->color( g, r );
@ -1156,7 +1155,7 @@ GuiPaletteEditDialog_t::~GuiPaletteEditDialog_t(void)
{
if ( editDialog == this )
{
editDialog = NULL;
editDialog = nullptr;
}
}
//----------------------------------------------------
@ -1328,13 +1327,13 @@ void GuiPaletteColorSelect::setText(void)
gTxt = "Inactive";
break;
default:
gTxt = NULL;
gTxt = nullptr;
break;
}
rTxt = getRoleText( role );
if ( (gTxt == NULL) || (rTxt == NULL) )
if ( (gTxt == nullptr) || (rTxt == nullptr) )
{
return;
}

View File

@ -33,8 +33,6 @@ public:
~fceuStyle(void);
QStyle *baseStyle() const;
void polish(QPalette &palette) override;
void polish(QApplication *app) override;

View File

@ -413,6 +413,25 @@ Config::getOption(const std::string &name,
return 0;
}
#ifdef __QT_DRIVER__
int
Config::getOption(const std::string &name,
QString *value) const
{
std::map<std::string, std::string>::const_iterator opt_i;
// confirm that the option exists
opt_i = _strOptMap.find(name);
if(opt_i == _strOptMap.end()) {
return -1;
}
// get the option
(*value) = QString::fromStdString(opt_i->second);
return 0;
}
#endif
int
Config::getOption(const std::string &name,
const char **value) const

View File

@ -4,6 +4,10 @@
#include <map>
#include <string>
#ifdef __QT_DRIVER__
#include <QString>
#endif
class Config {
private:
std::string _dir;
@ -66,6 +70,9 @@ public:
int setOption(const std::string &, double);
int setOption(const std::string &, void (*)(const std::string &));
#ifdef __QT_DRIVER__
int getOption(const std::string &, QString *) const;
#endif
int getOption(const std::string &, std::string *) const;
int getOption(const std::string &, const char **) const;
int getOption(const std::string &, int *) const;