Merge remote-tracking branch 'origin/4.15'

Conflicts:
	cmake/QtCreatorIDEBranding.cmake
	qbs/modules/qtc/qtc.qbs
	qtcreator_ide_branding.pri

Change-Id: Ibc60debb3c409ae27e99df6071cf6115b272d6d8
This commit is contained in:
Eike Ziller
2021-04-15 15:48:30 +02:00
44 changed files with 417 additions and 1104 deletions

View File

@@ -374,6 +374,11 @@ void DesignDocument::updateSubcomponentManager()
currentModel()->imports() + currentModel()->possibleImports());
}
void DesignDocument::updateSubcomponentManagerImport(const Import &import)
{
m_subComponentManager->updateImport(import);
}
void DesignDocument::deleteSelected()
{
if (!currentModel())

View File

@@ -69,6 +69,7 @@ public:
void attachRewriterToModel();
void close();
void updateSubcomponentManager();
void updateSubcomponentManagerImport(const Import &import);
bool isUndoAvailable() const;
bool isRedoAvailable() const;

View File

@@ -292,6 +292,7 @@ void ItemLibraryWidget::handleAddImport(int index)
}
m_model->changeImports({import}, {});
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManagerImport(import);
m_stackedWidget->setCurrentIndex(0); // switch to the Components view after import is added
updateSearch();

View File

@@ -48,6 +48,7 @@ public:
explicit SubComponentManager(Model *model, QObject *parent = nullptr);
void update(const QUrl &fileUrl, const QList<Import> &imports);
void updateImport(const Import &import);
QStringList qmlFiles() const;
QStringList directories() const;
@@ -57,8 +58,8 @@ private: // functions
void parseFile(const QString &canonicalFilePath, bool addToLibrary, const QString&);
void parseFile(const QString &canonicalFilePath);
void addImport(int pos, const Import &import);
void removeImport(int pos);
void addImport(const Import &import, int index = -1);
void removeImport(int index);
void parseDirectories();
QFileInfoList watchedFiles(const QString &canonicalDirPath);
void unregisterQmlFile(const QFileInfo &fileInfo, const QString &qualifier);

View File

@@ -69,10 +69,10 @@ SubComponentManager::SubComponentManager(Model *model, QObject *parent)
this, [this](const QString &path) { parseDirectory(path); });
}
void SubComponentManager::addImport(int pos, const Import &import)
void SubComponentManager::addImport(const Import &import, int index)
{
if (debug)
qDebug() << Q_FUNC_INFO << pos << import.file().toUtf8();
qDebug() << Q_FUNC_INFO << index << import.file().toUtf8();
if (import.isFileImport()) {
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
@@ -97,12 +97,15 @@ void SubComponentManager::addImport(int pos, const Import &import)
// TODO: QDeclarativeDomImport::Library
}
m_imports.insert(pos, import);
if (index == -1)
m_imports.append(import);
else
m_imports.insert(index, import);
}
void SubComponentManager::removeImport(int pos)
void SubComponentManager::removeImport(int index)
{
const Import import = m_imports.takeAt(pos);
const Import import = m_imports.takeAt(index);
if (import.isFileImport()) {
const QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
@@ -499,7 +502,7 @@ void SubComponentManager::update(const QUrl &filePath, const QList<Import> &impo
removeImport(ii);
for (int ii = i; ii < imports.size(); ++ii) {
addImport(ii, imports.at(ii));
addImport(imports.at(ii), ii);
}
const QString newPath = newDir.absoluteFilePath();
@@ -513,5 +516,42 @@ void SubComponentManager::update(const QUrl &filePath, const QList<Import> &impo
parseDirectories();
}
void SubComponentManager::updateImport(const Import &import)
{
addImport(import);
if (import.isFileImport()) {
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
if (dirInfo.exists() && dirInfo.isDir())
parseDirectory(dirInfo.canonicalFilePath(), true, dirInfo.baseName().toUtf8());
} else {
QString url = import.url();
url.replace('.', '/');
QFileInfo dirInfo = QFileInfo(url);
const QStringList importPathList = importPaths();
bool parsed = false;
for (const QString &path : importPathList) {
QString fullUrl = path + '/' + url;
dirInfo = QFileInfo(fullUrl);
if (dirInfo.exists() && dirInfo.isDir()) {
parseDirectory(dirInfo.canonicalFilePath(), false);
parsed = true;
}
QString fullUrlVersion = path + '/' + url + '.' + import.version().split('.').constFirst();
dirInfo = QFileInfo(fullUrlVersion);
if (dirInfo.exists() && dirInfo.isDir()) {
parseDirectory(dirInfo.canonicalFilePath(), false);
parsed = true;
}
if (parsed)
break;
}
}
}
} // namespace QmlDesigner

View File

@@ -151,36 +151,14 @@ QString ModelNode::validId()
static bool idIsQmlKeyWord(const QString& id)
{
static const QSet<QString> keywords = {
"as",
"break",
"case",
"catch",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"finally",
"for",
"function",
"if",
"import",
"in",
"instanceof",
"new",
"return",
"switch",
"this",
"throw",
"try",
"typeof",
"var",
"void",
"while",
"with"
};
static const QSet<QString> keywords = {"as", "break", "case", "catch",
"continue", "debugger", "default", "delete",
"do", "else", "finally", "for",
"function", "if", "import", "in",
"instanceof", "new", "print", "return",
"switch", "this", "throw", "try",
"typeof", "var", "void", "while",
"with"};
return keywords.contains(id);
}

View File

@@ -1,3 +1,5 @@
find_package(Qt5 COMPONENTS QmlDebug REQUIRED)
add_qtc_plugin(QmlPreview
DEPENDS QmlDebug QmlJS
PLUGIN_DEPENDS Core ProjectExplorer QmlJSTools QtSupport ResourceEditor QmlProjectManager
@@ -9,8 +11,6 @@ add_qtc_plugin(QmlPreview
qmlpreviewruncontrol.cpp qmlpreviewruncontrol.h
qmldebugtranslationclient.cpp qmldebugtranslationclient.h
qmlpreview_global.h
projectfileselectionswidget.cpp projectfileselectionswidget.h
qmldebugtranslationwidget.cpp qmldebugtranslationwidget.h
)
extend_qtc_plugin(QmlPreview
@@ -19,3 +19,21 @@ extend_qtc_plugin(QmlPreview
tests/qmlpreviewclient_test.cpp tests/qmlpreviewclient_test.h
tests/qmlpreviewplugin_test.cpp tests/qmlpreviewplugin_test.h
)
# check if Qt version have_qml_debug_translation_protocol
# will be introduced in Qt 6.2, but there are users
# who needs it in older but special built Qt versions aswell
string(REGEX MATCH "^[0-9]*" QT_VERSION_MAJOR ${Qt5_VERSION})
get_target_property(qmldebugprivate_include_directories
Qt${QT_VERSION_MAJOR}::QmlDebugPrivate
INTERFACE_INCLUDE_DIRECTORIES
)
find_file(have_qml_debug_translation_protocol
NAMES private/qqmldebugtranslationprotocol_p.h
PATHS ${qmldebugprivate_include_directories}
)
extend_qtc_plugin(QmlPreview
CONDITION have_qml_debug_translation_protocol
PUBLIC_DEPENDS Qt5::QmlDebugPrivate
PUBLIC_DEFINES "FOUND_QML_DEBUG_TRANSLATION_PROTOCOL"
)

View File

@@ -1,162 +0,0 @@
/****************************************************************************
**
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "projectfileselectionswidget.h"
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <utils/treemodel.h>
#include <QAbstractTableModel>
#include <QBoxLayout>
#include <QHeaderView>
#include <QTreeView>
namespace QmlPreview {
class ProjectFileItem : public Utils::TreeItem
{
public:
ProjectFileItem() = default;
ProjectFileItem(const Utils::FilePath &f, bool d)
: filePath(f)
, disabled(d)
{}
Qt::ItemFlags flags(int) const override
{
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
}
QVariant data(int , int role) const override
{
if (role == Qt::DisplayRole)
return filePath.toUserOutput();
if (role == Qt::CheckStateRole) {
if (disabled)
return Qt::Unchecked;
else
return Qt::Checked;
}
return QVariant();
}
bool setData(int , const QVariant &data, int role) override
{
if (role != Qt::CheckStateRole)
return false;
disabled = (data == Qt::Unchecked);
return true;
}
Utils::FilePath filePath;
bool disabled = false;
};
ProjectFileSelectionsWidget::ProjectFileSelectionsWidget(const QString &projectSettingsKey, ProjectExplorer::FileType fileType, QWidget *parent)
: QWidget(parent)
, m_projectSettingsKey(projectSettingsKey)
, m_fileType(fileType)
{
auto model = new Utils::TreeModel<ProjectFileItem>(this);
model->setHeader({tr("Files to test:")});
auto updateCheckedFiles = [this, model] () {
m_checkedFiles.clear();
QStringList uncheckedFiles;
model->forAllItems([&, this](ProjectFileItem *item) {
if (item->disabled)
uncheckedFiles.append(item->filePath.toString());
else
m_checkedFiles.append(item->filePath);
});
if (auto project = ProjectExplorer::SessionManager::startupProject())
project->setNamedSettings(m_projectSettingsKey, uncheckedFiles);
emit selectionChanged(m_checkedFiles);
};
connect(model, &QAbstractItemModel::dataChanged, updateCheckedFiles);
auto view = new QTreeView(this);
view->setMinimumSize(QSize(100, 100));
view->setTextElideMode(Qt::ElideMiddle);
view->setWordWrap(false);
view->setUniformRowHeights(true);
view->setModel(model);
const auto viewLayout = new QHBoxLayout;
viewLayout->addWidget(view);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(viewLayout);
auto initModel = [this, model, updateCheckedFiles](ProjectExplorer::Project *project) {
if (!project)
return;
auto refreshModel = [this, model, updateCheckedFiles] () {
model->clear();
if (auto project = ProjectExplorer::SessionManager::startupProject()) {
const auto settingsDisabledFiles = project->namedSettings(m_projectSettingsKey).toStringList();
if (auto rootProjectNode = project->rootProjectNode()) {
auto rootPath = rootProjectNode->filePath();
rootProjectNode->forEachNode([this, settingsDisabledFiles, model, rootPath](ProjectExplorer::FileNode *fileNode) {
if (fileNode->fileType() == m_fileType
&& !fileNode->filePath().relativeChildPath(rootPath).startsWith("imports/")) {
bool isDisabled = settingsDisabledFiles.contains(fileNode->filePath().toString());
model->rootItem()->appendChild(new ProjectFileItem(fileNode->filePath(), isDisabled));
}
});
}
updateCheckedFiles();
}
};
// deploymentDataChanged is only triggered if the active project changed, so it is not a
// problem that maybe many different targets are connected to refreshModel
this->connect(project->activeTarget(), &ProjectExplorer::Target::deploymentDataChanged,
model, refreshModel, Qt::UniqueConnection);
refreshModel();
};
if (auto project = ProjectExplorer::SessionManager::startupProject()) {
initModel(project);
}
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged,
initModel);
}
Utils::FilePaths ProjectFileSelectionsWidget::checkedFiles()
{
return m_checkedFiles;
}
} // QmlPreview

View File

@@ -1,50 +0,0 @@
/****************************************************************************
**
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projectexplorer/projectnodes.h>
#include <utils/fileutils.h>
#include <QWidget>
namespace QmlPreview {
class ProjectFileSelectionsWidget : public QWidget
{
Q_OBJECT
public:
explicit ProjectFileSelectionsWidget(const QString &projectSettingsKey, ProjectExplorer::FileType fileType, QWidget *parent = nullptr);
Utils::FilePaths checkedFiles();
signals:
void selectionChanged(const Utils::FilePaths &selectedFiles);
private:
const QString m_projectSettingsKey;
ProjectExplorer::FileType m_fileType;
Utils::FilePaths m_checkedFiles;
};
} // QmlPreview

View File

@@ -26,8 +26,9 @@
#include "qmldebugtranslationclient.h"
#include <qmldebug/qpacketprotocol.h>
#include <QUrl>
#include <QColor>
#ifdef FOUND_QML_DEBUG_TRANSLATION_PROTOCOL
#include <private/qqmldebugtranslationprotocol_p.h>
#endif
namespace QmlPreview {
@@ -39,51 +40,14 @@ QmlDebugTranslationClient::QmlDebugTranslationClient(QmlDebug::QmlDebugConnectio
void QmlDebugTranslationClient::changeLanguage(const QUrl &url, const QString &localeIsoCode)
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::ChangeLanguage) << url << localeIsoCode;
#ifdef FOUND_QML_DEBUG_TRANSLATION_PROTOCOL
sendMessage(QQmlDebugTranslation::createChangeLanguageRequest(packet, url, localeIsoCode));
#else
const int request_change_language = 1;
packet << request_change_language << url << localeIsoCode;
sendMessage(packet.data());
}
#endif
void QmlDebugTranslationClient::changeWarningColor(const QColor &warningColor)
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::ChangeWarningColor) << warningColor;
sendMessage(packet.data());
}
void QmlDebugTranslationClient::changeElidedTextWarningString(const QString &warningString)
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::ChangeElidedTextWarningString) << warningString;
sendMessage(packet.data());
}
void QmlDebugTranslationClient::changeElideWarning(bool elideWarning)
{
if (elideWarning)
enableElidedTextWarning();
else
disableElidedTextWarning();
}
void QmlDebugTranslationClient::setDebugTranslationServiceLogFile(const QString &logFilePath)
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::SetDebugTranslationServiceLogFile) << logFilePath;
sendMessage(packet.data());
}
void QmlDebugTranslationClient::enableElidedTextWarning()
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::EnableElidedTextWarning);
sendMessage(packet.data());
}
void QmlDebugTranslationClient::disableElidedTextWarning()
{
QmlDebug::QPacket packet(dataStreamVersion());
packet << static_cast<qint8>(Command::DisableElidedTextWarning);
sendMessage(packet.data());
}
void QmlDebugTranslationClient::messageReceived(const QByteArray &data)

View File

@@ -34,34 +34,14 @@ class QMLPREVIEW_EXPORT QmlDebugTranslationClient : public QmlDebug::QmlDebugCli
{
Q_OBJECT
public:
//needs to be in sync with QQmlDebugTranslationClient in qtdeclarative/src/plugins/qmltooling/qmldbg_preview/qqmldebugtranslationservice.h
enum class Command {
ChangeLanguage,
MissingTranslationsChecked,
EnableElidedTextWarning,
DisableElidedTextWarning,
ChangeWarningColor,
ChangeElidedTextWarningString,
SetDebugTranslationServiceLogFile,
TestAllLanguages
};
explicit QmlDebugTranslationClient(QmlDebug::QmlDebugConnection *connection);
void changeLanguage(const QUrl &url, const QString &localeIsoCode);
void changeWarningColor(const QColor &warningColor);
void changeElidedTextWarningString(const QString &warningString); //is QByteArray better here?
void changeElideWarning(bool elideWarning);
void setDebugTranslationServiceLogFile(const QString &logFilePath);
void enableElidedTextWarning();
void disableElidedTextWarning();
void messageReceived(const QByteArray &message) override;
void stateChanged(State state) override;
signals:
// void pathRequested(const QString &path);
// void errorReported(const QString &error);
void debugServiceUnavailable();
};

View File

@@ -1,523 +0,0 @@
/****************************************************************************
**
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "qmldebugtranslationwidget.h"
#include "qmlpreviewruncontrol.h"
#include "qmlpreviewplugin.h"
#include "projectfileselectionswidget.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/outputwindow.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/projecttree.h>
#include <utils/outputformatter.h>
#include <utils/utilsicons.h>
#include <utils/fileutils.h>
#include <utils/qtcolorbutton.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>
#include <extensionsystem/iplugin.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
#include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h>
#include <qmlprojectmanager/qmlmultilanguageaspect.h>
#include <qtsupport/qtoutputformatter.h>
#include <QIcon>
#include <QRegularExpression>
#include <QCheckBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QAction>
#include <QPushButton>
#include <QCheckBox>
#include <QLineEdit>
#include <QButtonGroup>
#include <QRadioButton>
#include <QSpacerItem>
#include <QToolButton>
#include <QTextBlock>
#include <QFileDialog>
namespace {
QObject *getPreviewPlugin()
{
const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
const auto pluginIt = std::find_if(specs.cbegin(), specs.cend(),
[](const ExtensionSystem::PluginSpec *p) {
return p->name() == "QmlPreview";
});
if (pluginIt != specs.cend())
return (*pluginIt)->plugin();
return nullptr;
}
}
namespace QmlPreview {
QmlDebugTranslationWidget::QmlDebugTranslationWidget(QWidget *parent, TestLanguageGetter languagesGetterMethod)
: QWidget(parent)
, m_testLanguagesGetter(languagesGetterMethod)
, m_warningColor(Qt::red)
//, m_foundTrColor(Qt::green) // invalid color -> init without the frame
, m_lastWarningColor(m_warningColor)
, m_lastfoundTrColor(Qt::green)
{
auto mainLayout = new QVBoxLayout(this);
auto buttonGroup = new QButtonGroup(this);
// it gets the text from updateCurrentEditor method
m_singleFileButton = new QRadioButton();
m_singleFileButton->setChecked(true);
buttonGroup->addButton(m_singleFileButton);
const QString projectSettingsKey = "QmlPreview.DisabledDebugTranslationFiles";
const ProjectExplorer::FileType filterFileType = ProjectExplorer::FileType::QML;
m_checkableProjectFileView = new ProjectFileSelectionsWidget(projectSettingsKey, filterFileType);
m_checkableProjectFileView->setVisible(false);
connect(m_checkableProjectFileView, &ProjectFileSelectionsWidget::selectionChanged, this, &QmlDebugTranslationWidget::setFiles);
m_multipleFileButton = new QRadioButton(tr("Multiple files"));
buttonGroup->addButton(m_multipleFileButton);
connect(m_multipleFileButton, &QAbstractButton::toggled, m_checkableProjectFileView, &QWidget::setVisible);
connect(m_multipleFileButton, &QAbstractButton::toggled, this, &QmlDebugTranslationWidget::updateFiles);
mainLayout->addWidget(m_singleFileButton);
mainLayout->addWidget(m_multipleFileButton);
mainLayout->addWidget(m_checkableProjectFileView);
// language checkboxes are add in updateAvailableTranslations method
m_selectLanguageLayout = new QHBoxLayout;
mainLayout->addLayout(m_selectLanguageLayout);
auto settingsLayout = new QHBoxLayout();
mainLayout->addLayout(settingsLayout);
auto elideWarningCheckBox = new QCheckBox(tr("Elide warning"));
connect(elideWarningCheckBox, &QCheckBox::stateChanged, [this] (int state) {
m_elideWarning = (state == Qt::Checked);
});
settingsLayout->addWidget(elideWarningCheckBox);
auto warningColorCheckbox = new QCheckBox(tr("Warning color: "));
settingsLayout->addWidget(warningColorCheckbox);
auto warningColorButton = new Utils::QtColorButton();
connect(warningColorCheckbox, &QCheckBox::stateChanged, [warningColorButton, this] (int state) {
if (state == Qt::Checked) {
warningColorButton->setColor(m_lastWarningColor);
warningColorButton->setEnabled(true);
} else {
m_lastWarningColor = warningColorButton->color();
warningColorButton->setColor({});
warningColorButton->setEnabled(false);
}
});
connect(warningColorButton, &Utils::QtColorButton::colorChanged, [this](const QColor &color) {
m_warningColor = color;
});
warningColorCheckbox->setCheckState(Qt::Checked);
settingsLayout->addWidget(warningColorButton);
auto foundTrColorCheckbox = new QCheckBox(tr("Found \"tr\" color: "));
settingsLayout->addWidget(foundTrColorCheckbox);
auto foundTrColorButton = new Utils::QtColorButton();
foundTrColorButton->setDisabled(true);
connect(foundTrColorCheckbox, &QCheckBox::stateChanged, [foundTrColorButton, this] (int state) {
if (state == Qt::Checked) {
foundTrColorButton->setColor(m_lastfoundTrColor);
foundTrColorButton->setEnabled(true);
} else {
m_lastfoundTrColor = foundTrColorButton->color();
foundTrColorButton->setColor({});
foundTrColorButton->setEnabled(false);
}
});
connect(foundTrColorButton, &Utils::QtColorButton::colorChanged, [this](const QColor &color) {
m_foundTrColor = color;
});
settingsLayout->addWidget(foundTrColorButton);
settingsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
auto controlLayout = new QHBoxLayout;
mainLayout->addLayout(controlLayout);
auto showLogButton = new QToolButton;
showLogButton->setText(tr("Show Log"));
showLogButton->setCheckable(true);
controlLayout->addWidget(showLogButton);
// TODO: do we still need this buttons?
// auto pauseButton = new QToolButton;
// pauseButton->setText(tr("Pause"));
// pauseButton->setCheckable(true);
// controlLayout->addWidget(pauseButton);
// auto onTheFlyButton = new QToolButton;
// onTheFlyButton->setText(tr("On the Fly"));
// controlLayout->addWidget(onTheFlyButton);
m_runTestButton = new QPushButton();
m_runTestButton->setCheckable(true);
m_runTestButton->setText(runButtonText());
connect(m_runTestButton, &QPushButton::toggled, [this](bool checked) {
m_runTestButton->setText(runButtonText(checked));
});
connect(m_runTestButton, &QPushButton::clicked, [this](bool checked) {
if (checked)
runTest();
else {
if (m_currentRunControl)
m_currentRunControl->initiateStop();
// TODO: what happens if we already have a preview running?
// QmlPreviewPlugin::stopAllRunControls();
// qWarning() << "not implemented"; // TODO: stop still running tests
}
});
controlLayout->addWidget(m_runTestButton);
m_runOutputWindow = new Core::OutputWindow(Core::Context("QmlPreview.DebugTranslation"),
"QmlPreview/OutputWindow/Zoom");
m_runOutputWindow->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_runOutputWindow->setReadOnly(true);
m_runOutputWindow->setVisible(false);
mainLayout->addWidget(m_runOutputWindow);
QSpacerItem *endSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
mainLayout->addItem(endSpacerItem);
connect(showLogButton, &QToolButton::toggled, m_runOutputWindow, [this, mainLayout, endSpacerItem](bool checked) {
m_runOutputWindow->setVisible(checked);
if (m_runOutputWindow->isVisible())
mainLayout->takeAt(mainLayout->count() - 1);
else
mainLayout->addItem(endSpacerItem);
});
auto loadLogButton = new QToolButton;
loadLogButton->setText(tr("Load"));
controlLayout->addWidget(loadLogButton);
connect(loadLogButton, &QToolButton::clicked, this, &QmlDebugTranslationWidget::loadLogFile);
auto saveLogButton = new QToolButton;
saveLogButton->setText(tr("Save"));
controlLayout->addWidget(saveLogButton);
connect(saveLogButton, &QToolButton::clicked, this, &QmlDebugTranslationWidget::saveLogToFile);
auto clearButton = new QToolButton;
clearButton->setText(tr("Clear"));
controlLayout->addWidget(clearButton);
connect(clearButton, &QToolButton::clicked, this, &QmlDebugTranslationWidget::clear);
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, &Core::EditorManager::currentEditorChanged, this, &QmlDebugTranslationWidget::updateCurrentEditor);
updateCurrentEditor(Core::EditorManager::currentEditor());
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged,
this, &QmlDebugTranslationWidget::updateCurrentTranslations);
updateStartupProjectTranslations();
ProjectExplorer::TaskHub::addCategory("QmlPreview.Translation", tr("Translation issues"));
}
QmlDebugTranslationWidget::~QmlDebugTranslationWidget()
{
}
void QmlDebugTranslationWidget::updateCurrentEditor(const Core::IEditor *editor)
{
if (editor && editor->document())
m_currentFilePath = editor->document()->filePath();
else
m_currentFilePath.clear();
m_singleFileButton->setText(singleFileButtonText(m_currentFilePath.toString()));
updateFiles();
}
void QmlDebugTranslationWidget::updateStartupProjectTranslations()
{
updateCurrentTranslations(ProjectExplorer::SessionManager::startupProject());
}
QColor QmlDebugTranslationWidget::warningColor()
{
return m_warningColor;
}
QColor QmlDebugTranslationWidget::foundTrColor()
{
return m_foundTrColor;
}
void QmlDebugTranslationWidget::updateCurrentTranslations(ProjectExplorer::Project *project)
{
m_testLanguages.clear();
for (int i = m_selectLanguageLayout->count()-1; i >= 0; --i) {
auto layoutItem = m_selectLanguageLayout->takeAt(i);
delete layoutItem->widget();
delete layoutItem;
}
if (!project)
return;
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current(project)) {
connect(multiLanguageAspect, &QmlProjectManager::QmlMultiLanguageAspect::changed,
this, &QmlDebugTranslationWidget::updateStartupProjectTranslations,
Qt::UniqueConnection);
auto languageLabel = new QLabel();
languageLabel->setText(tr("Language to test:"));
m_selectLanguageLayout->addWidget(languageLabel);
if (multiLanguageAspect->value()) {
addLanguageCheckBoxes({multiLanguageAspect->currentLocale()});
if (m_testLanguagesGetter) {
auto addTestLanguages = new QPushButton(tr("Add Test Languages"));
m_selectLanguageLayout->addWidget(addTestLanguages);
connect(addTestLanguages, &QPushButton::clicked, [this]() {
addLanguageCheckBoxes(m_testLanguagesGetter());
});
}
} else {
QString errorMessage;
addLanguageCheckBoxes(project->availableQmlPreviewTranslations(&errorMessage));
}
m_selectLanguageLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
}
}
void QmlDebugTranslationWidget::updateFiles()
{
if (m_multipleFileButton->isChecked())
setFiles(m_checkableProjectFileView->checkedFiles());
else
setFiles({m_currentFilePath});
}
void QmlDebugTranslationWidget::setFiles(const Utils::FilePaths &filePathes)
{
m_selectedFilePaths = filePathes;
}
void QmlDebugTranslationWidget::runTest()
{
m_runOutputWindow->grayOutOldContent();
auto runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE);
QTC_ASSERT(runControl, qWarning("Can not create a QmlPreviewRunner"); return;);
auto previewPlugin = qobject_cast<Internal::QmlPreviewPlugin*>(getPreviewPlugin());
connect(runControl, &ProjectExplorer::RunControl::started, [this, runControl, previewPlugin]() {
//Q_ASSERT(m_currentRunControl == nullptr); //TODO: who deletes the runcontrol
m_currentRunControl = runControl;
m_runOutputWindow->setLineParsers(
ProjectExplorer::OutputFormatterFactory::createFormatters(runControl->target()));
int timerCounter = 1;
const auto testLanguageList = m_testLanguages;
if (m_elideWarning)
previewPlugin->changeElideWarning(true);
auto testLanguages = [previewPlugin, runControl, testLanguageList](int timerCounter, const QString &previewedFile) {
for (auto language : testLanguageList) {
QTimer::singleShot(timerCounter * 1000, previewPlugin, [previewPlugin, runControl, language, previewedFile]() {
if (runControl && runControl->isRunning()) {
if (!previewedFile.isEmpty())
previewPlugin->setPreviewedFile(previewedFile);
previewPlugin->setLocaleIsoCode(language);
}
});
}
};
for (auto filePath : qAsConst(m_selectedFilePaths)) {
testLanguages(timerCounter++, filePath.toString());
}
});
connect(runControl, &ProjectExplorer::RunControl::stopped, [this]() {
m_runTestButton->setChecked(false);
//delete m_currentRunControl; // who deletes the runcontrol?
m_currentRunControl = nullptr;
if (auto previewPlugin = qobject_cast<Internal::QmlPreviewPlugin*>(getPreviewPlugin()))
previewPlugin->setLocaleIsoCode(m_lastUsedLanguageBeforeTest);
});
connect(runControl, &ProjectExplorer::RunControl::appendMessage,
this, &QmlDebugTranslationWidget::appendMessage);
if (auto project = ProjectExplorer::SessionManager::startupProject()) {
if (auto target = project->activeTarget()) {
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current(target))
m_lastUsedLanguageBeforeTest = multiLanguageAspect->currentLocale();
if (auto runConfiguration = target->activeRunConfiguration()) {
runControl->setRunConfiguration(runConfiguration);
if (runControl->createMainWorker()) {
previewPlugin->setLocaleIsoCode(QString());
runControl->initiateStart();
}
}
}
}
}
void QmlDebugTranslationWidget::clear()
{
m_runOutputWindow->clear();
ProjectExplorer::TaskHub::clearTasks("QmlPreview.Translation");
}
QString QmlDebugTranslationWidget::currentDir() const
{
return m_lastDir.isEmpty() ?
ProjectExplorer::ProjectTree::currentFilePath().parentDir().toString() : m_lastDir;
}
void QmlDebugTranslationWidget::setCurrentDir(const QString &path)
{
m_lastDir = path;
}
void QmlDebugTranslationWidget::loadLogFile()
{
const auto fileName = QFileDialog::getOpenFileName(this, QStringLiteral("Open File"), currentDir());
if (!fileName.isEmpty()) {
setCurrentDir(QFileInfo(fileName).absolutePath());
QFile f(fileName);
if (f.open(QFile::ReadOnly)) {
clear();
while (!f.atEnd())
appendMessage(QString::fromUtf8(f.readLine()), Utils::GeneralMessageFormat);
} else {
// TODO: maybe add this message to log and tasks
qWarning() << "Failed to open" << fileName << ":" << f.errorString();
}
}
}
void QmlDebugTranslationWidget::saveLogToFile()
{
const QString fileName = QFileDialog::getSaveFileName(
this, tr("Choose file to save logged issues."), currentDir());
if (!fileName.isEmpty()) {
setCurrentDir(QFileInfo(fileName).absolutePath());
QFile f(fileName);
if (f.open(QFile::WriteOnly | QFile::Text))
f.write(m_runOutputWindow->toPlainText().toUtf8());
}
}
void QmlDebugTranslationWidget::appendMessage(const QString &message, Utils::OutputFormat format)
{
const auto newLine = QRegularExpression("[\r\n]");
const auto messages = message.split(newLine, Qt::SkipEmptyParts);
if (messages.count() > 1) {
for (auto m : messages)
appendMessage(m + "\n", format);
return;
}
const QString serviceSeperator = ": QQmlDebugTranslationService: ";
if (!message.contains(serviceSeperator))
return;
QString locationString = message;
locationString = locationString.split(serviceSeperator).first();
static const QRegularExpression qmlLineColumnLink("^(" QT_QML_URL_REGEXP ")" // url
":(\\d+)" // line
":(\\d+)$"); // column
const QRegularExpressionMatch qmlLineColumnMatch = qmlLineColumnLink.match(locationString);
auto fileLine = -1;
QUrl fileUrl;
if (qmlLineColumnMatch.hasMatch()) {
fileUrl = QUrl(qmlLineColumnMatch.captured(1));
fileLine = qmlLineColumnMatch.captured(2).toInt();
}
m_runOutputWindow->appendMessage(message, format);
auto type = ProjectExplorer::Task::TaskType::Warning;
auto description = message.split(serviceSeperator).at(1);
auto filePath = Utils::FilePath::fromString(fileUrl.toLocalFile());
auto category = "QmlPreview.Translation";
auto icon = Utils::Icons::WARNING.icon();
ProjectExplorer::TaskHub::addTask(ProjectExplorer::Task(type,
description,
filePath,
fileLine,
category,
icon,
ProjectExplorer::Task::NoOptions));
}
QString QmlDebugTranslationWidget::singleFileButtonText(const QString &filePath)
{
auto buttonText = tr("Current file: %1");
if (filePath.isEmpty())
return buttonText.arg(tr("Empty"));
return buttonText.arg(filePath);
}
QString QmlDebugTranslationWidget::runButtonText(bool isRunning)
{
if (isRunning) {
return tr("Stop");
}
return tr("Run Language Tests");
}
void QmlDebugTranslationWidget::addLanguageCheckBoxes(const QStringList &languages)
{
for (auto language : languages) {
auto languageCheckBox = new QCheckBox(language);
m_selectLanguageLayout->addWidget(languageCheckBox);
connect(languageCheckBox, &QCheckBox::stateChanged, [this, language] (int state) {
if (state == Qt::Checked)
m_testLanguages.append(language);
else
m_testLanguages.removeAll(language);
});
languageCheckBox->setChecked(true);
}
}
} // namespace QmlPreview

View File

@@ -1,110 +0,0 @@
/****************************************************************************
**
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "qmlpreview_global.h"
#include <utils/fileutils.h>
#include <utils/outputformat.h>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QRadioButton;
class QPushButton;
class QHBoxLayout;
QT_END_NAMESPACE
namespace Core {
class IEditor;
class OutputWindow;
}
namespace ProjectExplorer {
class Project;
class RunControl;
}
namespace QmlPreview {
class ProjectFileSelectionsWidget;
class QMLPREVIEW_EXPORT QmlDebugTranslationWidget : public QWidget
{
using TestLanguageGetter = std::function<QStringList()>;
Q_OBJECT
public:
explicit QmlDebugTranslationWidget(QWidget *parent = nullptr, TestLanguageGetter languagesGetterMethod = {});
~QmlDebugTranslationWidget() override;
void setCurrentFile(const Utils::FilePath &filepath);
void setFiles(const Utils::FilePaths &filePathes);
void updateStartupProjectTranslations();
QColor warningColor();
QColor foundTrColor();
private:
void updateCurrentEditor(const Core::IEditor *editor);
void updateCurrentTranslations(ProjectExplorer::Project *project);
void updateFiles();
void runTest();
void appendMessage(const QString &message, Utils::OutputFormat format);
void clear();
void loadLogFile();
void saveLogToFile();
QString currentDir() const;
void setCurrentDir(const QString &path);
QString singleFileButtonText(const QString &filePath);
QString runButtonText(bool isRunning = false);
void addLanguageCheckBoxes(const QStringList &languages);
QStringList m_testLanguages;
QString m_lastUsedLanguageBeforeTest;
bool m_elideWarning = false;
Core::OutputWindow *m_runOutputWindow = nullptr;
QRadioButton *m_singleFileButton = nullptr;
QRadioButton *m_multipleFileButton = nullptr;
ProjectFileSelectionsWidget *m_checkableProjectFileView = nullptr;
QPushButton *m_runTestButton = nullptr;
Utils::FilePath m_currentFilePath;
Utils::FilePaths m_selectedFilePaths;
ProjectExplorer::RunControl *m_currentRunControl = nullptr;
QString m_lastDir;
QHBoxLayout *m_selectLanguageLayout;
TestLanguageGetter m_testLanguagesGetter;
QColor m_warningColor;
QColor m_foundTrColor;
QColor m_lastWarningColor;
QColor m_lastfoundTrColor;
};
} // namespace QmlPreview

View File

@@ -10,23 +10,19 @@ include(tests/tests.pri)
HEADERS += \
qmlpreview_global.h \
qmldebugtranslationclient.h \
qmldebugtranslationwidget.h \
qmlpreviewclient.h \
qmlpreviewplugin.h \
qmlpreviewruncontrol.h \
qmlpreviewconnectionmanager.h \
qmlpreviewfileontargetfinder.h \
projectfileselectionswidget.h
qmlpreviewfileontargetfinder.h
SOURCES += \
qmlpreviewplugin.cpp \
qmldebugtranslationclient.cpp \
qmldebugtranslationwidget.cpp \
qmlpreviewclient.cpp \
qmlpreviewruncontrol.cpp \
qmlpreviewconnectionmanager.cpp \
qmlpreviewfileontargetfinder.cpp \
projectfileselectionswidget.cpp
qmlpreviewfileontargetfinder.cpp
OTHER_FILES += \
QmlPreview.json.in

View File

@@ -26,8 +26,6 @@ QtcPlugin {
"qmlpreviewclient.h",
"qmldebugtranslationclient.cpp",
"qmldebugtranslationclient.h",
"qmldebugtranslationwidget.cpp",
"qmldebugtranslationwidget.h",
"qmlpreviewconnectionmanager.cpp",
"qmlpreviewconnectionmanager.h",
"qmlpreviewfileontargetfinder.cpp",
@@ -37,8 +35,6 @@ QtcPlugin {
"qmlpreviewplugin.h",
"qmlpreviewruncontrol.cpp",
"qmlpreviewruncontrol.h",
"projectfileselectionswidget.cpp",
"projectfileselectionswidget.h"
]
}

View File

@@ -40,6 +40,9 @@ QmlPreviewConnectionManager::QmlPreviewConnectionManager(QObject *parent) :
QmlDebug::QmlDebugConnectionManager(parent)
{
setTarget(nullptr);
m_createDebugTranslationClientMethod = [](QmlDebug::QmlDebugConnection *connection) {
return std::make_unique<QmlPreview::QmlDebugTranslationClient>(connection);
};
}
QmlPreviewConnectionManager::~QmlPreviewConnectionManager() = default;
@@ -66,6 +69,11 @@ void QmlPreviewConnectionManager::setFpsHandler(QmlPreviewFpsHandler fpsHandler)
m_fpsHandler = fpsHandler;
}
void QmlPreviewConnectionManager::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator)
{
m_createDebugTranslationClientMethod = creator;
}
void QmlPreviewConnectionManager::createClients()
{
createPreviewClient();
@@ -113,9 +121,9 @@ QUrl QmlPreviewConnectionManager::findValidI18nDirectoryAsUrl(const QString &loc
void QmlPreviewConnectionManager::createDebugTranslationClient()
{
m_qmlDebugTranslationClient = new QmlDebugTranslationClient(connection());
m_qmlDebugTranslationClient = m_createDebugTranslationClientMethod(connection());
connect(this, &QmlPreviewConnectionManager::language,
m_qmlDebugTranslationClient, [this](const QString &locale) {
m_qmlDebugTranslationClient.get(), [this](const QString &locale) {
m_lastUsedLanguage = locale;
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
// service expects a context URL.
@@ -124,10 +132,7 @@ void QmlPreviewConnectionManager::createDebugTranslationClient()
m_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), locale);
}
});
connect(this, &QmlPreviewConnectionManager::changeElideWarning,
m_qmlDebugTranslationClient, &QmlDebugTranslationClient::changeElideWarning);
connect(m_qmlDebugTranslationClient.data(), &QmlDebugTranslationClient::debugServiceUnavailable,
connect(m_qmlDebugTranslationClient.get(), &QmlDebugTranslationClient::debugServiceUnavailable,
this, []() {
QMessageBox::warning(Core::ICore::dialogParent(), "Error connect to QML DebugTranslation service",
"QML DebugTranslation feature is not available for this version of Qt.");
@@ -260,7 +265,7 @@ void QmlPreviewConnectionManager::clearClient(QObject *client)
void QmlPreviewConnectionManager::destroyClients()
{
clearClient(m_qmlPreviewClient);
clearClient(m_qmlDebugTranslationClient);
clearClient(m_qmlDebugTranslationClient.release());
m_fileSystemWatcher.removeFiles(m_fileSystemWatcher.files());
QTC_ASSERT(m_fileSystemWatcher.directories().isEmpty(),
m_fileSystemWatcher.removeDirectories(m_fileSystemWatcher.directories()));

View File

@@ -52,12 +52,12 @@ public:
void setFileLoader(QmlPreviewFileLoader fileLoader);
void setFileClassifier(QmlPreviewFileClassifier fileClassifier);
void setFpsHandler(QmlPreviewFpsHandler fpsHandler);
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator);
signals:
void loadFile(const QString &filename, const QString &changedFile, const QByteArray &contents);
void zoom(float zoomFactor);
void language(const QString &locale);
void changeElideWarning(bool elideWarning);
void rerun();
void restart();
@@ -68,18 +68,19 @@ protected:
private:
void createPreviewClient();
void createDebugTranslationClient();
QUrl findValidI18nDirectoryAsUrl(const QString &locale);
void clearClient(QObject *client);
QUrl findValidI18nDirectoryAsUrl(const QString &locale);
Utils::FileInProjectFinder m_projectFileFinder;
QmlPreviewFileOnTargetFinder m_targetFileFinder;
QPointer<QmlPreviewClient> m_qmlPreviewClient;
QPointer<QmlDebugTranslationClient> m_qmlDebugTranslationClient;
std::unique_ptr<QmlDebugTranslationClient> m_qmlDebugTranslationClient;
Utils::FileSystemWatcher m_fileSystemWatcher;
QUrl m_lastLoadedUrl;
QString m_lastUsedLanguage;
QmlPreviewFileLoader m_fileLoader = nullptr;
QmlPreviewFileClassifier m_fileClassifier = nullptr;
QmlPreviewFpsHandler m_fpsHandler = nullptr;
QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod;
};
} // namespace Internal

View File

@@ -26,8 +26,6 @@
#include "qmlpreviewplugin.h"
#include "qmlpreviewruncontrol.h"
#include "qmldebugtranslationwidget.h"
#ifdef WITH_TESTS
#include "tests/qmlpreviewclient_test.h"
#include "tests/qmlpreviewplugin_test.h"
@@ -67,7 +65,6 @@
using namespace ProjectExplorer;
namespace QmlPreview {
namespace Internal {
class QmlPreviewParser : public QObject
{
@@ -151,8 +148,7 @@ public:
float m_zoomFactor = -1.0;
QmlPreview::QmlPreviewFpsHandler m_fpsHandler = nullptr;
QString m_localeIsoCode;
bool m_translationElideWarning = false;
QPointer<QmlDebugTranslationWidget> m_qmlDebugTranslationWidget;
QmlDebugTranslationClientCreator m_createDebugTranslationClientMethod;
RunWorkerFactory localRunWorkerFactory{
RunWorkerFactory::make<LocalQmlPreviewSupport>(),
@@ -170,7 +166,7 @@ public:
m_fpsHandler,
m_zoomFactor,
m_localeIsoCode,
m_translationElideWarning
m_createDebugTranslationClientMethod
});
connect(q, &QmlPreviewPlugin::updatePreviews,
runner, &QmlPreviewRunner::loadFile);
@@ -182,8 +178,6 @@ public:
runner, &QmlPreviewRunner::zoom);
connect(q, &QmlPreviewPlugin::localeIsoCodeChanged,
runner, &QmlPreviewRunner::language);
connect(q, &QmlPreviewPlugin::elideWarningChanged,
runner, &QmlPreviewRunner::changeElideWarning);
connect(runner, &RunWorker::started, this, [this, runControl] {
addPreview(runControl);
@@ -222,50 +216,6 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
Core::ActionManager::registerAction(action, "QmlPreview.RunPreview"),
Constants::G_BUILD_RUN);
action = new QAction(QmlPreviewPlugin::tr("Test Translations"), this);
action->setToolTip(QLatin1String("Runs the preview with all available translations and collects all issues."));
action->setEnabled(SessionManager::startupProject() != nullptr);
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, action,
&QAction::setEnabled);
connect(action, &QAction::triggered, this, [this]() {
if (SessionManager::startupProject()) {
// Deletion for this widget is taken care of in aboutToShutdown() and registerWindow()
m_qmlDebugTranslationWidget = new QmlDebugTranslationWidget();
Core::ICore::registerWindow(m_qmlDebugTranslationWidget, Core::Context("Core.DebugTranslation"));
m_qmlDebugTranslationWidget->show();
}
});
menu->addAction(
Core::ActionManager::registerAction(action, "QmlPreview.TestTranslations"),
Constants::G_BUILD_RUN);
auto updateTestTranslationAction = [action]() {
bool showTestTranslationAction = false;
bool enableTestTranslationAction = false;
QtSupport::BaseQtVersion *activeQt{};
if (auto project = SessionManager::startupProject()) {
if (auto target = project->activeTarget()) {
if (auto activeKit = target->kit())
activeQt = QtSupport::QtKitAspect::qtVersion(activeKit);
}
}
for (auto qtVersion : QtSupport::QtVersionManager::versions()) {
if (qtVersion->features().contains("QtStudio")) {
showTestTranslationAction = true;
if (qtVersion == activeQt)
enableTestTranslationAction = true;
}
}
action->setVisible(showTestTranslationAction);
action->setEnabled(enableTestTranslationAction);
};
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged,
updateTestTranslationAction);
connect(QtSupport::QtVersionManager::instance(),
&QtSupport::QtVersionManager::qtVersionsChanged,
updateTestTranslationAction);
menu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT);
action = new QAction(QmlPreviewPlugin::tr("Preview File"), this);
action->setEnabled(false);
@@ -314,7 +264,6 @@ ExtensionSystem::IPlugin::ShutdownFlag QmlPreviewPlugin::aboutToShutdown()
{
d->m_parseThread.quit();
d->m_parseThread.wait();
delete d->m_qmlDebugTranslationWidget;
return SynchronousShutdown;
}
@@ -410,15 +359,9 @@ void QmlPreviewPlugin::setLocaleIsoCode(const QString &localeIsoCode)
emit localeIsoCodeChanged(d->m_localeIsoCode);
}
bool QmlPreviewPlugin::elideWarning() const
void QmlPreviewPlugin::setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator)
{
return d->m_translationElideWarning;
}
void QmlPreviewPlugin::changeElideWarning(bool elideWarning)
{
d->m_translationElideWarning = elideWarning;
emit elideWarningChanged(elideWarning);
d->m_createDebugTranslationClientMethod = creator;
}
void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
@@ -588,7 +531,6 @@ void QmlPreviewParser::parse(const QString &name, const QByteArray &contents,
emit failure();
}
} // namespace Internal
} // namespace QmlPreview
#include <qmlpreviewplugin.moc>

View File

@@ -25,6 +25,9 @@
#pragma once
#include "qmlpreview_global.h"
#include "qmldebugtranslationclient.h"
#include <projectexplorer/runcontrol.h>
#include <extensionsystem/iplugin.h>
#include <qmljs/qmljsdialect.h>
@@ -34,16 +37,17 @@
namespace Core { class IEditor; }
namespace QmlDebug { class QmlDebugConnection; }
namespace QmlPreview {
typedef bool (*QmlPreviewFileClassifier) (const QString &);
typedef QByteArray (*QmlPreviewFileLoader)(const QString &, bool *);
typedef void (*QmlPreviewFpsHandler)(quint16[8]);
typedef QList<ProjectExplorer::RunControl *> QmlPreviewRunControlList;
typedef std::function<std::unique_ptr<QmlDebugTranslationClient>(QmlDebug::QmlDebugConnection *)> QmlDebugTranslationClientCreator;
namespace Internal {
class QmlPreviewPlugin : public ExtensionSystem::IPlugin
class QMLPREVIEW_EXPORT QmlPreviewPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "QmlPreview.json")
@@ -59,7 +63,6 @@ class QmlPreviewPlugin : public ExtensionSystem::IPlugin
WRITE setFpsHandler NOTIFY fpsHandlerChanged)
Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
Q_PROPERTY(QString localeIsoCode READ localeIsoCode WRITE setLocaleIsoCode NOTIFY localeIsoCodeChanged)
Q_PROPERTY(bool elideWarning READ elideWarning WRITE changeElideWarning NOTIFY elideWarningChanged)
public:
~QmlPreviewPlugin() override;
@@ -87,8 +90,7 @@ public:
QString localeIsoCode() const;
void setLocaleIsoCode(const QString &localeIsoCode);
bool elideWarning() const;
void changeElideWarning(bool elideWarning);
void setQmlDebugTranslationClientCreator(QmlDebugTranslationClientCreator creator);
signals:
void checkDocument(const QString &name, const QByteArray &contents,
@@ -104,13 +106,11 @@ signals:
void zoomFactorChanged(float zoomFactor);
void localeIsoCodeChanged(const QString &localeIsoCode);
void elideWarningChanged(bool elideWarning);
private:
class QmlPreviewPluginPrivate *d = nullptr;
};
} // namespace Internal
} // namespace QmlPreview
Q_DECLARE_METATYPE(QmlPreview::QmlPreviewFileLoader)

View File

@@ -52,6 +52,8 @@ QmlPreviewRunner::QmlPreviewRunner(const QmlPreviewRunnerSetting &settings)
m_connectionManager.setFileLoader(settings.fileLoader);
m_connectionManager.setFileClassifier(settings.fileClassifier);
m_connectionManager.setFpsHandler(settings.fpsHandler);
m_connectionManager.setQmlDebugTranslationClientCreator(
settings.createDebugTranslationClientMethod);
connect(this, &QmlPreviewRunner::loadFile,
&m_connectionManager, &Internal::QmlPreviewConnectionManager::loadFile);
@@ -62,8 +64,6 @@ QmlPreviewRunner::QmlPreviewRunner(const QmlPreviewRunnerSetting &settings)
&m_connectionManager, &Internal::QmlPreviewConnectionManager::zoom);
connect(this, &QmlPreviewRunner::language,
&m_connectionManager, &Internal::QmlPreviewConnectionManager::language);
connect(this, &QmlPreviewRunner::changeElideWarning,
&m_connectionManager, &Internal::QmlPreviewConnectionManager::changeElideWarning);
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
this, [this, settings]() {
@@ -71,8 +71,6 @@ QmlPreviewRunner::QmlPreviewRunner(const QmlPreviewRunnerSetting &settings)
emit zoom(settings.zoom);
if (!settings.language.isEmpty())
emit language(settings.language);
if (settings.translationElideWarning)
emit changeElideWarning(true);
emit ready();
});

View File

@@ -39,7 +39,7 @@ struct QmlPreviewRunnerSetting {
QmlPreviewFpsHandler fpsHandler;
float zoom = 1.0;
QString language;
bool translationElideWarning = false;
QmlDebugTranslationClientCreator createDebugTranslationClientMethod;
};
class QmlPreviewRunner : public ProjectExplorer::RunWorker
@@ -59,7 +59,6 @@ signals:
void zoom(float zoomFactor);
void rerun();
void ready();
void changeElideWarning(bool elideWarning);
private:
void start() override;
void stop() override;

View File

@@ -29,7 +29,6 @@
#include <QtTest>
namespace QmlPreview {
namespace Internal {
class TestableQmlPreviewClient : public QmlPreviewClient
{
@@ -139,7 +138,6 @@ void QmlPreviewClientTest::testMessageReceived()
}
}
} // namespace Internal
} // namespace QmlPreview
#include "qmlpreviewclient_test.moc"

View File

@@ -26,7 +26,6 @@
#include <QObject>
namespace QmlPreview {
namespace Internal {
class QmlPreviewClientTest : public QObject
{
@@ -39,5 +38,4 @@ private slots:
void testMessageReceived();
};
} // namespace Internal
} // namespace QmlPreview

View File

@@ -31,11 +31,10 @@
#include <QtTest>
#include <QVariant>
Q_DECLARE_METATYPE(QmlPreview::Internal::TestFileLoader)
Q_DECLARE_METATYPE(QmlPreview::Internal::TestFpsHandler)
Q_DECLARE_METATYPE(QmlPreview::TestFileLoader)
Q_DECLARE_METATYPE(QmlPreview::TestFpsHandler)
namespace QmlPreview {
namespace Internal {
QmlPreviewPluginTest::QmlPreviewPluginTest(QObject *parent) : QObject(parent)
{
@@ -90,5 +89,4 @@ void QmlPreviewPluginTest::testFpsHandlerProperty()
handler(stats);
}
} // namespace Internal
} // namespace QmlPreview

View File

@@ -28,7 +28,6 @@
#include <QObject>
namespace QmlPreview {
namespace Internal {
typedef QByteArray (*TestFileLoader)(const QString &, bool *);
typedef void (*TestFpsHandler)(quint16[8]);
@@ -45,5 +44,4 @@ private slots:
void testFpsHandlerProperty();
};
} // namespace Internal
} // namespace QmlPreview