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

View File

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

View File

@ -413,6 +413,25 @@ Config::getOption(const std::string &name,
return 0; 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 int
Config::getOption(const std::string &name, Config::getOption(const std::string &name,
const char **value) const const char **value) const

View File

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