Qt Designer: Fix some clang warnings

- Use using instead of typedef
- User member initialization
- Use nullptr
- Do not use else after return
- Delete pointers unconditionally
- Fix some integer conversion warnings
- Use auto for new/casts to avoid type name repetition
- Use = default for trivial destructors

Task-number: QTCREATORBUG-23248
Change-Id: I0a7465d3aa200b5c862bec82636d2d22ddf8297b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Friedemann Kleint
2019-11-25 14:23:33 +01:00
parent f9c1795d3b
commit b96bf86f18
14 changed files with 41 additions and 52 deletions

View File

@@ -36,10 +36,10 @@
// Debug helpers for code model. @todo: Move to some CppTools library?
typedef QMap<QString, QStringList> DependencyMap;
typedef CPlusPlus::Document::Ptr DocumentPtr;
typedef QList<CPlusPlus::Symbol *> SymbolList;
typedef QList<DocumentPtr> DocumentPtrList;
using DependencyMap = QMap<QString, QStringList>;
using DocumentPtr = CPlusPlus::Document::Ptr;
using SymbolList = QList<CPlusPlus::Symbol *>;
using DocumentPtrList = QList<DocumentPtr>;
static const char setupUiC[] = "setupUi";

View File

@@ -58,14 +58,14 @@ QString FormClassWizard::formSuffix() const
Core::BaseFileWizard *FormClassWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const
{
FormClassWizardDialog *wizardDialog = new FormClassWizardDialog(this, parent);
auto wizardDialog = new FormClassWizardDialog(this, parent);
wizardDialog->setPath(parameters.defaultPath());
return wizardDialog;
}
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
auto wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
const Designer::FormClassWizardParameters params = wizardDialog->parameters();
if (params.uiTemplate.isEmpty()) {
@@ -90,7 +90,8 @@ Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *e
uiFile.setContents(params.uiTemplate);
uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
QString source, header;
QString source;
QString header;
QtDesignerFormClassCodeGenerator::generateCpp(params, &header, &source);
sourceFile.setContents(source);

View File

@@ -105,7 +105,7 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
// Ensure that loading designer translations is done before FormEditorW is instantiated
const QString locale = ICore::userInterfaceLanguage();
if (!locale.isEmpty()) {
QTranslator *qtr = new QTranslator(this);
auto qtr = new QTranslator(this);
const QString &creatorTrPath = ICore::resourcePath() + "/translations";
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
const QString &trFile = "designer_" + locale;

View File

@@ -92,7 +92,7 @@ void FormEditorStack::add(const EditorData &data)
// Since we have 1 pixel splitters we enforce no frame
// on the content widget
if (QFrame *frame = qobject_cast<QFrame*>(data.widgetHost))
if (auto frame = qobject_cast<QFrame*>(data.widgetHost))
frame->setFrameStyle(QFrame::NoFrame);
}
@@ -122,7 +122,7 @@ EditorData FormEditorStack::activeEditor() const
if (index >= 0)
return m_formEditors.at(index);
}
return EditorData();
return {};
}
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
@@ -173,7 +173,7 @@ void FormEditorStack::formSizeChanged(int w, int h)
// Handle main container resize.
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << w << h;
if (const SharedTools::WidgetHost *wh = qobject_cast<const SharedTools::WidgetHost *>(sender())) {
if (auto wh = qobject_cast<const SharedTools::WidgetHost *>(sender())) {
wh->formWindow()->setDirty(true);
static const QString geometry = "geometry";
m_designerCore->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) );

View File

@@ -115,7 +115,7 @@ namespace Internal {
class DesignerXmlEditorWidget : public TextEditor::TextEditorWidget
{
public:
DesignerXmlEditorWidget() {}
using TextEditorWidget::TextEditorWidget;
void finalizeInitialization() override
{
@@ -196,7 +196,7 @@ public:
QDesignerFormEditorInterface *m_formeditor = nullptr;
QtCreatorIntegration *m_integration = nullptr;
QDesignerFormWindowManagerInterface *m_fwm = nullptr;
FormEditorW::InitializationStage m_initStage;
FormEditorW::InitializationStage m_initStage = FormEditorW::RegisterPlugins;
QWidget *m_designerSubWindows[DesignerSubWindowCount];
@@ -229,8 +229,7 @@ static FormEditorData *d = nullptr;
static FormEditorW *m_instance = nullptr;
FormEditorData::FormEditorData() :
m_formeditor(QDesignerComponents::createFormEditor(nullptr)),
m_initStage(FormEditorW::RegisterPlugins)
m_formeditor(QDesignerComponents::createFormEditor(nullptr))
{
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO;
@@ -409,19 +408,18 @@ void FormEditorData::fullInit()
m_modeWidget = new QWidget;
m_modeWidget->setObjectName("DesignerModeWidget");
QVBoxLayout *layout = new QVBoxLayout;
auto layout = new QVBoxLayout(m_modeWidget);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(m_toolBar);
// Avoid mode switch to 'Edit' mode when the application started by
// 'Run' in 'Design' mode emits output.
MiniSplitter *splitter = new MiniSplitter(Qt::Vertical);
auto splitter = new MiniSplitter(Qt::Vertical);
splitter->addWidget(m_editorWidget);
QWidget *outputPane = new OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, splitter);
outputPane->setObjectName("DesignerOutputPanePlaceHolder");
splitter->addWidget(outputPane);
layout->addWidget(splitter);
m_modeWidget->setLayout(layout);
Context designerContexts = m_contexts;
designerContexts.add(Core::Constants::C_EDITORMANAGER);
@@ -648,9 +646,8 @@ void FormEditorData::setupActions()
QToolBar *FormEditorData::createEditorToolBar() const
{
QToolBar *editorToolBar = new QToolBar;
const QList<Id>::const_iterator cend = m_toolActionIds.constEnd();
for (QList<Id>::const_iterator it = m_toolActionIds.constBegin(); it != cend; ++it) {
Command *cmd = ActionManager::command(*it);
for (const auto &id : m_toolActionIds) {
Command *cmd = ActionManager::command(id);
QTC_ASSERT(cmd, continue);
QAction *action = cmd->action();
if (!action->icon().isNull()) // Simplify grid has no action yet
@@ -735,7 +732,7 @@ QAction *FormEditorData::createEditModeAction(QActionGroup *ag,
const QString &iconName,
const QString &keySequence)
{
QAction *rc = new QAction(actionName, ag);
auto rc = new QAction(actionName, ag);
rc->setCheckable(true);
if (!iconName.isEmpty())
rc->setIcon(designerIcon(iconName));
@@ -774,7 +771,7 @@ IEditor *FormEditorData::createEditor()
QTC_ASSERT(form, return nullptr);
QObject::connect(form, &QDesignerFormWindowInterface::toolChanged, [this] (int i) { toolChanged(i); });
SharedTools::WidgetHost *widgetHost = new SharedTools::WidgetHost( /* parent */ nullptr, form);
auto widgetHost = new SharedTools::WidgetHost( /* parent */ nullptr, form);
FormWindowEditor *formWindowEditor = m_xmlEditorFactory->create(form);
m_editorWidget->add(widgetHost, formWindowEditor);

View File

@@ -60,8 +60,7 @@ Utils::WizardPage *FormPageFactory::create(ProjectExplorer::JsonWizard *wizard,
QTC_ASSERT(canCreate(typeId), return nullptr);
FormTemplateWizardPage *page = new FormTemplateWizardPage;
return page;
return new FormTemplateWizardPage;
}
bool FormPageFactory::validateData(Core::Id typeId, const QVariant &data, QString *errorMessage)

View File

@@ -44,9 +44,7 @@ FormWindowEditor::FormWindowEditor()
addContext(Designer::Constants::C_DESIGNER_XML_EDITOR);
}
FormWindowEditor::~FormWindowEditor()
{
}
FormWindowEditor::~FormWindowEditor() = default;
QWidget *FormWindowEditor::toolBar()
{

View File

@@ -84,7 +84,7 @@ Core::IDocument::OpenResult FormWindowFile::open(QString *errorString, const QSt
Utils::TextFileFormat::ReadResult readResult = read(absfileName, &contents, errorString);
if (readResult == Utils::TextFileFormat::ReadEncodingError)
return OpenResult::CannotHandle;
else if (readResult != Utils::TextFileFormat::ReadSuccess)
if (readResult != Utils::TextFileFormat::ReadSuccess)
return OpenResult::ReadError;
form->setFileName(absfileName);

View File

@@ -218,18 +218,18 @@ static const Class *findClass(const Namespace *parentNameSpace, const LookupCont
static Function *findDeclaration(const Class *cl, const QString &functionName)
{
const QString funName = QString::fromUtf8(QMetaObject::normalizedSignature(functionName.toUtf8()));
const unsigned mCount = cl->memberCount();
const int mCount = cl->memberCount();
// we are interested only in declarations (can be decl of function or of a field)
// we are only interested in declarations of functions
const Overview overview;
for (unsigned j = 0; j < mCount; ++j) { // go through all members
for (int j = 0; j < mCount; ++j) { // go through all members
if (Declaration *decl = cl->memberAt(j)->asDeclaration())
if (Function *fun = decl->type()->asFunctionType()) {
// Format signature
QString memberFunction = overview.prettyName(fun->name());
memberFunction += '(';
const uint aCount = fun->argumentCount();
for (uint i = 0; i < aCount; i++) { // we build argument types string
const int aCount = fun->argumentCount();
for (int i = 0; i < aCount; i++) { // we build argument types string
const Argument *arg = fun->argumentAt(i)->asArgument();
if (i > 0)
memberFunction += ',';
@@ -350,7 +350,7 @@ static QString addConstRefIfNeeded(const QString &argument)
"unsigned", "qint64", "quint64"});
for (int i = 0; i < nonConstRefs.count(); i++) {
const QString nonConstRef = nonConstRefs.at(i);
const QString &nonConstRef = nonConstRefs.at(i);
if (argument == nonConstRef || argument.startsWith(nonConstRef + ' '))
return argument;
}
@@ -411,7 +411,7 @@ static QString addParameterNames(const QString &functionSignature, const QString
// included files (going down [maxIncludeDepth] includes) and return a pair
// of <Class*, Document>.
typedef QPair<const Class *, Document::Ptr> ClassDocumentPtrPair;
using ClassDocumentPtrPair = QPair<const Class *, Document::Ptr>;
static ClassDocumentPtrPair
findClassRecursively(const LookupContext &context, const QString &className,
@@ -431,7 +431,7 @@ static ClassDocumentPtrPair
for (const QString &include : includedFiles) {
const Snapshot::const_iterator it = docTable.find(include);
if (it != docTable.end()) {
const Document::Ptr includeDoc = it.value();
const Document::Ptr &includeDoc = it.value();
LookupContext context(includeDoc, docTable);
const ClassDocumentPtrPair irc = findClassRecursively(context, className,
recursionMaxIncludeDepth, namespaceName);
@@ -489,7 +489,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
const QStringList &parameterNames,
QString *errorMessage)
{
typedef QMap<int, Document::Ptr> DocumentMap;
using DocumentMap = QMap<int, Document::Ptr>;
const Utils::FilePath currentUiFile = FormEditorW::activeEditor()->document()->filePath();
#if 0

View File

@@ -73,10 +73,7 @@ void ResourceHandler::ensureInitialized()
qDebug() << "ResourceHandler::ensureInitialized() origPaths=" << m_originalUiQrcPaths;
}
ResourceHandler::~ResourceHandler()
{
}
ResourceHandler::~ResourceHandler() = default;
void ResourceHandler::updateResourcesHelper(bool updateProjectResources)
{

View File

@@ -42,14 +42,13 @@ using namespace SharedTools::Internal;
FormResizer::FormResizer(QWidget *parent) :
QWidget(parent),
m_frame(new QFrame),
m_formWindow(0)
m_frame(new QFrame)
{
// Make the resize grip of a mainwindow form find us as resizable window.
setWindowFlags(windowFlags() | Qt::SubWindow);
setBackgroundRole(QPalette::Base);
QVBoxLayout *handleLayout = new QVBoxLayout(this);
auto handleLayout = new QVBoxLayout(this);
handleLayout->setContentsMargins(SELECTION_MARGIN, SELECTION_MARGIN,
SELECTION_MARGIN, SELECTION_MARGIN);
handleLayout->addWidget(m_frame);
@@ -166,7 +165,7 @@ QWidget *FormResizer::mainContainer()
{
if (m_formWindow)
return m_formWindow->mainContainer();
return 0;
return nullptr;
}
void FormResizer::mainContainerChanged()

View File

@@ -60,7 +60,7 @@ class FormResizer : public QWidget
Q_OBJECT
public:
FormResizer(QWidget *parent = 0);
FormResizer(QWidget *parent = nullptr);
void updateGeometry();
void setState(SelectionHandleState st);
@@ -84,7 +84,7 @@ private:
QFrame *m_frame;
typedef QVector<SizeHandleRect*> Handles;
Handles m_handles;
QDesignerFormWindowInterface * m_formWindow;
QDesignerFormWindowInterface *m_formWindow = nullptr;
};
}

View File

@@ -41,7 +41,6 @@ using namespace SharedTools;
// ---------- WidgetHost
WidgetHost::WidgetHost(QWidget *parent, QDesignerFormWindowInterface *formWindow) :
QScrollArea(parent),
m_formWindow(0),
m_formResizer(new Internal::FormResizer)
{
setWidget(m_formResizer);
@@ -52,8 +51,7 @@ WidgetHost::WidgetHost(QWidget *parent, QDesignerFormWindowInterface *formWindow
WidgetHost::~WidgetHost()
{
if (m_formWindow)
delete m_formWindow;
delete m_formWindow;
}
void WidgetHost::setFormWindow(QDesignerFormWindowInterface *fw)
@@ -75,7 +73,7 @@ void WidgetHost::setFormWindow(QDesignerFormWindowInterface *fw)
QSize WidgetHost::formWindowSize() const
{
if (!m_formWindow || !m_formWindow->mainContainer())
return QSize();
return {};
return m_formWindow->mainContainer()->size();
}

View File

@@ -60,7 +60,7 @@ private slots:
private:
QSize formWindowSize() const;
QDesignerFormWindowInterface *m_formWindow;
QDesignerFormWindowInterface *m_formWindow = nullptr;
Internal::FormResizer *m_formResizer;
QSize m_oldFakeWidgetSize;
};