Skip to content

Commit

Permalink
First pass at level1 clazy checks for qt
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Nov 7, 2023
1 parent ed63b7b commit 2052269
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 309 deletions.
2 changes: 1 addition & 1 deletion include/gz/gui/MainWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ namespace gz::gui

/// \brief Get the action performed when GUI closes without prompt.
/// \return The action.
public: Q_INVOKABLE ExitAction DefaultExitAction() const;
public: Q_INVOKABLE gz::gui::ExitAction DefaultExitAction() const;

/// \brief Set the action performed when GUI closes without prompt.
/// \param[in] _defaultExitAction The action.
Expand Down
58 changes: 28 additions & 30 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bool Application::LoadConfig(const std::string &_config)
if (!configPathEnv.empty())
{
std::vector<std::string> parentPaths = common::Split(configPathEnv, ':');
for (auto parentPath : parentPaths)
for (const auto &parentPath : parentPaths)
{
std::string tempPath = common::joinPaths(parentPath, configFull);
if (common::exists(tempPath))
Expand Down Expand Up @@ -364,23 +364,24 @@ bool Application::LoadConfig(const std::string &_config)

// Clear all previous plugins
auto plugins = this->dataPtr->mainWin->findChildren<Plugin *>();
for (auto plugin : plugins)
for (auto *plugin : plugins)
{
auto pluginName = plugin->CardItem()->objectName();
this->RemovePlugin(pluginName.toStdString());
}
if (this->dataPtr->pluginsAdded.size() > 0)
if (!this->dataPtr->pluginsAdded.empty())
{
gzerr << "The plugin list was not properly cleaned up." << std::endl;
}
this->dataPtr->pluginsAdded.clear();

// Process each plugin
bool successful = true;
for (auto pluginElem = doc.FirstChildElement("plugin"); pluginElem != nullptr;
pluginElem = pluginElem->NextSiblingElement("plugin"))
for (auto *pluginElem = doc.FirstChildElement("plugin");
pluginElem != nullptr;
pluginElem = pluginElem->NextSiblingElement("plugin"))
{
auto filename = pluginElem->Attribute("filename");
const auto *filename = pluginElem->Attribute("filename");
if (!this->LoadPlugin(filename, pluginElem))
{
successful = false;
Expand All @@ -393,7 +394,7 @@ bool Application::LoadConfig(const std::string &_config)
}

// Process window properties
if (auto winElem = doc.FirstChildElement("window"))
if (auto *winElem = doc.FirstChildElement("window"))
{
gzdbg << "Loading window config" << std::endl;

Expand All @@ -407,7 +408,7 @@ bool Application::LoadConfig(const std::string &_config)
this->dataPtr->windowConfig.MergeFromXML(std::string(printer.CStr()));

// Closing behavior.
if (auto defaultExitActionElem =
if (auto *defaultExitActionElem =
winElem->FirstChildElement("default_exit_action"))
{
ExitAction action{ExitAction::CLOSE_GUI};
Expand All @@ -426,43 +427,43 @@ bool Application::LoadConfig(const std::string &_config)
}

// Dialog on exit
if (auto dialogOnExitElem = winElem->FirstChildElement("dialog_on_exit"))
if (auto *dialogOnExitElem = winElem->FirstChildElement("dialog_on_exit"))
{
bool showDialogOnExit{false};
dialogOnExitElem->QueryBoolText(&showDialogOnExit);
this->dataPtr->mainWin->SetShowDialogOnExit(showDialogOnExit);
}

if (auto dialogOnExitOptionsElem =
if (auto *dialogOnExitOptionsElem =
winElem->FirstChildElement("dialog_on_exit_options"))
{
if (auto promptElem =
if (auto *promptElem =
dialogOnExitOptionsElem->FirstChildElement("prompt_text"))
{
this->dataPtr->mainWin->SetDialogOnExitText(
QString::fromStdString(promptElem->GetText()));
}
if (auto showShutdownElem =
if (auto *showShutdownElem =
dialogOnExitOptionsElem->FirstChildElement("show_shutdown_button"))
{
bool showShutdownButton{false};
showShutdownElem->QueryBoolText(&showShutdownButton);
this->dataPtr->mainWin->SetExitDialogShowShutdown(showShutdownButton);
}
if (auto showCloseGuiElem =
if (auto *showCloseGuiElem =
dialogOnExitOptionsElem->FirstChildElement("show_close_gui_button"))
{
bool showCloseGuiButton{false};
showCloseGuiElem->QueryBoolText(&showCloseGuiButton);
this->dataPtr->mainWin->SetExitDialogShowCloseGui(showCloseGuiButton);
}
if (auto shutdownTextElem =
if (auto *shutdownTextElem =
dialogOnExitOptionsElem->FirstChildElement("shutdown_button_text"))
{
this->dataPtr->mainWin->SetExitDialogShutdownText(
QString::fromStdString(shutdownTextElem->GetText()));
}
if (auto closeGuiTextElem =
if (auto *closeGuiTextElem =
dialogOnExitOptionsElem->FirstChildElement("close_gui_button_text"))
{
this->dataPtr->mainWin->SetExitDialogCloseGuiText(
Expand All @@ -472,7 +473,7 @@ bool Application::LoadConfig(const std::string &_config)

// Server control service topic
std::string serverControlService{"/server_control"};
auto serverControlElem =
auto *serverControlElem =
winElem->FirstChildElement("server_control_service");
if (nullptr != serverControlElem && nullptr != serverControlElem->GetText())
{
Expand Down Expand Up @@ -563,7 +564,7 @@ bool Application::LoadPlugin(const std::string &_filename,
// gz::gui::Plugin interface
plugin::PluginPtr commonPlugin;
std::shared_ptr<gui::Plugin> plugin{nullptr};
for (auto pluginName : pluginNames)
for (const auto &pluginName : pluginNames)
{
commonPlugin = pluginLoader.Instantiate(pluginName);
if (!commonPlugin)
Expand All @@ -580,7 +581,7 @@ bool Application::LoadPlugin(const std::string &_filename,
"] : couldn't instantiate plugin on path [" << pathToLib <<
"]. Tried plugin names: " << std::endl;

for (auto pluginName : pluginNames)
for (const auto &pluginName : pluginNames)
{
gzerr << " * " << pluginName << std::endl;
}
Expand Down Expand Up @@ -620,7 +621,7 @@ bool Application::LoadPlugin(const std::string &_filename,
else
this->InitializeDialogs();

this->PluginAdded(plugin->CardItem()->objectName());
emit this->PluginAdded(plugin->CardItem()->objectName());
gzmsg << "Loaded plugin [" << _filename << "] from path [" << pathToLib
<< "]" << std::endl;

Expand All @@ -633,7 +634,7 @@ std::shared_ptr<Plugin> Application::PluginByName(
{
for (auto &plugin : this->dataPtr->pluginsAdded)
{
auto cardItem = plugin->CardItem();
auto *cardItem = plugin->CardItem();
if (!cardItem)
continue;

Expand Down Expand Up @@ -683,7 +684,7 @@ bool Application::AddPluginsToWindow()
return false;

// Get main window background item
auto bgItem = this->dataPtr->mainWin->QuickWindow()
auto *bgItem = this->dataPtr->mainWin->QuickWindow()
->findChild<QQuickItem *>("background");
if (!this->dataPtr->pluginsToAdd.empty() && !bgItem)
{
Expand All @@ -705,7 +706,7 @@ bool Application::AddPluginsToWindow()
continue;
}

auto cardItem = plugin->CardItem();
auto *cardItem = plugin->CardItem();
if (!cardItem)
continue;

Expand All @@ -714,7 +715,7 @@ bool Application::AddPluginsToWindow()
QMetaObject::invokeMethod(bgItem, "addSplitItem",
Q_RETURN_ARG(QVariant, splitName));

auto splitItem = bgItem->findChild<QQuickItem *>(
auto *splitItem = bgItem->findChild<QQuickItem *>(
splitName.toString());
if (!splitItem)
{
Expand Down Expand Up @@ -755,12 +756,12 @@ bool Application::InitializeDialogs()
this->dataPtr->pluginsToAdd.pop();

// Create card
auto cardItem = plugin->CardItem();
auto *cardItem = plugin->CardItem();
if (!cardItem)
continue;

// Create dialog
auto dialog = new Dialog();
auto *dialog = new Dialog();
if (!dialog || !dialog->QuickWindow())
continue;

Expand All @@ -787,10 +788,7 @@ bool Application::InitializeDialogs()
gzdbg << "Initialized dialog [" << title.toStdString() << "]" << std::endl;
}

if (this->dataPtr->pluginsAdded.empty())
return false;

return true;
return !this->dataPtr->pluginsAdded.empty();
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -844,7 +842,7 @@ std::vector<std::pair<std::string, std::vector<std::string>>>
ps.push_back(plugin);
}

plugins.push_back(std::make_pair(path, ps));
plugins.emplace_back(path, ps);
}

return plugins;
Expand Down
4 changes: 2 additions & 2 deletions src/Application_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))

// Close dialog after some time
auto closed = false;
QTimer::singleShot(300, [&] {
QTimer::singleShot(300, &app, [&] {
auto ds = app.allWindows();

// The main dialog - some systems return more, not sure why
Expand Down Expand Up @@ -371,7 +371,7 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))

// Close dialogs after some time
auto closed = false;
QTimer::singleShot(300, [&] {
QTimer::singleShot(300, &app, [&] {
auto ds = app.allWindows();

// 2 dialog - some systems return more, not sure why
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ TEST(HelpersTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(worldNames))
// Has names
EXPECT_FALSE(worldNames().empty());
ASSERT_EQ(2, worldNames().size());
EXPECT_EQ("banana", worldNames()[0]);
EXPECT_EQ("grape", worldNames()[1]);
EXPECT_EQ("banana", worldNames().at(0));
EXPECT_EQ("grape", worldNames().at(1));

mainWindow->setProperty("worldNames", QStringList());

Expand Down
Loading

0 comments on commit 2052269

Please sign in to comment.