Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at level1 clazy checks for qt #584

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

// 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 @@
}

// 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 @@
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 @@
}

// 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 @@

// 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 @@
// 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 @@
"] : couldn't instantiate plugin on path [" << pathToLib <<
"]. Tried plugin names: " << std::endl;

for (auto pluginName : pluginNames)
for (const auto &pluginName : pluginNames)

Check warning on line 584 in src/Application.cc

View check run for this annotation

Codecov / codecov/patch

src/Application.cc#L584

Added line #L584 was not covered by tests
{
gzerr << " * " << pluginName << std::endl;
}
Expand Down Expand Up @@ -620,7 +621,7 @@
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 @@
{
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 @@
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 @@
continue;
}

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

Expand All @@ -714,7 +715,7 @@
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 @@
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 @@
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 @@
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