ProjectExplorer: Code cosmetics

Change-Id: Idf96413b2fc70418efe14db5f581624028e29dcd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-11-29 17:17:03 +01:00
parent 1dbf3ad120
commit d743770493

View File

@@ -39,7 +39,7 @@ namespace ProjectExplorer {
namespace Internal { namespace Internal {
class ProjectFileTreeItem : public Utils::TreeItem class ProjectFileTreeItem : public TreeItem
{ {
public: public:
ProjectFileTreeItem(JsonWizard::GeneratorFile *candidate) : m_candidate(candidate) ProjectFileTreeItem(JsonWizard::GeneratorFile *candidate) : m_candidate(candidate)
@@ -64,7 +64,7 @@ private:
JsonWizard::GeneratorFile * const m_candidate; JsonWizard::GeneratorFile * const m_candidate;
}; };
class ProjectFilesModel : public Utils::TreeModel<Utils::TreeItem, ProjectFileTreeItem> class ProjectFilesModel : public TreeModel<TreeItem, ProjectFileTreeItem>
{ {
public: public:
ProjectFilesModel(const QList<JsonWizard::GeneratorFile *> &candidates, QObject *parent) ProjectFilesModel(const QList<JsonWizard::GeneratorFile *> &candidates, QObject *parent)
@@ -80,13 +80,13 @@ class ProjectFileChooser : public QDialog
{ {
public: public:
ProjectFileChooser(const QList<JsonWizard::GeneratorFile *> &candidates, QWidget *parent) ProjectFileChooser(const QList<JsonWizard::GeneratorFile *> &candidates, QWidget *parent)
: QDialog(parent), m_view(new Utils::TreeView(this)) : QDialog(parent), m_view(new TreeView(this))
{ {
setWindowTitle(QCoreApplication::translate("ProjectExplorer::JsonWizard", setWindowTitle(QCoreApplication::translate("ProjectExplorer::JsonWizard",
"Choose Project File")); "Choose Project File"));
const auto model = new ProjectFilesModel(candidates, this); const auto model = new ProjectFilesModel(candidates, this);
m_view->setSelectionMode(Utils::TreeView::ExtendedSelection); m_view->setSelectionMode(TreeView::ExtendedSelection);
m_view->setSelectionBehavior(Utils::TreeView::SelectRows); m_view->setSelectionBehavior(TreeView::SelectRows);
m_view->setModel(model); m_view->setModel(model);
const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
const auto updateOkButton = [buttonBox, this] { const auto updateOkButton = [buttonBox, this] {
@@ -118,13 +118,13 @@ private:
QDialog::accept(); QDialog::accept();
} }
Utils::TreeView * const m_view; TreeView * const m_view;
}; };
} // namespace Internal } // namespace Internal
JsonWizard::JsonWizard(QWidget *parent) JsonWizard::JsonWizard(QWidget *parent)
: Utils::Wizard(parent) : Wizard(parent)
{ {
setMinimumSize(800, 500); setMinimumSize(800, 500);
m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool { m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool {
@@ -157,7 +157,7 @@ void JsonWizard::addGenerator(JsonWizardGenerator *gen)
m_generators.append(gen); m_generators.append(gen);
} }
Utils::MacroExpander *JsonWizard::expander() MacroExpander *JsonWizard::expander()
{ {
return &m_expander; return &m_expander;
} }
@@ -167,16 +167,16 @@ JsonWizard::GeneratorFiles JsonWizard::generateFileList()
QString errorMessage; QString errorMessage;
GeneratorFiles list; GeneratorFiles list;
const Utils::FilePath targetPath = const FilePath targetPath =
Utils::FilePath::fromString(stringValue(QLatin1String("TargetPath"))); FilePath::fromString(stringValue(QLatin1String("TargetPath")));
if (targetPath.isEmpty()) if (targetPath.isEmpty())
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page."); errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
if (m_files.isEmpty() && errorMessage.isEmpty()) { if (m_files.isEmpty() && errorMessage.isEmpty()) {
emit preGenerateFiles(); emit preGenerateFiles();
for (JsonWizardGenerator *gen : std::as_const(m_generators)) { for (JsonWizardGenerator *gen : std::as_const(m_generators)) {
const Utils::FilePath wizardDir = const FilePath wizardDir =
Utils::FilePath::fromString(stringValue(QLatin1String("WizardDir"))); FilePath::fromString(stringValue(QLatin1String("WizardDir")));
const Core::GeneratedFiles tmp = const Core::GeneratedFiles tmp =
gen->fileList(&m_expander, wizardDir, targetPath, &errorMessage); gen->fileList(&m_expander, wizardDir, targetPath, &errorMessage);
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
@@ -274,7 +274,7 @@ QVariant JsonWizard::value(const QString &n) const
return QVariant(); return QVariant();
} }
bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expander) bool JsonWizard::boolFromVariant(const QVariant &v, MacroExpander *expander)
{ {
if (v.type() == QVariant::String) { if (v.type() == QVariant::String) {
const QString tmp = expander->expand(v.toString()); const QString tmp = expander->expand(v.toString());
@@ -283,7 +283,7 @@ bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expand
return v.toBool(); return v.toBool();
} }
QString JsonWizard::stringListToArrayString(const QStringList &list, const Utils::MacroExpander *expander) QString JsonWizard::stringListToArrayString(const QStringList &list, const MacroExpander *expander)
{ {
// Todo: Handle ' embedded in the strings better. // Todo: Handle ' embedded in the strings better.
if (list.isEmpty()) if (list.isEmpty())
@@ -322,11 +322,11 @@ QHash<QString, QVariant> JsonWizard::variables() const
void JsonWizard::accept() void JsonWizard::accept()
{ {
auto page = qobject_cast<Utils::WizardPage *>(currentPage()); auto page = qobject_cast<WizardPage *>(currentPage());
if (page && page->handleAccept()) if (page && page->handleAccept())
return; return;
Utils::Wizard::accept(); Wizard::accept();
QString errorMessage; QString errorMessage;
if (m_files.isEmpty()) { if (m_files.isEmpty()) {
@@ -387,20 +387,20 @@ void JsonWizard::accept()
void JsonWizard::reject() void JsonWizard::reject()
{ {
auto page = qobject_cast<Utils::WizardPage *>(currentPage()); auto page = qobject_cast<WizardPage *>(currentPage());
if (page && page->handleReject()) if (page && page->handleReject())
return; return;
Utils::Wizard::reject(); Wizard::reject();
} }
void JsonWizard::handleNewPages(int pageId) void JsonWizard::handleNewPages(int pageId)
{ {
auto wp = qobject_cast<Utils::WizardPage *>(page(pageId)); auto wp = qobject_cast<WizardPage *>(page(pageId));
if (!wp) if (!wp)
return; return;
connect(wp, &Utils::WizardPage::reportError, this, &JsonWizard::handleError); connect(wp, &WizardPage::reportError, this, &JsonWizard::handleError);
} }
void JsonWizard::handleError(const QString &message) void JsonWizard::handleError(const QString &message)
@@ -484,8 +484,6 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
void JsonWizard::openProjectForNode(Node *node) void JsonWizard::openProjectForNode(Node *node)
{ {
using namespace Utils;
const ProjectNode *projNode = node->asProjectNode(); const ProjectNode *projNode = node->asProjectNode();
if (!projNode) { if (!projNode) {
if (ContainerNode * const cn = node->asContainerNode()) if (ContainerNode * const cn = node->asContainerNode())
@@ -505,14 +503,14 @@ void JsonWizard::openProjectForNode(Node *node)
} }
} }
QString JsonWizard::OptionDefinition::value(Utils::MacroExpander &expander) const QString JsonWizard::OptionDefinition::value(MacroExpander &expander) const
{ {
if (JsonWizard::boolFromVariant(m_evaluate, &expander)) if (JsonWizard::boolFromVariant(m_evaluate, &expander))
return expander.expand(m_value); return expander.expand(m_value);
return m_value; return m_value;
} }
bool JsonWizard::OptionDefinition::condition(Utils::MacroExpander &expander) const bool JsonWizard::OptionDefinition::condition(MacroExpander &expander) const
{ {
return JsonWizard::boolFromVariant(m_condition, &expander); return JsonWizard::boolFromVariant(m_condition, &expander);
} }