CMakePM: Add "variable" link to CMake offline/online documentation

This way an user can find quickly a CMake variable if needed.

Change-Id: Ie885a34321cf2ce31ee662659e669de88b28801c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2022-02-03 16:52:50 +01:00
parent 4fa399fbcb
commit d408e4c22c
4 changed files with 40 additions and 28 deletions

View File

@@ -494,8 +494,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
auto handleOptionsLink = [this](const QString &link) { auto handleOptionsLink = [this](const QString &link) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfiguration->target()->kit()); const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfiguration->target()->kit());
if (tool) CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options");
tool->openCMakeHelpUrl("%1/manual/cmake.1.html#options");
}; };
connect(bc->aspect<InitialCMakeArgumentsAspect>(), connect(bc->aspect<InitialCMakeArgumentsAspect>(),
&Utils::BaseAspect::labelLinkActivated, &Utils::BaseAspect::labelLinkActivated,
@@ -518,10 +517,14 @@ void CMakeBuildSettingsWidget::batchEditConfiguration()
auto editor = new QPlainTextEdit(dialog); auto editor = new QPlainTextEdit(dialog);
auto label = new QLabel(dialog); auto label = new QLabel(dialog);
label->setText(tr("Enter one CMake variable per line.\n" label->setText(tr("Enter one CMake <a href=\"variable\">variable</a> per line.<br/>"
"To set or change a variable, use -D<variable>:<type>=<value>.\n" "To set or change a variable, use -D&lt;variable&gt;:&lt;type&gt;=&lt;value&gt;.<br/>"
"<type> can have one of the following values: FILEPATH, PATH, BOOL, INTERNAL, or STRING.\n" "&lt;type&gt; can have one of the following values: FILEPATH, PATH, BOOL, INTERNAL, or STRING.<br/>"
"To unset a variable, use -U<variable>.\n")); "To unset a variable, use -U&lt;variable&gt;.<br/>"));
connect(label, &QLabel::linkActivated, this, [this](const QString &link) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(m_buildConfiguration->target()->kit());
CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake-variables.7.html");
});
editor->setMinimumSize(800, 200); editor->setMinimumSize(800, 200);
auto chooser = new Utils::VariableChooser(dialog); auto chooser = new Utils::VariableChooser(dialog);

View File

@@ -925,15 +925,20 @@ private:
QTC_ASSERT(!m_editor, return); QTC_ASSERT(!m_editor, return);
const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit());
m_dialog = new QDialog(m_summaryLabel->window()); m_dialog = new QDialog(m_summaryLabel->window());
m_dialog->setWindowTitle(tr("Edit CMake Configuration")); m_dialog->setWindowTitle(tr("Edit CMake Configuration"));
auto layout = new QVBoxLayout(m_dialog); auto layout = new QVBoxLayout(m_dialog);
m_editor = new QPlainTextEdit; m_editor = new QPlainTextEdit;
auto editorLabel = new QLabel(m_dialog); auto editorLabel = new QLabel(m_dialog);
editorLabel->setText(tr("Enter one CMake variable per line.\n" editorLabel->setText(tr("Enter one CMake <a href=\"variable\">variable</a> per line.<br/>"
"To set a variable, use -D<variable>:<type>=<value>.\n" "To set a variable, use -D&lt;variable&gt;:&lt;type&gt;=&lt;value&gt;.<br/>"
"<type> can have one of the following values: FILEPATH, PATH, " "&lt;type&gt; can have one of the following values: FILEPATH, PATH, "
"BOOL, INTERNAL, or STRING.")); "BOOL, INTERNAL, or STRING."));
connect(editorLabel, &QLabel::linkActivated, this, [=](const QString &link) {
CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake-variables.7.html");
});
m_editor->setMinimumSize(800, 200); m_editor->setMinimumSize(800, 200);
auto chooser = new VariableChooser(m_dialog); auto chooser = new VariableChooser(m_dialog);
@@ -943,10 +948,8 @@ private:
m_additionalEditor = new QLineEdit; m_additionalEditor = new QLineEdit;
auto additionalLabel = new QLabel(m_dialog); auto additionalLabel = new QLabel(m_dialog);
additionalLabel->setText(tr("Additional CMake <a href=\"options\">options</a>:")); additionalLabel->setText(tr("Additional CMake <a href=\"options\">options</a>:"));
connect(additionalLabel, &QLabel::linkActivated, this, [this](const QString &link) { connect(additionalLabel, &QLabel::linkActivated, this, [=](const QString &link) {
const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit()); CMakeTool::openCMakeHelpUrl(tool, "%1/manual/cmake.1.html#options");
if (tool)
tool->openCMakeHelpUrl("%1/manual/cmake.1.html#options");
}); });
auto additionalChooser = new VariableChooser(m_dialog); auto additionalChooser = new VariableChooser(m_dialog);

View File

@@ -382,26 +382,32 @@ FilePath CMakeTool::searchQchFile(const FilePath &executable)
return {}; return {};
} }
QString CMakeTool::documentationUrl(bool online) const QString CMakeTool::documentationUrl(const Version &version, bool online)
{ {
if (online) if (online) {
return QString("https://cmake.org/cmake/help/v%1.%2") QString helpVersion = "latest";
.arg(version().major) if (!(version.major == 0 && version.minor == 0))
.arg(version().minor); helpVersion = QString("v%1.%2").arg(version.major).arg(version.minor);
return QString("https://cmake.org/cmake/help/%1").arg(helpVersion);
}
return QString("qthelp://org.cmake.%1.%2.%3/doc") return QString("qthelp://org.cmake.%1.%2.%3/doc")
.arg(version().major) .arg(version.major)
.arg(version().minor) .arg(version.minor)
.arg(version().patch); .arg(version.patch);
} }
void CMakeTool::openCMakeHelpUrl(const QString &linkUrl) const void CMakeTool::openCMakeHelpUrl(const CMakeTool *tool, const QString &linkUrl)
{ {
if (!isValid()) bool online = true;
return; Version version;
if (tool && tool->isValid()) {
online = tool->qchFilePath().isEmpty();
version = tool->version();
}
const bool online = qchFilePath().isEmpty(); Core::HelpManager::showHelpUrl(linkUrl.arg(documentationUrl(version, online)));
Core::HelpManager::showHelpUrl(linkUrl.arg(documentationUrl(online)));
} }
void CMakeTool::readInformation() const void CMakeTool::readInformation() const

View File

@@ -112,8 +112,8 @@ public:
QString detectionSource() const { return m_detectionSource; } QString detectionSource() const { return m_detectionSource; }
void setDetectionSource(const QString &source) { m_detectionSource = source; } void setDetectionSource(const QString &source) { m_detectionSource = source; }
QString documentationUrl(bool online) const; static QString documentationUrl(const Version &version, bool online);
void openCMakeHelpUrl(const QString &linkUrl) const; static void openCMakeHelpUrl(const CMakeTool *tool, const QString &linkUrl);
private: private:
void readInformation() const; void readInformation() const;