uic: Fix clang-tidy warnings
- Simplify/streamline if statmenents - Change else if to if after return/break/continue - Use isEmpty() for containers instead of checking size() - Replace index-based loops by range-based for Change-Id: I008228a99082a4d0e27be9f6c6af392602140b2f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>bb10
parent
22eb4bacae
commit
abc024eef7
|
|
@ -40,10 +40,11 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace {
|
||||
void openNameSpaces(const QStringList &namespaceList, QTextStream &output) {
|
||||
for (auto it = namespaceList.begin(), end = namespaceList.end(); it != end; ++it) {
|
||||
if (!it->isEmpty())
|
||||
output << "namespace " << *it << " {\n";
|
||||
void openNameSpaces(const QStringList &namespaceList, QTextStream &output)
|
||||
{
|
||||
for (const QString &n : namespaceList) {
|
||||
if (!n.isEmpty())
|
||||
output << "namespace " << n << " {\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,13 +104,9 @@ void WriteDeclaration::acceptUI(DomUI *node)
|
|||
<< "public:\n";
|
||||
|
||||
const QStringList connections = m_uic->databaseInfo()->connections();
|
||||
for (int i=0; i<connections.size(); ++i) {
|
||||
const QString connection = connections.at(i);
|
||||
|
||||
if (connection == QLatin1String("(default)"))
|
||||
continue;
|
||||
|
||||
m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n";
|
||||
for (const QString &connection : connections) {
|
||||
if (connection != QLatin1String("(default)"))
|
||||
m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n";
|
||||
}
|
||||
|
||||
TreeWalker::acceptWidget(node->elementWidget());
|
||||
|
|
|
|||
|
|
@ -519,11 +519,9 @@ void WriteInitialization::acceptUI(DomUI *node)
|
|||
|
||||
acceptWidget(node->elementWidget());
|
||||
|
||||
if (m_buddies.size() > 0)
|
||||
if (!m_buddies.empty())
|
||||
openIfndef(m_output, QLatin1String(shortcutDefineC));
|
||||
for (int i=0; i<m_buddies.size(); ++i) {
|
||||
const Buddy &b = m_buddies.at(i);
|
||||
|
||||
for (const Buddy &b : qAsConst(m_buddies)) {
|
||||
if (!m_registeredWidgets.contains(b.objName)) {
|
||||
fprintf(stderr, "%s: Warning: Buddy assignment: '%s' is not a valid widget.\n",
|
||||
qPrintable(m_option.messagePrefix()),
|
||||
|
|
@ -538,7 +536,7 @@ void WriteInitialization::acceptUI(DomUI *node)
|
|||
|
||||
m_output << m_indent << b.objName << "->setBuddy(" << b.buddy << ");\n";
|
||||
}
|
||||
if (m_buddies.size() > 0)
|
||||
if (!m_buddies.empty())
|
||||
closeIfndef(m_output, QLatin1String(shortcutDefineC));
|
||||
|
||||
if (node->elementTabStops())
|
||||
|
|
@ -817,9 +815,7 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||
m_layoutChain.pop();
|
||||
|
||||
const QStringList zOrder = node->elementZOrder();
|
||||
for (int i = 0; i < zOrder.size(); ++i) {
|
||||
const QString name = zOrder.at(i);
|
||||
|
||||
for (const QString &name : zOrder) {
|
||||
if (!m_registeredWidgets.contains(name)) {
|
||||
fprintf(stderr, "%s: Warning: Z-order assignment: '%s' is not a valid widget.\n",
|
||||
qPrintable(m_option.messagePrefix()),
|
||||
|
|
@ -827,11 +823,8 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_output << m_indent << name << "->raise();\n";
|
||||
if (!name.isEmpty())
|
||||
m_output << m_indent << name << "->raise();\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1159,8 +1152,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||
leftMargin = topMargin = rightMargin = bottomMargin = -1;
|
||||
bool frameShadowEncountered = false;
|
||||
|
||||
for (int i=0; i<lst.size(); ++i) {
|
||||
const DomProperty *p = lst.at(i);
|
||||
for (const DomProperty *p : lst) {
|
||||
if (!checkProperty(m_option.inputFile, p))
|
||||
continue;
|
||||
QString propertyName = p->attributeName();
|
||||
|
|
@ -1172,30 +1164,35 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||
const DomRect *r = p->elementRect();
|
||||
m_output << m_indent << varName << "->resize(" << r->elementWidth() << ", " << r->elementHeight() << ");\n";
|
||||
continue;
|
||||
} else if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) {
|
||||
}
|
||||
if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) {
|
||||
m_delayedOut << m_indent << varName << "->setCurrentRow("
|
||||
<< p->elementNumber() << ");\n";
|
||||
continue;
|
||||
} else if (propertyName == QLatin1String("currentIndex") // set currentIndex later
|
||||
&& (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QComboBox"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStackedWidget"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTabWidget"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox")))) {
|
||||
}
|
||||
if (propertyName == QLatin1String("currentIndex") // set currentIndex later
|
||||
&& (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QComboBox"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStackedWidget"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTabWidget"))
|
||||
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox")))) {
|
||||
m_delayedOut << m_indent << varName << "->setCurrentIndex("
|
||||
<< p->elementNumber() << ");\n";
|
||||
continue;
|
||||
} else if (propertyName == QLatin1String("tabSpacing")
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox"))) {
|
||||
}
|
||||
if (propertyName == QLatin1String("tabSpacing")
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox"))) {
|
||||
m_delayedOut << m_indent << varName << "->layout()->setSpacing("
|
||||
<< p->elementNumber() << ");\n";
|
||||
continue;
|
||||
} else if (propertyName == QLatin1String("control") // ActiveQt support
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) {
|
||||
}
|
||||
if (propertyName == QLatin1String("control") // ActiveQt support
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) {
|
||||
// already done ;)
|
||||
continue;
|
||||
} else if (propertyName == QLatin1String("default")
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QPushButton"))) {
|
||||
}
|
||||
if (propertyName == QLatin1String("default")
|
||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QPushButton"))) {
|
||||
// QTBUG-44406: Setting of QPushButton::default needs to be delayed until the parent is set
|
||||
delayProperty = true;
|
||||
} else if (propertyName == QLatin1String("database")
|
||||
|
|
@ -1850,7 +1847,7 @@ void WriteInitialization::acceptTabStops(DomTabStops *tabStops)
|
|||
|
||||
const QStringList l = tabStops->elementTabStop();
|
||||
for (int i=0; i<l.size(); ++i) {
|
||||
const QString name = l.at(i);
|
||||
const QString &name = l.at(i);
|
||||
|
||||
if (!m_registeredWidgets.contains(name)) {
|
||||
fprintf(stderr, "%s: Warning: Tab-stop assignment: '%s' is not a valid widget.\n",
|
||||
|
|
@ -1862,9 +1859,9 @@ void WriteInitialization::acceptTabStops(DomTabStops *tabStops)
|
|||
if (i == 0) {
|
||||
lastName = name;
|
||||
continue;
|
||||
} else if (name.isEmpty() || lastName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (name.isEmpty() || lastName.isEmpty())
|
||||
continue;
|
||||
|
||||
m_output << m_indent << "QWidget::setTabOrder(" << lastName << ", " << name << ");\n";
|
||||
|
||||
|
|
@ -2134,7 +2131,7 @@ void WriteInitialization::initializeTreeWidget(DomWidget *w)
|
|||
if (!itemName.isNull())
|
||||
m_output << m_indent << varName << "->setHeaderItem(" << itemName << ");\n";
|
||||
|
||||
if (w->elementItem().size() == 0)
|
||||
if (w->elementItem().empty())
|
||||
return;
|
||||
|
||||
QString tempName = disableSorting(w, varName);
|
||||
|
|
@ -2176,9 +2173,8 @@ QList<WriteInitialization::Item *> WriteInitialization::initializeTreeWidgetItem
|
|||
|
||||
int col = -1;
|
||||
const DomPropertyList properties = domItem->elementProperty();
|
||||
for (int j = 0; j < properties.size(); ++j) {
|
||||
DomProperty *p = properties.at(j);
|
||||
if (p->attributeName() == QLatin1String("text")) {
|
||||
for (DomProperty *p : properties) {
|
||||
if (p->attributeName() == QLatin1String("text")) {
|
||||
if (!map.isEmpty()) {
|
||||
addCommonInitializers(item, map, col);
|
||||
map.clear();
|
||||
|
|
@ -2205,7 +2201,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w)
|
|||
// columns
|
||||
const auto &columns = w->elementColumn();
|
||||
|
||||
if (columns.size() != 0) {
|
||||
if (!columns.empty()) {
|
||||
m_output << m_indent << "if (" << varName << "->columnCount() < " << columns.size() << ")\n"
|
||||
<< m_dindent << varName << "->setColumnCount(" << columns.size() << ");\n";
|
||||
}
|
||||
|
|
@ -2227,7 +2223,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w)
|
|||
// rows
|
||||
const auto &rows = w->elementRow();
|
||||
|
||||
if (rows.size() != 0) {
|
||||
if (!rows.isEmpty()) {
|
||||
m_output << m_indent << "if (" << varName << "->rowCount() < " << rows.size() << ")\n"
|
||||
<< m_dindent << varName << "->setRowCount(" << rows.size() << ");\n";
|
||||
}
|
||||
|
|
@ -2251,8 +2247,7 @@ void WriteInitialization::initializeTableWidget(DomWidget *w)
|
|||
|
||||
const auto &items = w->elementItem();
|
||||
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
const DomItem *cell = items.at(i);
|
||||
for (const DomItem *cell : items) {
|
||||
if (cell->hasAttributeRow() && cell->hasAttributeColumn() && !cell->elementProperty().isEmpty()) {
|
||||
const int r = cell->attributeRow();
|
||||
const int c = cell->attributeColumn();
|
||||
|
|
@ -2460,13 +2455,13 @@ QString WriteInitialization::Item::writeSetupUi(const QString &parent, Item::Emp
|
|||
return QString();
|
||||
|
||||
bool generateMultiDirective = false;
|
||||
if (emptyItemPolicy == Item::ConstructItemOnly && m_children.size() == 0) {
|
||||
if (emptyItemPolicy == Item::ConstructItemOnly && m_children.isEmpty()) {
|
||||
if (m_setupUiData.policy == ItemData::DontGenerate) {
|
||||
m_setupUiStream << m_indent << "new " << m_itemClassName << '(' << parent << ");\n";
|
||||
return QString();
|
||||
} else if (m_setupUiData.policy == ItemData::GenerateWithMultiDirective) {
|
||||
generateMultiDirective = true;
|
||||
return QString();
|
||||
}
|
||||
if (m_setupUiData.policy == ItemData::GenerateWithMultiDirective)
|
||||
generateMultiDirective = true;
|
||||
}
|
||||
|
||||
if (generateMultiDirective)
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ private:
|
|||
// special initialization
|
||||
//
|
||||
class Item {
|
||||
Q_DISABLE_COPY(Item)
|
||||
public:
|
||||
Item(const QString &itemClassName, const QString &indent, QTextStream &setupUiStream, QTextStream &retranslateUiStream, Driver *driver);
|
||||
~Item();
|
||||
|
|
@ -176,15 +177,15 @@ private:
|
|||
int setupUiCount() const { return m_setupUiData.setters.count(); }
|
||||
int retranslateUiCount() const { return m_retranslateUiData.setters.count(); }
|
||||
private:
|
||||
struct ItemData {
|
||||
ItemData() : policy(DontGenerate) {}
|
||||
struct ItemData
|
||||
{
|
||||
QMultiMap<QString, QString> setters; // directive to setter
|
||||
QSet<QString> directives;
|
||||
enum TemporaryVariableGeneratorPolicy { // policies with priority, number describes the priority
|
||||
DontGenerate = 1,
|
||||
GenerateWithMultiDirective = 2,
|
||||
Generate = 3
|
||||
} policy;
|
||||
} policy = DontGenerate;
|
||||
};
|
||||
ItemData m_setupUiData;
|
||||
ItemData m_retranslateUiData;
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
CustomWidgetsInfo::CustomWidgetsInfo()
|
||||
{
|
||||
}
|
||||
CustomWidgetsInfo::CustomWidgetsInfo() = default;
|
||||
|
||||
void CustomWidgetsInfo::acceptUI(DomUI *node)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ Driver::Driver()
|
|||
m_output = &m_stdout;
|
||||
}
|
||||
|
||||
Driver::~Driver()
|
||||
{
|
||||
}
|
||||
Driver::~Driver() = default;
|
||||
|
||||
QString Driver::findOrInsertWidget(DomWidget *ui_widget)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class DomButtonGroup;
|
|||
|
||||
class Driver
|
||||
{
|
||||
Q_DISABLE_COPY(Driver)
|
||||
public:
|
||||
Driver();
|
||||
virtual ~Driver();
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class DomButtonGroup;
|
|||
|
||||
struct TreeWalker
|
||||
{
|
||||
inline virtual ~TreeWalker() {}
|
||||
inline virtual ~TreeWalker() = default;
|
||||
|
||||
virtual void acceptUI(DomUI *ui);
|
||||
virtual void acceptLayoutDefault(DomLayoutDefault *layoutDefault);
|
||||
|
|
|
|||
|
|
@ -56,9 +56,7 @@ Uic::Uic(Driver *d)
|
|||
{
|
||||
}
|
||||
|
||||
Uic::~Uic()
|
||||
{
|
||||
}
|
||||
Uic::~Uic() = default;
|
||||
|
||||
bool Uic::printDependencies()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ struct Option;
|
|||
|
||||
class Uic
|
||||
{
|
||||
Q_DISABLE_COPY(Uic)
|
||||
public:
|
||||
Uic(Driver *driver);
|
||||
~Uic();
|
||||
|
|
|
|||
|
|
@ -94,12 +94,8 @@ inline QString fixString(const QString &str, const QString &indent)
|
|||
inline QHash<QString, DomProperty *> propertyMap(const QList<DomProperty *> &properties)
|
||||
{
|
||||
QHash<QString, DomProperty *> map;
|
||||
|
||||
for (int i=0; i<properties.size(); ++i) {
|
||||
DomProperty *p = properties.at(i);
|
||||
map.insert(p->attributeName(), p);
|
||||
}
|
||||
|
||||
for (DomProperty *p : properties)
|
||||
map.insert(p->attributeName(), p);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue