diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp index e018e7bf31a..840b71c6711 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp @@ -768,7 +768,8 @@ QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlC qWarning() << error; } - object->setProperty("__designer_url__", QUrl::fromLocalFile(componentPath)); + if (object) + object->setProperty("__designer_url__", QUrl::fromLocalFile(componentPath)); return object; } diff --git a/src/libs/sqlite/createtablesqlstatementbuilder.cpp b/src/libs/sqlite/createtablesqlstatementbuilder.cpp index 2ea93d2bcdd..07008a9a1da 100644 --- a/src/libs/sqlite/createtablesqlstatementbuilder.cpp +++ b/src/libs/sqlite/createtablesqlstatementbuilder.cpp @@ -192,6 +192,8 @@ public: columnDefinitionString.append(defaultValue.value.toStringView()); columnDefinitionString.append("'"); break; + default: + break; } } diff --git a/src/libs/sqlite/lastchangedrowid.h b/src/libs/sqlite/lastchangedrowid.h index b7e1969daf0..a1d3331abbf 100644 --- a/src/libs/sqlite/lastchangedrowid.h +++ b/src/libs/sqlite/lastchangedrowid.h @@ -33,6 +33,7 @@ namespace Sqlite { +template class LastChangedRowId { public: @@ -40,86 +41,82 @@ public: : database(database) { - callback = [=](ChangeType, char const *, char const *, long long rowId) { - this->lastRowId = rowId; - }; - - database.setUpdateHook(callback); + database.setUpdateHook(this, callbackOnlyRowId); } LastChangedRowId(DatabaseInterface &database, Utils::SmallStringView databaseName) : database(database) - + , databaseName(databaseName) { - callback = [=](ChangeType, char const *database, char const *, long long rowId) { - if (databaseName == database) - this->lastRowId = rowId; - }; - - database.setUpdateHook(callback); + database.setUpdateHook(this, callbackWithDatabase); } + template LastChangedRowId(DatabaseInterface &database, Utils::SmallStringView databaseName, - Utils::SmallStringView tableName) + Tables... tableNames) : database(database) - + , databaseName(databaseName) + , tableNames({tableNames...}) { - callback = [=](ChangeType, char const *database, char const *table, long long rowId) { - if (databaseName == database && tableName == table) - this->lastRowId = rowId; - }; - - database.setUpdateHook(callback); - } - - LastChangedRowId(DatabaseInterface &database, - Utils::SmallStringView databaseName, - Utils::SmallStringView tableName, - Utils::SmallStringView tableName2) - : database(database) - - { - callback = [=](ChangeType, char const *database, char const *table, long long rowId) { - if (databaseName == database && (tableName == table || tableName2 == table)) - this->lastRowId = rowId; - }; - - database.setUpdateHook(callback); - } - - LastChangedRowId(DatabaseInterface &database, - Utils::SmallStringView databaseName, - Utils::SmallStringView tableName, - Utils::SmallStringView tableName2, - Utils::SmallStringView tableName3) - : database(database) - - { - callback = [=](ChangeType, char const *database, char const *table, long long rowId) { - if (databaseName == database - && (tableName == table || tableName2 == table || tableName3 == table)) - this->lastRowId = rowId; - }; - - database.setUpdateHook(callback); + database.setUpdateHook(this, callbackWithTables); } ~LastChangedRowId() { database.resetUpdateHook(); } - long long takeLastRowId() + void operator()(long long rowId) { lastRowId = rowId; } + + static void callbackOnlyRowId(void *object, int, char const *, char const *, long long rowId) { - long long rowId = lastRowId; - lastRowId = -1; - return rowId; + (*static_cast(object))(rowId); } - bool lastRowIdIsValid() { return lastRowId >= 0; } + bool containsTable(Utils::SmallStringView table) + { + return std::find(tableNames.begin(), tableNames.end(), table) != tableNames.end(); + } + + void operator()(Utils::SmallStringView database, long long rowId) + { + if (databaseName == database) + lastRowId = rowId; + } + + static void callbackWithDatabase( + void *object, int, char const *database, char const *, long long rowId) + { + (*static_cast(object))(Utils::SmallStringView{database}, rowId); + } + + void operator()(Utils::SmallStringView database, Utils::SmallStringView table, long long rowId) + { + if (databaseName == database && containsTable(table)) + lastRowId = rowId; + } + + static void callbackWithTables( + void *object, int, char const *database, char const *table, long long rowId) + { + (*static_cast( + object))(Utils::SmallStringView{database}, Utils::SmallStringView{table}, rowId); + } + + long long takeLastRowId() + { + long long lastId = lastRowId; + + lastRowId = -1; + + return lastId; + } + + bool lastRowIdIsValid() const { return lastRowId >= 0; } public: DatabaseInterface &database; - DatabaseInterface::UpdateCallback callback; long long lastRowId = -1; + Utils::SmallStringView databaseName; + std::array tableNames; }; } // namespace Sqlite diff --git a/src/libs/sqlite/sqlitebasestatement.cpp b/src/libs/sqlite/sqlitebasestatement.cpp index f8dadeb425b..ce22ece5262 100644 --- a/src/libs/sqlite/sqlitebasestatement.cpp +++ b/src/libs/sqlite/sqlitebasestatement.cpp @@ -214,6 +214,9 @@ void BaseStatement::bind(int index, const Value &value) case ValueType::String: bind(index, value.toStringView()); break; + case ValueType::Null: + bind(index, NullValue{}); + break; } } diff --git a/src/libs/sqlite/sqlitedatabase.h b/src/libs/sqlite/sqlitedatabase.h index 1fd8e832ef1..54836f01094 100644 --- a/src/libs/sqlite/sqlitedatabase.h +++ b/src/libs/sqlite/sqlitedatabase.h @@ -89,7 +89,7 @@ public: void setOpenMode(OpenMode openMode); OpenMode openMode() const; - void execute(Utils::SmallStringView sqlStatement); + void execute(Utils::SmallStringView sqlStatement) override; DatabaseBackend &backend(); @@ -116,15 +116,20 @@ public: m_databaseBackend.walCheckpointFull(); } - void setUpdateHook(DatabaseBackend::UpdateCallback &callback) + void setUpdateHook(void *object, + void (*callback)(void *object, + int, + char const *database, + char const *, + long long rowId)) override { - m_databaseBackend.setUpdateHook(callback); + m_databaseBackend.setUpdateHook(object, callback); } - void resetUpdateHook() { m_databaseBackend.resetUpdateHook(); } + void resetUpdateHook() override { m_databaseBackend.resetUpdateHook(); } - void setAttachedTables(const Utils::SmallStringVector &tables); - void applyAndUpdateSessions(); + void setAttachedTables(const Utils::SmallStringVector &tables) override; + void applyAndUpdateSessions() override; private: void deferredBegin() override; diff --git a/src/libs/sqlite/sqlitedatabasebackend.cpp b/src/libs/sqlite/sqlitedatabasebackend.cpp index a0edd8e78d1..cad3ed879b3 100644 --- a/src/libs/sqlite/sqlitedatabasebackend.cpp +++ b/src/libs/sqlite/sqlitedatabasebackend.cpp @@ -400,22 +400,11 @@ void DatabaseBackend::walCheckpointFull() } } -namespace { -void updateCallback( - void *callback, int type, char const *database, char const *table, sqlite3_int64 row) +void DatabaseBackend::setUpdateHook( + void *object, + void (*callback)(void *object, int, char const *database, char const *, long long rowId)) { - auto &function = *reinterpret_cast(callback); - - function(static_cast(type), database, table, row); -} -} // namespace - -void DatabaseBackend::setUpdateHook(UpdateCallback &callback) -{ - if (callback) - sqlite3_update_hook(m_databaseHandle, updateCallback, &callback); - else - sqlite3_update_hook(m_databaseHandle, nullptr, nullptr); + sqlite3_update_hook(m_databaseHandle, callback, object); } void DatabaseBackend::resetUpdateHook() diff --git a/src/libs/sqlite/sqlitedatabasebackend.h b/src/libs/sqlite/sqlitedatabasebackend.h index 355ed41f920..2e7b25a4678 100644 --- a/src/libs/sqlite/sqlitedatabasebackend.h +++ b/src/libs/sqlite/sqlitedatabasebackend.h @@ -41,9 +41,6 @@ class Database; class SQLITE_EXPORT DatabaseBackend { public: - using UpdateCallback - = std::function; - DatabaseBackend(Database &database); ~DatabaseBackend(); @@ -88,7 +85,9 @@ public: void walCheckpointFull(); - void setUpdateHook(UpdateCallback &callback); + void setUpdateHook( + void *object, + void (*callback)(void *object, int, char const *database, char const *, long long rowId)); void resetUpdateHook(); protected: diff --git a/src/libs/sqlite/sqlitedatabaseinterface.h b/src/libs/sqlite/sqlitedatabaseinterface.h index 46bc2dcab7d..a8a8928e1df 100644 --- a/src/libs/sqlite/sqlitedatabaseinterface.h +++ b/src/libs/sqlite/sqlitedatabaseinterface.h @@ -29,18 +29,16 @@ #include "sqliteglobal.h" -#include - namespace Sqlite { class DatabaseInterface { public: - using UpdateCallback - = std::function; - virtual void walCheckpointFull() = 0; virtual void execute(Utils::SmallStringView sqlStatement) = 0; - virtual void setUpdateHook(UpdateCallback &callback) = 0; + virtual void setUpdateHook( + void *object, + void (*)(void *object, int, char const *database, char const *, long long rowId)) + = 0; virtual void resetUpdateHook() = 0; virtual void applyAndUpdateSessions() = 0; virtual void setAttachedTables(const Utils::SmallStringVector &tables) = 0; diff --git a/src/libs/sqlite/sqlitevalue.h b/src/libs/sqlite/sqlitevalue.h index a57ad7aa120..934db37642e 100644 --- a/src/libs/sqlite/sqlitevalue.h +++ b/src/libs/sqlite/sqlitevalue.h @@ -102,6 +102,8 @@ public: return QVariant(toFloat()); case ValueType::String: return QVariant(QString(toStringView())); + case ValueType::Null: + break; } return {}; @@ -281,6 +283,8 @@ public: return first.toFloat() == second.toFloat(); case ValueType::String: return first.toStringView() == second.toStringView(); + case ValueType::Null: + return false; } return false; diff --git a/src/plugins/clangrefactoring/CMakeLists.txt b/src/plugins/clangrefactoring/CMakeLists.txt index 53930f13dea..95c926dc2d0 100644 --- a/src/plugins/clangrefactoring/CMakeLists.txt +++ b/src/plugins/clangrefactoring/CMakeLists.txt @@ -36,6 +36,6 @@ add_qtc_plugin(ClangRefactoring symbol.h symbolquery.h symbolqueryinterface.h - symbolsfindfilter.cpp symbolsfindfilter.h + clangsymbolsfindfilter.cpp clangsymbolsfindfilter.h symbolsfindfilterconfigwidget.cpp symbolsfindfilterconfigwidget.h ) diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri index b12d4a9b986..273e6fe834a 100644 --- a/src/plugins/clangrefactoring/clangrefactoring-source.pri +++ b/src/plugins/clangrefactoring/clangrefactoring-source.pri @@ -6,6 +6,7 @@ HEADERS += \ $$PWD/clangqueryhighlighter.h \ $$PWD/clangqueryhighlightmarker.h \ $$PWD/clangqueryprojectsfindfilter.h \ + $$PWD/clangsymbolsfindfilter.h \ $$PWD/projectpartutilities.h \ $$PWD/refactoringclient.h \ $$PWD/refactoringconnectionclient.h \ @@ -13,7 +14,6 @@ HEADERS += \ $$PWD/refactoringprojectupdater.h \ $$PWD/searchinterface.h \ $$PWD/searchhandle.h \ - $$PWD/symbolsfindfilter.h \ $$PWD/symbolqueryinterface.h \ $$PWD/symbol.h \ $$PWD/projectpartproviderinterface.h \ @@ -24,11 +24,11 @@ SOURCES += \ $$PWD/clangqueryexamplehighlighter.cpp \ $$PWD/clangqueryhighlighter.cpp \ $$PWD/clangqueryprojectsfindfilter.cpp \ + $$PWD/clangsymbolsfindfilter.cpp \ $$PWD/projectpartutilities.cpp \ $$PWD/refactoringclient.cpp \ $$PWD/refactoringconnectionclient.cpp \ $$PWD/refactoringengine.cpp \ $$PWD/refactoringprojectupdater.cpp \ $$PWD/searchhandle.cpp \ - $$PWD/symbolsfindfilter.cpp \ $$PWD/locatorfilter.cpp diff --git a/src/plugins/clangrefactoring/clangrefactoring.qbs b/src/plugins/clangrefactoring/clangrefactoring.qbs index ec8c4c6a247..b440d6e08e1 100644 --- a/src/plugins/clangrefactoring/clangrefactoring.qbs +++ b/src/plugins/clangrefactoring/clangrefactoring.qbs @@ -73,8 +73,8 @@ QtcPlugin { "symbol.h", "symbolquery.h", "symbolqueryinterface.h", - "symbolsfindfilter.cpp", - "symbolsfindfilter.h", + "clangsymbolsfindfilter.cpp", + "clangsymbolsfindfilter.h", "symbolsfindfilterconfigwidget.cpp", "symbolsfindfilterconfigwidget.h", ] diff --git a/src/plugins/clangrefactoring/symbolsfindfilter.cpp b/src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp similarity index 98% rename from src/plugins/clangrefactoring/symbolsfindfilter.cpp rename to src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp index f043c612bce..c2555586346 100644 --- a/src/plugins/clangrefactoring/symbolsfindfilter.cpp +++ b/src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp @@ -23,7 +23,7 @@ ** ****************************************************************************/ -#include "symbolsfindfilter.h" +#include "clangsymbolsfindfilter.h" #include diff --git a/src/plugins/clangrefactoring/symbolsfindfilter.h b/src/plugins/clangrefactoring/clangsymbolsfindfilter.h similarity index 100% rename from src/plugins/clangrefactoring/symbolsfindfilter.h rename to src/plugins/clangrefactoring/clangsymbolsfindfilter.h diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h index cd09463088d..60a6d1d7a99 100644 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h +++ b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h @@ -25,7 +25,7 @@ #pragma once -#include "symbolsfindfilter.h" +#include "clangsymbolsfindfilter.h" namespace ClangRefactoring { diff --git a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp b/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp index 9c391676e1f..abe3013c7d9 100644 --- a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp +++ b/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp @@ -26,7 +26,7 @@ #include "symbolsfindfilterconfigwidget.h" -#include "symbolsfindfilter.h" +#include "clangsymbolsfindfilter.h" namespace ClangRefactoring { diff --git a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp index 15a3f3a93ef..946a3e72e79 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp @@ -56,6 +56,7 @@ const int flowBlockSize = 200; const int blockRadius = 18; const int blockAdjust = 40; const int startItemOffset = 96; +const int labelFontSize = 16; void drawIcon(QPainter *painter, int x, @@ -670,6 +671,7 @@ void FormEditorFlowActionItem::paint(QPainter *painter, const QStyleOptionGraphi if (qmlItemNode().modelNode().hasAuxiliaryData("color")) flowColor = qmlItemNode().modelNode().auxiliaryData("color").value(); + const qreal scaleFactor = viewportTransform().m11(); qreal width = 2; if (qmlItemNode().modelNode().hasAuxiliaryData("width")) @@ -787,26 +789,28 @@ public: } } } - // Only assign area node if there is exactly one from (QmlFlowItemNode) - if (from.size() == 1) { - const QmlItemNode tmp = from.back(); - const QmlFlowItemNode f(tmp.modelNode()); - if (f.isValid()) { - for (const QmlFlowActionAreaNode &area : f.flowActionAreas()) { - ModelNode target = area.targetTransition(); - if (target == node.modelNode()) { - areaNode = area; - } else { - const ModelNode decisionNode = area.decisionNodeForTransition(node.modelNode()); - if (decisionNode.isValid()) { - from.clear(); - from.append(decisionNode); - areaNode = ModelNode(); + + // Only assign area node if there is exactly one from (QmlFlowItemNode) + if (from.size() == 1) { + const QmlItemNode tmp = from.back(); + const QmlFlowItemNode f(tmp.modelNode()); + + if (f.isValid()) { + for (const QmlFlowActionAreaNode &area : f.flowActionAreas()) { + ModelNode target = area.targetTransition(); + if (target == node.modelNode()) { + areaNode = area; + } else { + const ModelNode decisionNode = area.decisionNodeForTransition(node.modelNode()); + if (decisionNode.isValid()) { + from.clear(); + from.append(decisionNode); + areaNode = ModelNode(); + } } } - } - if (f.modelNode().hasAuxiliaryData("joinConnection")) - joinConnection = f.modelNode().auxiliaryData("joinConnection").toBool(); + if (f.modelNode().hasAuxiliaryData("joinConnection")) + joinConnection = f.modelNode().auxiliaryData("joinConnection").toBool(); } else { if (f == node.rootModelNode()) isStartLine = true; @@ -852,7 +856,7 @@ public: , bezier(50) , type(ConnectionType::Default) , label() - , fontSize(16 / scaleFactor) + , fontSize(labelFontSize / scaleFactor) , labelOffset(14 / scaleFactor) , labelPosition(50.0) , labelFlags(Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextDontClip) @@ -1159,10 +1163,29 @@ public: const ConnectionConfiguration &connectionConfig) : config(connectionConfig) { - if (from.isFlowDecision() || from.isFlowWildcard() || from.isFlowView()) + if (from.isFlowDecision()) { + int size = flowBlockSize; + if (from.modelNode().hasAuxiliaryData("blockSize")) + size = from.modelNode().auxiliaryData("blockSize").toInt(); + + fromRect = QRectF(0, 0, size, size); + + QTransform transform; + transform.translate(fromRect.center().x(), fromRect.center().y()); + transform.rotate(45); + transform.translate(-fromRect.center().x(), -fromRect.center().y()); + + fromRect = transform.mapRect(fromRect); + } else if (from.isFlowWildcard()) { + int size = flowBlockSize; + if (from.modelNode().hasAuxiliaryData("blockSize")) + size = from.modelNode().auxiliaryData("blockSize").toInt(); + fromRect = QRectF(0, 0, size, size); + } else if (from.isFlowView()) { fromRect = QRectF(0, 0, flowBlockSize, flowBlockSize); - else + } else { fromRect = from.instanceBoundingRect(); + } fromRect.translate(from.flowPosition()); @@ -1172,15 +1195,27 @@ public: fromRect.translate(resolveConnection.areaNode.instancePosition()); } - if (to.isFlowDecision()) - toRect = QRectF(0, 0, flowBlockSize,flowBlockSize); - else + if (to.isFlowDecision()) { + int size = flowBlockSize; + if (to.modelNode().hasAuxiliaryData("blockSize")) + size = to.modelNode().auxiliaryData("blockSize").toInt(); + + toRect = QRectF(0, 0, size, size); + + QTransform transform; + transform.translate(toRect.center().x(), toRect.center().y()); + transform.rotate(45); + transform.translate(-toRect.center().x(), -toRect.center().y()); + + toRect = transform.mapRect(toRect); + } else { toRect = to.instanceBoundingRect(); + } toRect.translate(to.flowPosition()); if (resolveConnection.isStartLine) { - fromRect = QRectF(0, 0, 96, 96); + fromRect = QRectF(0, 0, 96, 96); // TODO Use const startItemOffset fromRect.translate(to.flowPosition() + QPoint(-180, toRect.height() / 2 - 96 / 2)); fromRect.translate(0, config.outOffset); } @@ -1623,7 +1658,76 @@ QTransform FormEditorItem::viewportTransform() const void FormEditorFlowDecisionItem::updateGeometry() { prepareGeometryChange(); - m_selectionBoundingRect = QRectF(0, 0, flowBlockSize, flowBlockSize); + + int size = flowBlockSize; + if (qmlItemNode().modelNode().hasAuxiliaryData("blockSize")) + size = qmlItemNode().modelNode().auxiliaryData("blockSize").toInt(); + + QRectF boundingRect(0, 0, size, size); + QTransform transform; + if (qmlItemNode().isFlowDecision()) { + transform.translate(boundingRect.center().x(), boundingRect.center().y()); + transform.rotate(45); + transform.translate(-boundingRect.center().x(), -boundingRect.center().y()); + + // If drawing the dialog title is requested we need to add it to the bounding rect. + QRectF labelBoundingRect; + int showDialogLabel = false; + if (qmlItemNode().modelNode().hasAuxiliaryData("showDialogLabel")) + showDialogLabel = qmlItemNode().modelNode().auxiliaryData("showDialogLabel").toBool(); + + if (showDialogLabel) { + QString dialogTitle; + if (qmlItemNode().modelNode().hasVariantProperty("dialogTitle")) + dialogTitle = qmlItemNode().modelNode().variantProperty("dialogTitle").value().toString(); + + if (!dialogTitle.isEmpty()) { + // Local painter is used to get the labels bounding rect by using drawText() + QPixmap pixmap(640, 480); + QPainter localPainter(&pixmap); + QFont font = localPainter.font(); + font.setPixelSize(labelFontSize / viewportTransform().m11()); + localPainter.setFont(font); + + int margin = blockAdjust * 0.5; + const QRectF adjustedRect = boundingRect.adjusted(margin, margin, -margin, -margin); + + QRectF textRect(0, 0, 100, 20); + + Qt::Corner corner = Qt::TopRightCorner; + if (qmlItemNode().modelNode().hasAuxiliaryData("dialogLabelPosition")) + corner = qmlItemNode().modelNode().auxiliaryData("dialogLabelPosition").value(); + + int flag = 0; + switch (corner) { + case Qt::TopLeftCorner: + flag = Qt::AlignRight; + textRect.moveBottomRight(adjustedRect.topLeft()); + break; + case Qt::TopRightCorner: + flag = Qt::AlignLeft; + textRect.moveBottomLeft(adjustedRect.topRight()); + break; + case Qt::BottomLeftCorner: + flag = Qt::AlignRight; + textRect.moveTopRight(adjustedRect.bottomLeft()); + break; + case Qt::BottomRightCorner: + flag = Qt::AlignLeft; + textRect.moveTopLeft(adjustedRect.bottomRight()); + break; + } + + localPainter.drawText(textRect, flag | Qt::TextDontClip, dialogTitle, &labelBoundingRect); + } + } + + // Unite the rotate item bounding rect with the label bounding rect. + boundingRect = transform.mapRect(boundingRect); + boundingRect = boundingRect.united(labelBoundingRect); + } + + m_selectionBoundingRect = boundingRect; m_paintedBoundingRect = m_selectionBoundingRect; m_boundingRect = m_paintedBoundingRect; setTransform(qmlItemNode().instanceTransformWithContentTransform()); @@ -1665,6 +1769,7 @@ void FormEditorFlowDecisionItem::paint(QPainter *painter, const QStyleOptionGrap if (qmlItemNode().modelNode().hasAuxiliaryData("color")) flowColor = qmlItemNode().modelNode().auxiliaryData("color").value(); + const qreal scaleFactor = viewportTransform().m11(); qreal width = 2; if (qmlItemNode().modelNode().hasAuxiliaryData("width")) @@ -1692,30 +1797,84 @@ void FormEditorFlowDecisionItem::paint(QPainter *painter, const QStyleOptionGrap painter->save(); - if (m_iconType == DecisionIcon) { - painter->translate(boundingRect().center()); - painter->rotate(45); - painter->translate(-boundingRect().center()); - } - if (fillColor.alpha() > 0) painter->setBrush(fillColor); int radius = blockRadius; + if (qmlItemNode().modelNode().hasAuxiliaryData("blockRadius")) + radius = qmlItemNode().modelNode().auxiliaryData("blockRadius").toInt(); - const QRectF adjustedRect = boundingRect().adjusted(blockAdjust, - blockAdjust, - -blockAdjust, - -blockAdjust); + int size = flowBlockSize; + if (qmlItemNode().modelNode().hasAuxiliaryData("blockSize")) + size = qmlItemNode().modelNode().auxiliaryData("blockSize").toInt(); + QRectF boundingRect(0, 0, size, size); + QTransform transform; + int margin = blockAdjust; + if (m_iconType == DecisionIcon) { + transform.translate(boundingRect.center().x(), boundingRect.center().y()); + transform.rotate(45); + transform.translate(-boundingRect.center().x(), -boundingRect.center().y()); + margin *= 0.5; + } + + const QRectF adjustedRect = boundingRect.adjusted(margin, margin, -margin, -margin); + + painter->setTransform(transform, true); painter->drawRoundedRect(adjustedRect, radius, radius); const int iconDecrement = 32; const int iconSize = adjustedRect.width() - iconDecrement; - const int offset = iconDecrement / 2 + blockAdjust; + const int offset = iconDecrement / 2 + margin; painter->restore(); + // Draw the dialog title inside the form view if requested. Decision item only. + int showDialogLabel = false; + if (qmlItemNode().modelNode().hasAuxiliaryData("showDialogLabel")) + showDialogLabel = qmlItemNode().modelNode().auxiliaryData("showDialogLabel").toBool(); + + if (showDialogLabel) { + QString dialogTitle; + if (qmlItemNode().modelNode().hasVariantProperty("dialogTitle")) + dialogTitle = qmlItemNode().modelNode().variantProperty("dialogTitle").value().toString(); + + if (!dialogTitle.isEmpty()) { + + QFont font = painter->font(); + font.setPixelSize(labelFontSize / scaleFactor); + painter->setFont(font); + + QRectF textRect(0, 0, 100, 20); + + Qt::Corner corner = Qt::TopRightCorner; + if (qmlItemNode().modelNode().hasAuxiliaryData("dialogLabelPosition")) + corner = qmlItemNode().modelNode().auxiliaryData("dialogLabelPosition").value(); + + int flag = 0; + switch (corner) { + case Qt::TopLeftCorner: + flag = Qt::AlignRight; + textRect.moveBottomRight(adjustedRect.topLeft()); + break; + case Qt::TopRightCorner: + flag = Qt::AlignLeft; + textRect.moveBottomLeft(adjustedRect.topRight()); + break; + case Qt::BottomLeftCorner: + flag = Qt::AlignRight; + textRect.moveTopRight(adjustedRect.bottomLeft()); + break; + case Qt::BottomRightCorner: + flag = Qt::AlignLeft; + textRect.moveTopLeft(adjustedRect.bottomRight()); + break; + } + + painter->drawText(textRect, flag | Qt::TextDontClip, dialogTitle); + } + } + const QString icon = (m_iconType == WildcardIcon) ? Theme::getIconUnicode(Theme::wildcard) : Theme::getIconUnicode(Theme::decisionNode); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index d43ba509144..c7c34329c4a 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -392,9 +392,9 @@ void FormEditorView::variantPropertiesChanged(const QList &prop Q_UNUSED(propertyChange) for (const VariantProperty &property : propertyList) { QmlVisualNode node(property.parentModelNode()); - if (node.isFlowTransition()) { + if (node.isFlowTransition() || node.isFlowDecision()) { if (FormEditorItem *item = m_scene->itemForQmlItemNode(node.toQmlItemNode())) { - if (property.name() == "question") + if (property.name() == "question" || property.name() == "dialogTitle") item->updateGeometry(); } } @@ -572,7 +572,8 @@ void FormEditorView::auxiliaryDataChanged(const ModelNode &node, const PropertyN // Update the geomtry if one of the following auxiliary properties has changed static const QStringList updateGeometryPropertyNames = { "breakPoint", "bezier", "transitionBezier", "type", "tranitionType", "radius", - "transitionRadius", "labelPosition", "labelFlipSide", "inOffset", "outOffset" + "transitionRadius", "labelPosition", "labelFlipSide", "inOffset", "outOffset", + "blockSize", "blockRadius", "showDialogLabel", "dialogLabelPosition" }; if (updateGeometryPropertyNames.contains(QString::fromUtf8(name))) editorItem->updateGeometry(); diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 678e5664eca..bf2243d09fc 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -188,6 +188,14 @@ QVariant properDefaultAuxiliaryProperties(const QmlObjectNode &qmlObjectNode, return QString(); else if (propertyName == "joinConnection") return false; + else if (propertyName == "blockSize") + return 200; + else if (propertyName == "blockRadius") + return 18; + else if (propertyName == "showDialogLabel") + return false; + else if (propertyName == "dialogLabelPosition") + return Qt::TopRightCorner; return {}; } @@ -259,9 +267,9 @@ void PropertyEditorQmlBackend::setupAuxiliaryProperties(const QmlObjectNode &qml } else if (itemNode.isFlowActionArea()) { propertyNames.append({"color", "width", "fillColor", "outOffset", "dash"}); } else if (itemNode.isFlowDecision()) { - propertyNames.append({"color", "width", "fillColor", "dash"}); + propertyNames.append({"color", "width", "fillColor", "dash", "blockSize", "blockRadius", "showDialogLabel", "dialogLabelPosition"}); } else if (itemNode.isFlowWildcard()) { - propertyNames.append({"color", "width", "fillColor", "dash"}); + propertyNames.append({"color", "width", "fillColor", "dash", "blockSize", "blockRadius"}); } else if (itemNode.isFlowView()) { propertyNames.append({"transitionColor", "areaColor", "areaFillColor", "blockColor", "transitionType", "transitionRadius", "transitionBezier"}); } diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index 3fd9c4b7af4..20f5c30d0e6 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -62,6 +62,7 @@ add_qtc_test(unittest GTEST gtest-creator-printing.cpp gtest-creator-printing.h gtest-llvm-printing.h gtest-qt-printing.cpp gtest-qt-printing.h + gtest-std-printing.h headerpathfilter-test.cpp highlightingresultreporter-test.cpp lineprefixer-test.cpp @@ -390,7 +391,7 @@ extend_qtc_test(unittest refactoringprojectupdater.cpp refactoringprojectupdater.h searchinterface.h searchhandle.cpp searchhandle.h - symbolsfindfilter.cpp symbolsfindfilter.h + clangsymbolsfindfilter.cpp clangsymbolsfindfilter.h symbolqueryinterface.h symbol.h projectpartproviderinterface.h diff --git a/tests/unit/unittest/creator_dependency.pri b/tests/unit/unittest/creator_dependency.pri index e5b10f65ae8..4aaac22a1bf 100644 --- a/tests/unit/unittest/creator_dependency.pri +++ b/tests/unit/unittest/creator_dependency.pri @@ -16,7 +16,7 @@ include($$PWD/../../../src/plugins/clangpchmanager/clangpchmanager-source.pri) include($$PWD/../../../src/plugins/cpptools/cpptoolsunittestfiles.pri) include($$PWD/../../../src/plugins/debugger/debuggerunittestfiles.pri) include($$PWD/../../../src/plugins/compilationdatabaseprojectmanager/compilationdatabaseunittestfiles.pri) -include(cplusplus.pri) +!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):include(cplusplus.pri) !isEmpty(LLVM_VERSION) { include($$PWD/../../../src/plugins/clangtools/clangtoolsunittestfiles.pri) include($$PWD/../../../src/shared/clang/clang_defines.pri) diff --git a/tests/unit/unittest/googletest.h b/tests/unit/unittest/googletest.h index 0b9bf2d2fa1..4c917a45b32 100644 --- a/tests/unit/unittest/googletest.h +++ b/tests/unit/unittest/googletest.h @@ -38,9 +38,10 @@ #include "compare-operators.h" #include "conditionally-disabled-tests.h" -#include "gtest-qt-printing.h" #include "gtest-creator-printing.h" #include "gtest-llvm-printing.h" +#include "gtest-qt-printing.h" +#include "gtest-std-printing.h" #ifdef CLANG_UNIT_TESTS # include "gtest-clang-printing.h" #endif diff --git a/tests/unit/unittest/gtest-clang-printing.cpp b/tests/unit/unittest/gtest-clang-printing.cpp index c7004d25c50..217114ab9ed 100644 --- a/tests/unit/unittest/gtest-clang-printing.cpp +++ b/tests/unit/unittest/gtest-clang-printing.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "gtest-creator-printing.h" +#include "gtest-std-printing.h" #ifdef CLANG_UNIT_TESTS #include diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 0f79e048b91..704c9c6b90a 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "gtest-creator-printing.h" +#include "gtest-std-printing.h" #include "gtest-qt-printing.h" @@ -320,6 +321,9 @@ std::ostream &operator<<(std::ostream &out, const Value &value) case Sqlite::ValueType::String: out << "\"" << value.toStringView() << "\""; break; + case Sqlite::ValueType::Null: + out << "null"; + break; } return out << ")"; diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index c791290ae2d..e0cb55315f4 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -350,24 +350,4 @@ std::ostream &operator<<(std::ostream &out, const Diagnostic &diag); } // namespace Internal } // namespace CppTools -namespace std { -template -ostream &operator<<(ostream &out, const vector &vector) -{ - out << "["; - - for (auto current = vector.begin(); current != vector.end(); ++current) { - out << *current; - - if (std::next(current) != vector.end()) - out << ", "; - } - - out << "]"; - - return out; -} - -} // namespace std - void setFilePathCache(ClangBackEnd::FilePathCaching *filePathCache); diff --git a/tests/unit/unittest/gtest-llvm-printing.cpp b/tests/unit/unittest/gtest-llvm-printing.cpp index 467f4a52613..f3b1befde7d 100644 --- a/tests/unit/unittest/gtest-llvm-printing.cpp +++ b/tests/unit/unittest/gtest-llvm-printing.cpp @@ -23,7 +23,8 @@ ** ****************************************************************************/ -#include "gtest-creator-printing.h" +#include "gtest-llvm-printing.h" +#include "gtest-std-printing.h" #include diff --git a/tests/unit/unittest/gtest-std-printing.h b/tests/unit/unittest/gtest-std-printing.h new file mode 100644 index 00000000000..874f8c41c62 --- /dev/null +++ b/tests/unit/unittest/gtest-std-printing.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +****************************************************************************/ + +#pragma once + +#include +#include + +namespace std { +template +ostream &operator<<(ostream &out, const vector &vector) +{ + out << "["; + + for (auto current = vector.begin(); current != vector.end(); ++current) { + out << *current; + + if (std::next(current) != vector.end()) + out << ", "; + } + + out << "]"; + + return out; +} + +} // namespace std diff --git a/tests/unit/unittest/lastchangedrowid-test.cpp b/tests/unit/unittest/lastchangedrowid-test.cpp index 07b29bee576..aee2d187e35 100644 --- a/tests/unit/unittest/lastchangedrowid-test.cpp +++ b/tests/unit/unittest/lastchangedrowid-test.cpp @@ -35,14 +35,14 @@ class LastChangedRowId : public testing::Test { protected: NiceMock mockSqliteDatabase; - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"}; }; TEST_F(LastChangedRowId, SetUpdateHookInContructor) { - EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_)); + EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"}; } TEST_F(LastChangedRowId, ResetUpdateHookInDestructor) @@ -57,42 +57,42 @@ TEST_F(LastChangedRowId, GetMinusOneAsRowIdIfNoCallbackWasCalled) TEST_F(LastChangedRowId, CallbackSetsLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowId, CallbackChecksDatabaseName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42); + lastRowId("temp", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowId, CallbackChecksTableName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42); + lastRowId("main", "bar", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowId, LastCallSetsRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); - lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33); + lastRowId("main", "foo", 42); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66); + lastRowId("main", "foo", 66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowId, TakeLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); auto id = lastRowId.takeLastRowId(); @@ -101,7 +101,7 @@ TEST_F(LastChangedRowId, TakeLastRowId) TEST_F(LastChangedRowId, TakeLastRowIdResetsRowIdToMinusOne) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); lastRowId.takeLastRowId(); auto id = lastRowId.takeLastRowId(); @@ -114,14 +114,14 @@ class LastChangedRowIdWithTwoTables : public testing::Test protected: NiceMock mockSqliteDatabase; - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo", "bar"}; + Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"}; }; TEST_F(LastChangedRowIdWithTwoTables, SetUpdateHookInContructor) { - EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_)); + EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"}; } TEST_F(LastChangedRowIdWithTwoTables, ResetUpdateHookInDestructor) @@ -136,48 +136,48 @@ TEST_F(LastChangedRowIdWithTwoTables, GetMinusOneAsRowIdIfNoCallbackWasCalled) TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdFirstTable) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdSecondTable) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 66); + lastRowId("main", "bar", 66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksDatabaseName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42); + lastRowId("temp", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksTableName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "main", "zoo", 42); + lastRowId("main", "zoo", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowIdWithTwoTables, LastCallSetsRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); - lastRowId.callback(Sqlite::ChangeType::Delete, "main", "bar", 66); + lastRowId("main", "bar", 66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); auto id = lastRowId.takeLastRowId(); @@ -186,7 +186,7 @@ TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId) TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowIdResetsRowIdToMinusOne) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); lastRowId.takeLastRowId(); auto id = lastRowId.takeLastRowId(); @@ -199,14 +199,14 @@ class LastChangedRowIdWithThreeTables : public testing::Test protected: NiceMock mockSqliteDatabase; - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"}; + Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"}; }; TEST_F(LastChangedRowIdWithThreeTables, SetUpdateHookInContructor) { - EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_)); + EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"}; } TEST_F(LastChangedRowIdWithThreeTables, ResetUpdateHookInDestructor) @@ -221,56 +221,56 @@ TEST_F(LastChangedRowIdWithThreeTables, GetMinusOneAsRowIdIfNoCallbackWasCalled) TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdFirstTable) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdSecondTable) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42); + lastRowId("main", "bar", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdThirdTable) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "too", 42); + lastRowId("main", "too", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksDatabaseName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42); + lastRowId("temp", "foo", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksTableName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", "foo", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "main", "zoo", 42); + lastRowId("main", "zoo", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } TEST_F(LastChangedRowIdWithThreeTables, LastCallSetsRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42); - lastRowId.callback(Sqlite::ChangeType::Insert, "main", "too", 33); + lastRowId("main", "bar", 42); + lastRowId("main", "too", 33); - lastRowId.callback(Sqlite::ChangeType::Delete, "main", "too", 66); + lastRowId("main", "too", 66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); auto id = lastRowId.takeLastRowId(); @@ -279,7 +279,7 @@ TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId) TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowIdResetsRowIdToMinusOne) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", "foo", 42); lastRowId.takeLastRowId(); auto id = lastRowId.takeLastRowId(); @@ -291,14 +291,14 @@ class LastChangedRowIdWithNoDatabaseAndTable : public testing::Test { protected: NiceMock mockSqliteDatabase; - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase}; + Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase}; }; TEST_F(LastChangedRowIdWithNoDatabaseAndTable, SetUpdateHookInContructor) { - EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_)); + EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase}; } TEST_F(LastChangedRowIdWithNoDatabaseAndTable, ResetUpdateHookInDestructor) @@ -313,42 +313,24 @@ TEST_F(LastChangedRowIdWithNoDatabaseAndTable, GetMinusOneAsRowIdIfNoCallbackWas TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackSetsLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); - - ASSERT_THAT(lastRowId.lastRowId, 42); -} - -TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackDoNotChecksDatabaseName) -{ - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); - - lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42); - - ASSERT_THAT(lastRowId.lastRowId, 42); -} - -TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackDoNotChecksTableName) -{ - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); - - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42); + lastRowId(42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithNoDatabaseAndTable, LastCallSetsRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); - lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33); + lastRowId(42); + lastRowId(33); - lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66); + lastRowId(66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId(42); auto id = lastRowId.takeLastRowId(); @@ -357,7 +339,7 @@ TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId) TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowIdResetsRowIdToMinusOne) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId(42); lastRowId.takeLastRowId(); auto id = lastRowId.takeLastRowId(); @@ -369,14 +351,14 @@ class LastChangedRowIdWithNoTable : public testing::Test { protected: NiceMock mockSqliteDatabase; - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main"}; + Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"}; }; TEST_F(LastChangedRowIdWithNoTable, SetUpdateHookInContructor) { - EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_)); + EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); - Sqlite::LastChangedRowId lastRowId{mockSqliteDatabase, "main", "foo"}; + Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"}; } TEST_F(LastChangedRowIdWithNoTable, ResetUpdateHookInDestructor) @@ -391,42 +373,33 @@ TEST_F(LastChangedRowIdWithNoTable, GetMinusOneAsRowIdIfNoCallbackWasCalled) TEST_F(LastChangedRowIdWithNoTable, CallbackSetsLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", 42); ASSERT_THAT(lastRowId.lastRowId, 42); } TEST_F(LastChangedRowIdWithNoTable, CallbackChecksDatabaseName) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); + lastRowId("main", 33); - lastRowId.callback(Sqlite::ChangeType::Update, "temp", "foo", 42); + lastRowId("temp", 42); ASSERT_THAT(lastRowId.lastRowId, 33); } -TEST_F(LastChangedRowIdWithNoTable, CallbackDoNotChecksTableName) -{ - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 33); - - lastRowId.callback(Sqlite::ChangeType::Update, "main", "bar", 42); - - ASSERT_THAT(lastRowId.lastRowId, 42); -} - TEST_F(LastChangedRowIdWithNoTable, LastCallSetsRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); - lastRowId.callback(Sqlite::ChangeType::Insert, "main", "foo", 33); + lastRowId("main", 42); + lastRowId("main", 33); - lastRowId.callback(Sqlite::ChangeType::Delete, "main", "foo", 66); + lastRowId("main", 66); ASSERT_THAT(lastRowId.lastRowId, 66); } TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", 42); auto id = lastRowId.takeLastRowId(); @@ -435,7 +408,7 @@ TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId) TEST_F(LastChangedRowIdWithNoTable, TakeLastRowIdResetsRowIdToMinusOne) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 42); + lastRowId("main", 42); lastRowId.takeLastRowId(); auto id = lastRowId.takeLastRowId(); @@ -452,7 +425,7 @@ TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsNotValidForNegativeValues) TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 0); + lastRowId("main", 0); auto isValid = lastRowId.lastRowIdIsValid(); @@ -461,7 +434,7 @@ TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull) TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForPositiveValues) { - lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 777); + lastRowId("main", 777); auto isValid = lastRowId.lastRowIdIsValid(); diff --git a/tests/unit/unittest/mocksqlitedatabase.h b/tests/unit/unittest/mocksqlitedatabase.h index c627f995a4a..7a4a8b9e75e 100644 --- a/tests/unit/unittest/mocksqlitedatabase.h +++ b/tests/unit/unittest/mocksqlitedatabase.h @@ -60,7 +60,9 @@ public: MOCK_METHOD0(walCheckpointFull, void()); - MOCK_METHOD1(setUpdateHook, void(Sqlite::DatabaseInterface::UpdateCallback &)); + MOCK_METHOD2(setUpdateHook, + void(void *object, + void (*)(void *object, int, char const *database, char const *, long long rowId))); MOCK_METHOD0(resetUpdateHook, void()); diff --git a/tests/unit/unittest/sqlitedatabase-test.cpp b/tests/unit/unittest/sqlitedatabase-test.cpp index 5d7fdb1e540..a93100c3e04 100644 --- a/tests/unit/unittest/sqlitedatabase-test.cpp +++ b/tests/unit/unittest/sqlitedatabase-test.cpp @@ -39,6 +39,8 @@ #include #include +#include + namespace { using testing::Contains; @@ -74,13 +76,23 @@ protected: return Sqlite::ReadStatement("SELECT name FROM test", database).values(8); } + static void updateHookCallback( + void *object, int type, char const *database, char const *table, long long rowId) + { + static_cast(object)->callback(static_cast(type), + database, + table, + rowId); + } + protected: SpyDummy spyDummy; QString databaseFilePath{":memory:"}; mutable Sqlite::Database database; Sqlite::TransactionInterface &transactionInterface = database; MockFunction callbackMock; - Sqlite::Database::UpdateCallback callback = callbackMock.AsStdFunction(); + std::function + callback = callbackMock.AsStdFunction(); }; TEST_F(SqliteDatabase, SetDatabaseFilePath) @@ -232,7 +244,7 @@ TEST_F(SqliteDatabase, Rollback) TEST_F(SqliteDatabase, SetUpdateHookSet) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(_, _, _, _)); Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42); @@ -240,10 +252,9 @@ TEST_F(SqliteDatabase, SetUpdateHookSet) TEST_F(SqliteDatabase, SetNullUpdateHook) { - database.setUpdateHook(callback); - Sqlite::Database::UpdateCallback newCallback; + database.setUpdateHook(this, updateHookCallback); - database.setUpdateHook(newCallback); + database.setUpdateHook(nullptr, nullptr); EXPECT_CALL(callbackMock, Call(_, _, _, _)).Times(0); Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42); @@ -251,8 +262,7 @@ TEST_F(SqliteDatabase, SetNullUpdateHook) TEST_F(SqliteDatabase, ResetUpdateHook) { - database.setUpdateHook(callback); - Sqlite::Database::UpdateCallback newCallback; + database.setUpdateHook(this, updateHookCallback); database.resetUpdateHook(); @@ -263,7 +273,7 @@ TEST_F(SqliteDatabase, ResetUpdateHook) TEST_F(SqliteDatabase, DeleteUpdateHookCall) { Sqlite::WriteStatement("INSERT INTO test(name) VALUES (?)", database).write(42); - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Delete), _, _, _)); @@ -272,7 +282,7 @@ TEST_F(SqliteDatabase, DeleteUpdateHookCall) TEST_F(SqliteDatabase, InsertUpdateHookCall) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _)); @@ -281,7 +291,7 @@ TEST_F(SqliteDatabase, InsertUpdateHookCall) TEST_F(SqliteDatabase, UpdateUpdateHookCall) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(Eq(Sqlite::ChangeType::Insert), _, _, _)); @@ -290,7 +300,7 @@ TEST_F(SqliteDatabase, UpdateUpdateHookCall) TEST_F(SqliteDatabase, RowIdUpdateHookCall) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(_, _, _, Eq(42))); @@ -299,7 +309,7 @@ TEST_F(SqliteDatabase, RowIdUpdateHookCall) TEST_F(SqliteDatabase, DatabaseUpdateHookCall) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(_, StrEq("main"), _, _)); @@ -308,7 +318,7 @@ TEST_F(SqliteDatabase, DatabaseUpdateHookCall) TEST_F(SqliteDatabase, TableUpdateHookCall) { - database.setUpdateHook(callback); + database.setUpdateHook(this, updateHookCallback); EXPECT_CALL(callbackMock, Call(_, _, StrEq("test"), _)); diff --git a/tests/unit/unittest/sqlitestatement-test.cpp b/tests/unit/unittest/sqlitestatement-test.cpp index a7dd5d5f9ba..cc264bf90f5 100644 --- a/tests/unit/unittest/sqlitestatement-test.cpp +++ b/tests/unit/unittest/sqlitestatement-test.cpp @@ -388,6 +388,7 @@ TEST_F(SqliteStatement, WritePointerValues) TEST_F(SqliteStatement, WriteNullValues) { WriteStatement statement("UPDATE test SET name=?, number=? WHERE rowid=?", database); + statement.write(1, 1, 1); statement.write(Sqlite::NullValue{}, Sqlite::Value{}, 1); diff --git a/tests/unit/unittest/symbolsfindfilter-test.cpp b/tests/unit/unittest/symbolsfindfilter-test.cpp index fad174dfceb..38e43b717e9 100644 --- a/tests/unit/unittest/symbolsfindfilter-test.cpp +++ b/tests/unit/unittest/symbolsfindfilter-test.cpp @@ -25,7 +25,7 @@ #include "googletest.h" -#include +#include namespace { diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 03f04f39824..e9a96ace5f0 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -1,9 +1,11 @@ INCLUDEPATH += ../mockup QT += core network testlib widgets -CONFIG += console c++14 testcase object_parallel_to_source +CONFIG += console c++14 testcase CONFIG -= app_bundle shared +QTC_UNITTEST_BUILD_CPP_PARSER = $$(QTC_UNITTEST_BUILD_CPP_PARSER) + include(gmock_dependency.pri) include(clang_dependency.pri) include(creator_dependency.pri) @@ -11,8 +13,6 @@ include(benchmark_dependency.pri) requires(isEmpty(QTC_CLANG_BUILDMODE_MISMATCH)) -OBJECTS_DIR = $$OUT_PWD/obj # workaround for qmake bug in object_parallel_to_source - !msvc:force_debug_info:QMAKE_CXXFLAGS += -fno-omit-frame-pointer DEFINES += \ @@ -66,7 +66,6 @@ SOURCES += \ lastchangedrowid-test.cpp \ lineprefixer-test.cpp \ locatorfilter-test.cpp \ - matchingtext-test.cpp \ mimedatabase-utilities.cpp \ pchmanagerclientserverinprocess-test.cpp \ pchmanagerclient-test.cpp \ @@ -133,6 +132,8 @@ SOURCES += \ sqlstatementbuilder-test.cpp \ createtablesqlstatementbuilder-test.cpp +!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):matchingtext-test.cpp + !isEmpty(LIBCLANG_LIBS) { SOURCES += \ activationsequencecontextprocessor-test.cpp \ @@ -229,6 +230,7 @@ HEADERS += \ gtest-creator-printing.h \ gtest-llvm-printing.h \ gtest-qt-printing.h \ + gtest-std-printing.h \ mimedatabase-utilities.h \ mockclangcodemodelclient.h \ mockclangcodemodelserver.h \