diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-04-09 13:06:22 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-04-09 13:06:22 +0200 |
commit | da9b8b60848afad84e4a9a8452480a88ab948bb8 (patch) | |
tree | 6b6915403524c70957671430e04d8c587384302d | |
parent | 5500aca86669ec9a6f4440fe0438850297451c90 (diff) | |
parent | c96755ea7eede1f1881e00718fc03c3f5f693c33 (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Ifa1d05c3f578d04db599c68ec96ef343e293fd51
19 files changed, 332 insertions, 220 deletions
diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp index 5935295e6..bf0eb9e91 100644 --- a/src/assistant/help/qhelpcollectionhandler.cpp +++ b/src/assistant/help/qhelpcollectionhandler.cpp @@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE QHelpCollectionHandler::QHelpCollectionHandler(const QString &collectionFile, QObject *parent) : QObject(parent) - , m_dbOpened(false) , m_collectionFile(collectionFile) { const QFileInfo fi(m_collectionFile); @@ -63,20 +62,29 @@ QHelpCollectionHandler::QHelpCollectionHandler(const QString &collectionFile, QO QHelpCollectionHandler::~QHelpCollectionHandler() { - m_query.clear(); - if (m_dbOpened) - QSqlDatabase::removeDatabase(m_connectionName); + closeDB(); } bool QHelpCollectionHandler::isDBOpened() { - if (m_dbOpened) + if (m_query) return true; emit error(tr("The collection file \"%1\" is not set up yet."). arg(m_collectionFile)); return false; } +void QHelpCollectionHandler::closeDB() +{ + if (!m_query) + return; + + delete m_query; + m_query = nullptr; + QSqlDatabase::removeDatabase(m_connectionName); + m_connectionName = QString(); +} + QString QHelpCollectionHandler::collectionFile() const { return m_collectionFile; @@ -84,12 +92,11 @@ QString QHelpCollectionHandler::collectionFile() const bool QHelpCollectionHandler::openCollectionFile() { - if (m_dbOpened) - return m_dbOpened; + if (m_query) + return true; m_connectionName = QHelpGlobal::uniquifyConnectionName( QLatin1String("QHelpCollectionHandler"), this); - bool openingOk = true; { QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), m_connectionName); @@ -100,36 +107,36 @@ bool QHelpCollectionHandler::openCollectionFile() } db.setDatabaseName(collectionFile()); - openingOk = db.open(); - if (openingOk) - m_query = QSqlQuery(db); - } - if (!openingOk) { - QSqlDatabase::removeDatabase(m_connectionName); - emit error(tr("Cannot open collection file: %1").arg(collectionFile())); - return false; + if (db.open()) + m_query = new QSqlQuery(db); + + if (!m_query) { + QSqlDatabase::removeDatabase(m_connectionName); + emit error(tr("Cannot open collection file: %1").arg(collectionFile())); + return false; + } } - m_query.exec(QLatin1String("PRAGMA synchronous=OFF")); - m_query.exec(QLatin1String("PRAGMA cache_size=3000")); + m_query->exec(QLatin1String("PRAGMA synchronous=OFF")); + m_query->exec(QLatin1String("PRAGMA cache_size=3000")); - m_query.exec(QLatin1String("SELECT COUNT(*) FROM sqlite_master WHERE TYPE=\'table\'" - "AND Name=\'NamespaceTable\'")); - m_query.next(); - if (m_query.value(0).toInt() < 1) { - if (!createTables(&m_query)) { + m_query->exec(QLatin1String("SELECT COUNT(*) FROM sqlite_master WHERE TYPE=\'table\' " + "AND Name=\'NamespaceTable\'")); + m_query->next(); + if (m_query->value(0).toInt() < 1) { + if (!createTables(m_query)) { + closeDB(); emit error(tr("Cannot create tables in file %1.").arg(collectionFile())); return false; } } - m_dbOpened = true; - return m_dbOpened; + return true; } bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) { - if (!m_dbOpened) + if (!m_query) return false; const QFileInfo fi(fileName); @@ -172,54 +179,54 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) const QString &oldBaseDir = QFileInfo(collectionFile()).absolutePath(); const QFileInfo newColFi(colFile); - m_query.exec(QLatin1String("SELECT Name, FilePath FROM NamespaceTable")); - while (m_query.next()) { + m_query->exec(QLatin1String("SELECT Name, FilePath FROM NamespaceTable")); + while (m_query->next()) { copyQuery->prepare(QLatin1String("INSERT INTO NamespaceTable VALUES(NULL, ?, ?)")); - copyQuery->bindValue(0, m_query.value(0).toString()); - QString oldFilePath = m_query.value(1).toString(); + copyQuery->bindValue(0, m_query->value(0).toString()); + QString oldFilePath = m_query->value(1).toString(); if (!QDir::isAbsolutePath(oldFilePath)) oldFilePath = oldBaseDir + QDir::separator() + oldFilePath; copyQuery->bindValue(1, newColFi.absoluteDir().relativeFilePath(oldFilePath)); copyQuery->exec(); } - m_query.exec(QLatin1String("SELECT NamespaceId, Name FROM FolderTable")); - while (m_query.next()) { + m_query->exec(QLatin1String("SELECT NamespaceId, Name FROM FolderTable")); + while (m_query->next()) { copyQuery->prepare(QLatin1String("INSERT INTO FolderTable VALUES(NULL, ?, ?)")); - copyQuery->bindValue(0, m_query.value(0).toString()); - copyQuery->bindValue(1, m_query.value(1).toString()); + copyQuery->bindValue(0, m_query->value(0).toString()); + copyQuery->bindValue(1, m_query->value(1).toString()); copyQuery->exec(); } - m_query.exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); - while (m_query.next()) { + m_query->exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); + while (m_query->next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); - copyQuery->bindValue(0, m_query.value(0).toString()); + copyQuery->bindValue(0, m_query->value(0).toString()); copyQuery->exec(); } - m_query.exec(QLatin1String("SELECT Name FROM FilterNameTable")); - while (m_query.next()) { + m_query->exec(QLatin1String("SELECT Name FROM FilterNameTable")); + while (m_query->next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterNameTable VALUES(NULL, ?)")); - copyQuery->bindValue(0, m_query.value(0).toString()); + copyQuery->bindValue(0, m_query->value(0).toString()); copyQuery->exec(); } - m_query.exec(QLatin1String("SELECT NameId, FilterAttributeId FROM FilterTable")); - while (m_query.next()) { + m_query->exec(QLatin1String("SELECT NameId, FilterAttributeId FROM FilterTable")); + while (m_query->next()) { copyQuery->prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)")); - copyQuery->bindValue(0, m_query.value(0).toInt()); - copyQuery->bindValue(1, m_query.value(1).toInt()); + copyQuery->bindValue(0, m_query->value(0).toInt()); + copyQuery->bindValue(1, m_query->value(1).toInt()); copyQuery->exec(); } - m_query.exec(QLatin1String("SELECT Key, Value FROM SettingsTable")); - while (m_query.next()) { - if (m_query.value(0).toString() == QLatin1String("FTS5IndexedNamespaces")) + m_query->exec(QLatin1String("SELECT Key, Value FROM SettingsTable")); + while (m_query->next()) { + if (m_query->value(0).toString() == QLatin1String("FTS5IndexedNamespaces")) continue; copyQuery->prepare(QLatin1String("INSERT INTO SettingsTable VALUES(?, ?)")); - copyQuery->bindValue(0, m_query.value(0).toString()); - copyQuery->bindValue(1, m_query.value(1)); + copyQuery->bindValue(0, m_query->value(0).toString()); + copyQuery->bindValue(1, m_query->value(1)); copyQuery->exec(); } @@ -263,10 +270,10 @@ bool QHelpCollectionHandler::createTables(QSqlQuery *query) QStringList QHelpCollectionHandler::customFilters() const { QStringList list; - if (m_dbOpened) { - m_query.exec(QLatin1String("SELECT Name FROM FilterNameTable")); - while (m_query.next()) - list.append(m_query.value(0).toString()); + if (m_query) { + m_query->exec(QLatin1String("SELECT Name FROM FilterNameTable")); + while (m_query->next()) + list.append(m_query->value(0).toString()); } return list; } @@ -277,24 +284,24 @@ bool QHelpCollectionHandler::removeCustomFilter(const QString &filterName) return false; int filterNameId = -1; - m_query.prepare(QLatin1String("SELECT Id FROM FilterNameTable WHERE Name=?")); - m_query.bindValue(0, filterName); - m_query.exec(); - if (m_query.next()) - filterNameId = m_query.value(0).toInt(); + m_query->prepare(QLatin1String("SELECT Id FROM FilterNameTable WHERE Name=?")); + m_query->bindValue(0, filterName); + m_query->exec(); + if (m_query->next()) + filterNameId = m_query->value(0).toInt(); if (filterNameId < 0) { emit error(tr("Unknown filter \"%1\".").arg(filterName)); return false; } - m_query.prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?")); - m_query.bindValue(0, filterNameId); - m_query.exec(); + m_query->prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?")); + m_query->bindValue(0, filterNameId); + m_query->exec(); - m_query.prepare(QLatin1String("DELETE FROM FilterNameTable WHERE Id=?")); - m_query.bindValue(0, filterNameId); - m_query.exec(); + m_query->prepare(QLatin1String("DELETE FROM FilterNameTable WHERE Id=?")); + m_query->bindValue(0, filterNameId); + m_query->exec(); return true; } @@ -306,34 +313,34 @@ bool QHelpCollectionHandler::addCustomFilter(const QString &filterName, return false; int nameId = -1; - m_query.prepare(QLatin1String("SELECT Id FROM FilterNameTable WHERE Name=?")); - m_query.bindValue(0, filterName); - m_query.exec(); - if (m_query.next()) - nameId = m_query.value(0).toInt(); + m_query->prepare(QLatin1String("SELECT Id FROM FilterNameTable WHERE Name=?")); + m_query->bindValue(0, filterName); + m_query->exec(); + if (m_query->next()) + nameId = m_query->value(0).toInt(); - m_query.exec(QLatin1String("SELECT Id, Name FROM FilterAttributeTable")); + m_query->exec(QLatin1String("SELECT Id, Name FROM FilterAttributeTable")); QStringList idsToInsert = attributes; QMap<QString, int> attributeMap; - while (m_query.next()) { - attributeMap.insert(m_query.value(1).toString(), - m_query.value(0).toInt()); - if (idsToInsert.contains(m_query.value(1).toString())) - idsToInsert.removeAll(m_query.value(1).toString()); + while (m_query->next()) { + attributeMap.insert(m_query->value(1).toString(), + m_query->value(0).toInt()); + if (idsToInsert.contains(m_query->value(1).toString())) + idsToInsert.removeAll(m_query->value(1).toString()); } for (const QString &id : qAsConst(idsToInsert)) { - m_query.prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); - m_query.bindValue(0, id); - m_query.exec(); - attributeMap.insert(id, m_query.lastInsertId().toInt()); + m_query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); + m_query->bindValue(0, id); + m_query->exec(); + attributeMap.insert(id, m_query->lastInsertId().toInt()); } if (nameId < 0) { - m_query.prepare(QLatin1String("INSERT INTO FilterNameTable VALUES(NULL, ?)")); - m_query.bindValue(0, filterName); - if (m_query.exec()) - nameId = m_query.lastInsertId().toInt(); + m_query->prepare(QLatin1String("INSERT INTO FilterNameTable VALUES(NULL, ?)")); + m_query->bindValue(0, filterName); + if (m_query->exec()) + nameId = m_query->lastInsertId().toInt(); } if (nameId < 0) { @@ -341,15 +348,15 @@ bool QHelpCollectionHandler::addCustomFilter(const QString &filterName, return false; } - m_query.prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?")); - m_query.bindValue(0, nameId); - m_query.exec(); + m_query->prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?")); + m_query->bindValue(0, nameId); + m_query->exec(); for (const QString &att : attributes) { - m_query.prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)")); - m_query.bindValue(0, nameId); - m_query.bindValue(1, attributeMap[att]); - if (!m_query.exec()) + m_query->prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)")); + m_query->bindValue(0, nameId); + m_query->bindValue(1, attributeMap[att]); + if (!m_query->exec()) return false; } return true; @@ -359,26 +366,31 @@ QHelpCollectionHandler::DocInfoList QHelpCollectionHandler::registeredDocumentat const QString &namespaceName) const { DocInfoList list; - if (m_dbOpened) { - static const QLatin1String baseQuery("SELECT a.Name, a.FilePath, b.Name " - "FROM NamespaceTable a, FolderTable b " - "WHERE a.Id=b.NamespaceId"); - if (namespaceName.isEmpty()) { - m_query.prepare(baseQuery); - } else { - m_query.prepare(baseQuery + QLatin1String(" AND a.Name=? LIMIT 1")); - m_query.bindValue(0, namespaceName); - } - m_query.exec(); - - while (m_query.next()) { - DocInfo info; - info.fileName = m_query.value(1).toString(); - info.folderName = m_query.value(2).toString(); - info.namespaceName = m_query.value(0).toString(); - list.append(info); - } + + if (!m_query) + return list; + + static const QLatin1String baseQuery("SELECT a.Name, a.FilePath, b.Name " + "FROM NamespaceTable a, FolderTable b " + "WHERE a.Id=b.NamespaceId"); + + if (namespaceName.isEmpty()) { + m_query->prepare(baseQuery); + } else { + m_query->prepare(baseQuery + QLatin1String(" AND a.Name=? LIMIT 1")); + m_query->bindValue(0, namespaceName); + } + + m_query->exec(); + + while (m_query->next()) { + DocInfo info; + info.namespaceName = m_query->value(0).toString(); + info.fileName = m_query->value(1).toString(); + info.folderName = m_query->value(2).toString(); + list.append(info); } + return list; } @@ -421,24 +433,28 @@ bool QHelpCollectionHandler::unregisterDocumentation(const QString &namespaceNam if (!isDBOpened()) return false; - m_query.prepare(QLatin1String("SELECT Id FROM NamespaceTable WHERE Name=?")); - m_query.bindValue(0, namespaceName); - m_query.exec(); + m_query->prepare(QLatin1String("SELECT Id FROM NamespaceTable WHERE Name = ?")); + m_query->bindValue(0, namespaceName); + m_query->exec(); - if (!m_query.next()) { + if (!m_query->next()) { emit error(tr("The namespace %1 was not registered.").arg(namespaceName)); return false; } - const int nsId = m_query.value(0).toInt(); + const int nsId = m_query->value(0).toInt(); + + m_query->prepare(QLatin1String("DELETE FROM NamespaceTable WHERE Id = ?")); + m_query->bindValue(0, nsId); + if (!m_query->exec()) + return false; - m_query.prepare(QLatin1String("DELETE FROM NamespaceTable WHERE Id=?")); - m_query.bindValue(0, nsId); - m_query.exec(); + m_query->prepare(QLatin1String("DELETE FROM FolderTable WHERE NamespaceId = ?")); + m_query->bindValue(0, nsId); + if (!m_query->exec()) + return false; - m_query.prepare(QLatin1String("DELETE FROM FolderTable WHERE NamespaceId=?")); - m_query.bindValue(0, nsId); - return m_query.exec(); + return true; } bool QHelpCollectionHandler::removeCustomValue(const QString &key) @@ -446,30 +462,30 @@ bool QHelpCollectionHandler::removeCustomValue(const QString &key) if (!isDBOpened()) return false; - m_query.prepare(QLatin1String("DELETE FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - return m_query.exec(); + m_query->prepare(QLatin1String("DELETE FROM SettingsTable WHERE Key=?")); + m_query->bindValue(0, key); + return m_query->exec(); } QVariant QHelpCollectionHandler::customValue(const QString &key, const QVariant &defaultValue) const { - if (!m_dbOpened) + if (!m_query) return defaultValue; - m_query.prepare(QLatin1String("SELECT COUNT(Key) FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - if (!m_query.exec() || !m_query.next() || !m_query.value(0).toInt()) { - m_query.clear(); + m_query->prepare(QLatin1String("SELECT COUNT(Key) FROM SettingsTable WHERE Key=?")); + m_query->bindValue(0, key); + if (!m_query->exec() || !m_query->next() || !m_query->value(0).toInt()) { + m_query->clear(); return defaultValue; } - m_query.clear(); - m_query.prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - if (m_query.exec() && m_query.next()) { - const QVariant &value = m_query.value(0); - m_query.clear(); + m_query->clear(); + m_query->prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); + m_query->bindValue(0, key); + if (m_query->exec() && m_query->next()) { + const QVariant &value = m_query->value(0); + m_query->clear(); return value; } @@ -482,19 +498,19 @@ bool QHelpCollectionHandler::setCustomValue(const QString &key, if (!isDBOpened()) return false; - m_query.prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - m_query.exec(); - if (m_query.next()) { - m_query.prepare(QLatin1String("UPDATE SettingsTable SET Value=? where Key=?")); - m_query.bindValue(0, value); - m_query.bindValue(1, key); + m_query->prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); + m_query->bindValue(0, key); + m_query->exec(); + if (m_query->next()) { + m_query->prepare(QLatin1String("UPDATE SettingsTable SET Value=? where Key=?")); + m_query->bindValue(0, value); + m_query->bindValue(1, key); } else { - m_query.prepare(QLatin1String("INSERT INTO SettingsTable VALUES(?, ?)")); - m_query.bindValue(0, key); - m_query.bindValue(1, value); + m_query->prepare(QLatin1String("INSERT INTO SettingsTable VALUES(?, ?)")); + m_query->bindValue(0, key); + m_query->bindValue(1, value); } - return m_query.exec(); + return m_query->exec(); } bool QHelpCollectionHandler::addFilterAttributes(const QStringList &attributes) @@ -502,16 +518,16 @@ bool QHelpCollectionHandler::addFilterAttributes(const QStringList &attributes) if (!isDBOpened()) return false; - m_query.exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); + m_query->exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); QSet<QString> atts; - while (m_query.next()) - atts.insert(m_query.value(0).toString()); + while (m_query->next()) + atts.insert(m_query->value(0).toString()); for (const QString &s : attributes) { if (!atts.contains(s)) { - m_query.prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); - m_query.bindValue(0, s); - m_query.exec(); + m_query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)")); + m_query->bindValue(0, s); + m_query->exec(); } } return true; @@ -520,10 +536,10 @@ bool QHelpCollectionHandler::addFilterAttributes(const QStringList &attributes) QStringList QHelpCollectionHandler::filterAttributes() const { QStringList list; - if (m_dbOpened) { - m_query.exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); - while (m_query.next()) - list.append(m_query.value(0).toString()); + if (m_query) { + m_query->exec(QLatin1String("SELECT Name FROM FilterAttributeTable")); + while (m_query->next()) + list.append(m_query->value(0).toString()); } return list; } @@ -531,50 +547,57 @@ QStringList QHelpCollectionHandler::filterAttributes() const QStringList QHelpCollectionHandler::filterAttributes(const QString &filterName) const { QStringList list; - if (m_dbOpened) { - m_query.prepare(QLatin1String("SELECT a.Name FROM FilterAttributeTable a, " + if (m_query) { + m_query->prepare(QLatin1String("SELECT a.Name FROM FilterAttributeTable a, " "FilterTable b, FilterNameTable c WHERE a.Id=b.FilterAttributeId " "AND b.NameId=c.Id AND c.Name=?")); - m_query.bindValue(0, filterName); - m_query.exec(); - while (m_query.next()) - list.append(m_query.value(0).toString()); + m_query->bindValue(0, filterName); + m_query->exec(); + while (m_query->next()) + list.append(m_query->value(0).toString()); } return list; } int QHelpCollectionHandler::registerNamespace(const QString &nspace, const QString &fileName) { - m_query.prepare(QLatin1String("SELECT COUNT(Id) FROM NamespaceTable WHERE Name=?")); - m_query.bindValue(0, nspace); - m_query.exec(); - while (m_query.next()) { - if (m_query.value(0).toInt() > 0) { + const int errorValue = -1; + if (!m_query) + return errorValue; + + m_query->prepare(QLatin1String("SELECT COUNT(Id) FROM NamespaceTable WHERE Name=?")); + m_query->bindValue(0, nspace); + m_query->exec(); + while (m_query->next()) { + if (m_query->value(0).toInt() > 0) { emit error(tr("Namespace %1 already exists.").arg(nspace)); - return -1; + return errorValue; } } QFileInfo fi(m_collectionFile); - m_query.prepare(QLatin1String("INSERT INTO NamespaceTable VALUES(NULL, ?, ?)")); - m_query.bindValue(0, nspace); - m_query.bindValue(1, fi.absoluteDir().relativeFilePath(fileName)); - int namespaceId = -1; - if (m_query.exec()) - namespaceId = m_query.lastInsertId().toInt(); + m_query->prepare(QLatin1String("INSERT INTO NamespaceTable VALUES(NULL, ?, ?)")); + m_query->bindValue(0, nspace); + m_query->bindValue(1, fi.absoluteDir().relativeFilePath(fileName)); + int namespaceId = errorValue; + if (m_query->exec()) + namespaceId = m_query->lastInsertId().toInt(); if (namespaceId < 1) { emit error(tr("Cannot register namespace \"%1\".").arg(nspace)); - return -1; + return errorValue; } return namespaceId; } bool QHelpCollectionHandler::registerVirtualFolder(const QString &folderName, int namespaceId) { - m_query.prepare(QLatin1String("INSERT INTO FolderTable VALUES(NULL, ?, ?)")); - m_query.bindValue(0, namespaceId); - m_query.bindValue(1, folderName); - return m_query.exec(); + if (!m_query) + return false; + + m_query->prepare(QLatin1String("INSERT INTO FolderTable VALUES(NULL, ?, ?)")); + m_query->bindValue(0, namespaceId); + m_query->bindValue(1, folderName); + return m_query->exec(); } void QHelpCollectionHandler::optimizeDatabase(const QString &fileName) diff --git a/src/assistant/help/qhelpcollectionhandler_p.h b/src/assistant/help/qhelpcollectionhandler_p.h index 2b1b57718..d804b3f04 100644 --- a/src/assistant/help/qhelpcollectionhandler_p.h +++ b/src/assistant/help/qhelpcollectionhandler_p.h @@ -109,12 +109,12 @@ signals: private: bool isDBOpened(); + void closeDB(); bool createTables(QSqlQuery *query); - bool m_dbOpened; QString m_collectionFile; QString m_connectionName; - mutable QSqlQuery m_query; + QSqlQuery *m_query = nullptr; }; QT_END_NAMESPACE diff --git a/src/designer/src/components/formeditor/qdesigner_resource.cpp b/src/designer/src/components/formeditor/qdesigner_resource.cpp index bd6a3aa52..b799e648c 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.cpp +++ b/src/designer/src/components/formeditor/qdesigner_resource.cpp @@ -507,7 +507,8 @@ void QDesignerResource::saveDom(DomUI *ui, QWidget *widget) ui->setElementExportMacro(exportMacro); } - ui->setAttributeIdbasedtr(m_formWindow->useIdBasedTranslations()); + if (m_formWindow->useIdBasedTranslations()) + ui->setAttributeIdbasedtr(true); const QVariantMap designerFormData = m_formWindow->formData(); if (!designerFormData.empty()) { diff --git a/src/qdbus/qdbusviewer/logviewer.cpp b/src/qdbus/qdbusviewer/logviewer.cpp index 190d41112..7dd1ba6d6 100644 --- a/src/qdbus/qdbusviewer/logviewer.cpp +++ b/src/qdbus/qdbusviewer/logviewer.cpp @@ -40,7 +40,7 @@ void LogViewer::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = createStandardContextMenu(); QAction *action = menu->addAction(tr("Clear")); - connect(action, SIGNAL(triggered()), this, SLOT(clear())); + connect(action, &QAction::triggered, this, &QTextEdit::clear); menu->exec(event->globalPos()); delete menu; } diff --git a/src/qdbus/qdbusviewer/mainwindow.cpp b/src/qdbus/qdbusviewer/mainwindow.cpp index 4f4484581..f1935d605 100644 --- a/src/qdbus/qdbusviewer/mainwindow.cpp +++ b/src/qdbus/qdbusviewer/mainwindow.cpp @@ -44,18 +44,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - QAction *quitAction = fileMenu->addAction(tr("&Quit"), this, SLOT(close())); + QAction *quitAction = fileMenu->addAction(tr("&Quit"), this, &QWidget::close); quitAction->setShortcut(QKeySequence::Quit); quitAction->setMenuRole(QAction::QuitRole); QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); QAction *aboutAction = helpMenu->addAction(tr("&About")); aboutAction->setMenuRole(QAction::AboutRole); - QObject::connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + QObject::connect(aboutAction, &QAction::triggered, this, &MainWindow::about); QAction *aboutQtAction = helpMenu->addAction(tr("About &Qt")); aboutQtAction->setMenuRole(QAction::AboutQtRole); - QObject::connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + QObject::connect(aboutQtAction, &QAction::triggered, qApp, &QApplication::aboutQt); tabWidget = new QTabWidget; setCentralWidget(tabWidget); diff --git a/src/qdbus/qdbusviewer/propertydialog.cpp b/src/qdbus/qdbusviewer/propertydialog.cpp index 8595babc1..d9c7837f3 100644 --- a/src/qdbus/qdbusviewer/propertydialog.cpp +++ b/src/qdbus/qdbusviewer/propertydialog.cpp @@ -46,8 +46,8 @@ PropertyDialog::PropertyDialog(QWidget *parent, Qt::WindowFlags f) propertyTable->horizontalHeader()->setStretchLastSection(true); propertyTable->setEditTriggers(QAbstractItemView::AllEditTriggers); - connect(buttonBox, SIGNAL(accepted()), SLOT(accept()), Qt::QueuedConnection); - connect(buttonBox, SIGNAL(rejected()), SLOT(reject()), Qt::QueuedConnection); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept, Qt::QueuedConnection); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject, Qt::QueuedConnection); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(label); diff --git a/src/qdbus/qdbusviewer/qdbusviewer.cpp b/src/qdbus/qdbusviewer/qdbusviewer.cpp index 00de97891..4a513f357 100644 --- a/src/qdbus/qdbusviewer/qdbusviewer.cpp +++ b/src/qdbus/qdbusviewer/qdbusviewer.cpp @@ -36,6 +36,7 @@ #include <QtCore/QStringListModel> #include <QtCore/QMetaProperty> #include <QtCore/QSettings> +#include <QtGui/QKeyEvent> #include <QtWidgets/QLineEdit> #include <QtWidgets/QAction> #include <QtWidgets/QShortcut> @@ -71,6 +72,19 @@ public: } }; +class ServicesModel : public QStringListModel +{ +public: + explicit ServicesModel(QObject *parent = nullptr) + : QStringListModel(parent) + {} + + Qt::ItemFlags flags(const QModelIndex &index) const override + { + return QStringListModel::flags(index) & ~Qt::ItemIsEditable; + } +}; + QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : QWidget(parent), c(connection), @@ -80,13 +94,14 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : serviceFilterLine->setPlaceholderText(tr("Search...")); // Create model for services list - servicesModel = new QStringListModel(this); + servicesModel = new ServicesModel(this); // Wrap service list model in proxy for easy filtering and interactive sorting servicesProxyModel = new ServicesProxyModel(this); servicesProxyModel->setSourceModel(servicesModel); servicesProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); servicesView = new QTableView(this); + servicesView->installEventFilter(this); servicesView->setModel(servicesProxyModel); // Make services grid view behave like a list view with headers servicesView->verticalHeader()->hide(); @@ -96,27 +111,28 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : servicesView->setSortingEnabled(true); servicesView->sortByColumn(0, Qt::AscendingOrder); - connect(serviceFilterLine, SIGNAL(textChanged(QString)), servicesProxyModel, SLOT(setFilterFixedString(QString))); + connect(serviceFilterLine, &QLineEdit::textChanged, servicesProxyModel, &QSortFilterProxyModel::setFilterFixedString); + connect(serviceFilterLine, &QLineEdit::returnPressed, this, &QDBusViewer::serviceFilterReturnPressed); tree = new QTreeView; tree->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tree, SIGNAL(activated(QModelIndex)), this, SLOT(activate(QModelIndex))); + connect(tree, &QAbstractItemView::activated, this, &QDBusViewer::activate); refreshAction = new QAction(tr("&Refresh"), tree); refreshAction->setData(42); // increase the amount of 42 used as magic number by one refreshAction->setShortcut(QKeySequence::Refresh); - connect(refreshAction, SIGNAL(triggered()), this, SLOT(refreshChildren())); + connect(refreshAction, &QAction::triggered, this, &QDBusViewer::refreshChildren); QShortcut *refreshShortcut = new QShortcut(QKeySequence::Refresh, tree); - connect(refreshShortcut, SIGNAL(activated()), this, SLOT(refreshChildren())); + connect(refreshShortcut, &QShortcut::activated, this, &QDBusViewer::refreshChildren); QVBoxLayout *layout = new QVBoxLayout(this); topSplitter = new QSplitter(Qt::Vertical, this); layout->addWidget(topSplitter); log = new LogViewer; - connect(log, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl))); + connect(log, &QTextBrowser::anchorClicked, this, &QDBusViewer::anchorClicked); splitter = new QSplitter(topSplitter); splitter->addWidget(servicesView); @@ -131,22 +147,17 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : topSplitter->addWidget(splitter); topSplitter->addWidget(log); - connect(servicesView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(serviceChanged(QModelIndex))); - connect(tree, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(showContextMenu(QPoint))); + connect(servicesView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QDBusViewer::serviceChanged); + connect(tree, &QWidget::customContextMenuRequested, this, &QDBusViewer::showContextMenu); QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); if (c.isConnected()) { logMessage(QLatin1String("Connected to D-Bus.")); QDBusConnectionInterface *iface = c.interface(); - connect(iface, SIGNAL(serviceRegistered(QString)), - this, SLOT(serviceRegistered(QString))); - connect(iface, SIGNAL(serviceUnregistered(QString)), - this, SLOT(serviceUnregistered(QString))); - connect(iface, SIGNAL(serviceOwnerChanged(QString,QString,QString)), - this, SLOT(serviceOwnerChanged(QString,QString,QString))); + connect(iface, &QDBusConnectionInterface::serviceRegistered, this, &QDBusViewer::serviceRegistered); + connect(iface, &QDBusConnectionInterface::serviceUnregistered, this, &QDBusViewer::serviceUnregistered); + connect(iface, &QDBusConnectionInterface::serviceOwnerChanged, this, &QDBusViewer::serviceOwnerChanged); } else { logError(QLatin1String("Cannot connect to D-Bus: ") + c.lastError().message()); } @@ -175,6 +186,26 @@ void QDBusViewer::logMessage(const QString &msg) log->append(msg + QLatin1Char('\n')); } +void QDBusViewer::showEvent(QShowEvent *) +{ + serviceFilterLine->setFocus(); +} + +bool QDBusViewer::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == servicesView) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); + if (keyEvent->modifiers() == Qt::NoModifier) { + if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { + tree->setFocus(); + } + } + } + } + return false; +} + void QDBusViewer::logError(const QString &msg) { log->append(QLatin1String("<font color=\"red\">Error: </font>") + msg.toHtmlEscaped() + QLatin1String("<br>")); @@ -460,8 +491,9 @@ void QDBusViewer::serviceChanged(const QModelIndex &index) return; currentService = index.data().toString(); - tree->setModel(new QDBusViewModel(currentService, c)); - connect(tree->model(), SIGNAL(busError(QString)), this, SLOT(logError(QString))); + QDBusViewModel *model = new QDBusViewModel(currentService, c); + tree->setModel(model); + connect(model, &QDBusModel::busError, this, &QDBusViewer::logError); } void QDBusViewer::serviceRegistered(const QString &service) @@ -505,6 +537,15 @@ void QDBusViewer::serviceOwnerChanged(const QString &name, const QString &oldOwn } } +void QDBusViewer::serviceFilterReturnPressed() +{ + if (servicesProxyModel->rowCount() <= 0) + return; + + servicesView->selectRow(0); + servicesView->setFocus(); +} + void QDBusViewer::refreshChildren() { QDBusModel *model = qobject_cast<QDBusModel *>(tree->model()); diff --git a/src/qdbus/qdbusviewer/qdbusviewer.h b/src/qdbus/qdbusviewer/qdbusviewer.h index bd7c26ab6..34002f8ff 100644 --- a/src/qdbus/qdbusviewer/qdbusviewer.h +++ b/src/qdbus/qdbusviewer/qdbusviewer.h @@ -78,6 +78,7 @@ private slots: void serviceUnregistered(const QString &service); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); + void serviceFilterReturnPressed(); void activate(const QModelIndex &item); void logError(const QString &msg); @@ -85,6 +86,8 @@ private slots: private: void logMessage(const QString &msg); + void showEvent(QShowEvent *) override; + bool eventFilter(QObject *obj, QEvent *event) override; QDBusConnection c; QString currentService; diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index ec145c736..e64e2e223 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -742,11 +742,20 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l if (findNodeForCursor(qdb_, cursor)) // Was already parsed, propably in another tu return CXChildVisit_Continue; QString enumTypeName = fromCXString(clang_getCursorSpelling(cursor)); - if (enumTypeName.isEmpty()) + EnumNode* en = 0; + if (enumTypeName.isEmpty()) { enumTypeName = "anonymous"; - auto en = new EnumNode(parent_, enumTypeName); - en->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); - en->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); + if (parent_ && (parent_->isClass() || parent_->isNamespace())) { + Node* n = parent_->findChildNode(enumTypeName, Node::Enum); + if (n) + en = static_cast<EnumNode*>(n); + } + } + if (!en) { + en = new EnumNode(parent_, enumTypeName); + en->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); + en->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); + } // Enum values visitChildrenLambda(cursor, [&](CXCursor cur) { if (clang_getCursorKind(cur) != CXCursor_EnumConstantDecl) diff --git a/src/qdoc/config.cpp b/src/qdoc/config.cpp index 64c8786f6..27018007b 100644 --- a/src/qdoc/config.cpp +++ b/src/qdoc/config.cpp @@ -39,6 +39,9 @@ #include "config.h" #include "generator.h" #include <stdlib.h> +#if QT_CONFIG(process) +#include "qprocess.h" +#endif QT_BEGIN_NAMESPACE @@ -929,6 +932,30 @@ QStringList Config::loadMaster(const QString& fileName) } /*! + Returns the value of the environment variable \a varName. + If qgetenv() returns null and \a varName starts with 'Q', + try to query the variable from qmake. +*/ +QByteArray Config::getEnv(const char *varName) +{ + QByteArray var = qgetenv(varName); +#if QT_CONFIG(process) + if (var.isNull() && varName[0] == 'Q') { + QString path(QCoreApplication::applicationFilePath()); + path.replace(path.lastIndexOf('/') + 1, prog.size(), "qmake"); + QProcess qmake; + qmake.start(path, QStringList() << "-query" << varName); + if (qmake.waitForFinished()) { + QByteArray result = qmake.readAll().trimmed(); + if (result.at(0) != '*') + var = result; + } + } +#endif + return var; +} + +/*! Load, parse, and process a qdoc configuration file. This function is only called by the other load() function, but this one is recursive, i.e., it calls itself when it sees @@ -1032,7 +1059,7 @@ void Config::load(Location location, const QString& fileName) SKIP_CHAR(); } if (!var.isEmpty()) { - const QByteArray val = qgetenv(var.toLatin1().data()); + const QByteArray val = getEnv(var.toLatin1().data()); if (val.isNull()) { location.fatal(tr("Environment variable '%1' undefined").arg(var)); } @@ -1140,7 +1167,7 @@ void Config::load(Location location, const QString& fileName) SKIP_CHAR(); } if (!var.isEmpty()) { - const QByteArray val = qgetenv(var.toLatin1().constData()); + const QByteArray val = getEnv(var.toLatin1().constData()); if (val.isNull()) { location.fatal(tr("Environment variable '%1' undefined").arg(var)); } diff --git a/src/qdoc/config.h b/src/qdoc/config.h index 0de7076eb..ce705370b 100644 --- a/src/qdoc/config.h +++ b/src/qdoc/config.h @@ -102,6 +102,7 @@ public: QString getIncludeFilePath(const QString& fileName) const; QStringList getExampleQdocFiles(const QSet<QString> &excludedDirs, const QSet<QString> &excludedFiles); QStringList getExampleImageFiles(const QSet<QString> &excludedDirs, const QSet<QString> &excludedFiles); + QByteArray getEnv(const char *varName); static QStringList loadMaster(const QString& fileName); static bool isFileExcluded(const QString &fileName, const QSet<QString> &excludedFiles); diff --git a/src/qtattributionsscanner/scanner.cpp b/src/qtattributionsscanner/scanner.cpp index d7d958138..86450dd9e 100644 --- a/src/qtattributionsscanner/scanner.cpp +++ b/src/qtattributionsscanner/scanner.cpp @@ -195,7 +195,11 @@ QVector<Package> scanDirectory(const QString &directory, LogLevel logLevel) QDir dir(directory); QVector<Package> packages; - dir.setNameFilters(QStringList() << QStringLiteral("qt_attribution.json")); + QStringList nameFilters = QStringList() + << QStringLiteral("qt_attribution.json"); + if (qEnvironmentVariableIsSet("QT_ATTRIBUTIONSSCANNER_TEST")) + nameFilters << QStringLiteral("qt_attribution_test.json"); + dir.setNameFilters(nameFilters); dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files); const QFileInfoList entries = dir.entryInfoList(); diff --git a/tests/auto/qtattributionsscanner/testdata/good/complete/qt_attribution.json b/tests/auto/qtattributionsscanner/testdata/good/complete/qt_attribution_test.json index f8e7b1c68..f8e7b1c68 100644 --- a/tests/auto/qtattributionsscanner/testdata/good/complete/qt_attribution.json +++ b/tests/auto/qtattributionsscanner/testdata/good/complete/qt_attribution_test.json diff --git a/tests/auto/qtattributionsscanner/testdata/good/minimal/qt_attribution.json b/tests/auto/qtattributionsscanner/testdata/good/minimal/qt_attribution_test.json index 2dc53f852..2dc53f852 100644 --- a/tests/auto/qtattributionsscanner/testdata/good/minimal/qt_attribution.json +++ b/tests/auto/qtattributionsscanner/testdata/good/minimal/qt_attribution_test.json diff --git a/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/expected.error b/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/expected.error index e18d2976b..7095bf1a2 100644 --- a/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/expected.error +++ b/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/expected.error @@ -1,6 +1,6 @@ -File %{PWD}/qt_attribution.json: Missing mandatory property 'Name'. -File %{PWD}/qt_attribution.json: Missing mandatory property 'Id'. -File %{PWD}/qt_attribution.json: Missing mandatory property 'QDocModule'. -File %{PWD}/qt_attribution.json: Missing mandatory property 'QtUsage'. -File %{PWD}/qt_attribution.json: Missing mandatory property 'License'. -File %{PWD}/qt_attribution.json: Missing mandatory property 'Copyright'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'Name'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'Id'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'QDocModule'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'QtUsage'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'License'. +File %{PWD}/qt_attribution_test.json: Missing mandatory property 'Copyright'. diff --git a/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/qt_attribution.json b/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/qt_attribution_test.json index 2c63c0851..2c63c0851 100644 --- a/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/qt_attribution.json +++ b/tests/auto/qtattributionsscanner/testdata/warnings/incomplete/qt_attribution_test.json diff --git a/tests/auto/qtattributionsscanner/testdata/warnings/unknown/expected.error b/tests/auto/qtattributionsscanner/testdata/warnings/unknown/expected.error index 89b48074b..2cc0102a7 100644 --- a/tests/auto/qtattributionsscanner/testdata/warnings/unknown/expected.error +++ b/tests/auto/qtattributionsscanner/testdata/warnings/unknown/expected.error @@ -1 +1 @@ -File %{PWD}/qt_attribution.json: Unknown key Unknown. +File %{PWD}/qt_attribution_test.json: Unknown key Unknown. diff --git a/tests/auto/qtattributionsscanner/testdata/warnings/unknown/qt_attribution.json b/tests/auto/qtattributionsscanner/testdata/warnings/unknown/qt_attribution_test.json index f1d55638c..f1d55638c 100644 --- a/tests/auto/qtattributionsscanner/testdata/warnings/unknown/qt_attribution.json +++ b/tests/auto/qtattributionsscanner/testdata/warnings/unknown/qt_attribution_test.json diff --git a/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp b/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp index 7740fde9b..7789ad5f7 100644 --- a/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp +++ b/tests/auto/qtattributionsscanner/tst_qtattributionsscanner.cpp @@ -81,7 +81,7 @@ void tst_qtattributionsscanner::test_data() << QStringLiteral("warnings/unknown/expected.json") << QStringLiteral("warnings/unknown/expected.error"); QTest::newRow("singlefile") - << QStringLiteral("good/minimal/qt_attribution.json") + << QStringLiteral("good/minimal/qt_attribution_test.json") << QStringLiteral("good/minimal/expected.json") << QStringLiteral("good/minimal/expected.error"); } @@ -106,6 +106,9 @@ void tst_qtattributionsscanner::test() QProcess proc; QString command = m_cmd + " " + dir + " --output-format json"; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("QT_ATTRIBUTIONSSCANNER_TEST", "1"); + proc.setProcessEnvironment(env); proc.start(command, QIODevice::ReadWrite | QIODevice::Text); QVERIFY2(proc.waitForStarted(), qPrintable(command + QLatin1String(" :") + proc.errorString())); |