forked from qt-creator/qt-creator
CMake: Make use of CMake-provided .qch files
* Have UI to select a .qch file location in CMake Tool setup * Auto-detect CMake's .qch file in its default location (relative to the cmake executable) * Register the .qch files with the HelpManager Task-number: QTCREATORBUG-21338 Change-Id: I4057eec42c39535012d9f0daf788fc62ef20d544 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -69,13 +69,22 @@ public:
|
||||
|
||||
CMakeToolTreeItem *cmakeToolItem(const Core::Id &id) const;
|
||||
CMakeToolTreeItem *cmakeToolItem(const QModelIndex &index) const;
|
||||
QModelIndex addCMakeTool(const QString &name, const FilePath &executable, const bool autoRun, const bool autoCreate, const bool isAutoDetected);
|
||||
QModelIndex addCMakeTool(const QString &name,
|
||||
const FilePath &executable,
|
||||
const FilePath &qchFile,
|
||||
const bool autoRun,
|
||||
const bool autoCreate,
|
||||
const bool isAutoDetected);
|
||||
void addCMakeTool(const CMakeTool *item, bool changed);
|
||||
TreeItem *autoGroupItem() const;
|
||||
TreeItem *manualGroupItem() const;
|
||||
void reevaluateChangedFlag(CMakeToolTreeItem *item) const;
|
||||
void updateCMakeTool(const Core::Id &id, const QString &displayName, const FilePath &executable,
|
||||
bool autoRun, bool autoCreate);
|
||||
void updateCMakeTool(const Core::Id &id,
|
||||
const QString &displayName,
|
||||
const FilePath &executable,
|
||||
const FilePath &qchFile,
|
||||
bool autoRun,
|
||||
bool autoCreate);
|
||||
void removeCMakeTool(const Core::Id &id);
|
||||
void apply();
|
||||
|
||||
@@ -97,6 +106,7 @@ public:
|
||||
: m_id(item->id())
|
||||
, m_name(item->displayName())
|
||||
, m_executable(item->filePath())
|
||||
, m_qchFile(item->qchFilePath())
|
||||
, m_isAutoRun(item->isAutoRun())
|
||||
, m_autoCreateBuildDirectory(item->autoCreateBuildDirectory())
|
||||
, m_autodetected(item->isAutoDetected())
|
||||
@@ -111,12 +121,14 @@ public:
|
||||
|
||||
CMakeToolTreeItem(const QString &name,
|
||||
const Utils::FilePath &executable,
|
||||
const FilePath &qchFile,
|
||||
bool autoRun,
|
||||
bool autoCreate,
|
||||
bool autodetected)
|
||||
: m_id(Core::Id::fromString(QUuid::createUuid().toString()))
|
||||
, m_name(name)
|
||||
, m_executable(executable)
|
||||
, m_qchFile(qchFile)
|
||||
, m_isAutoRun(autoRun)
|
||||
, m_autoCreateBuildDirectory(autoCreate)
|
||||
, m_autodetected(autodetected)
|
||||
@@ -197,6 +209,7 @@ public:
|
||||
QString m_name;
|
||||
QString m_tooltip;
|
||||
FilePath m_executable;
|
||||
FilePath m_qchFile;
|
||||
bool m_isAutoRun = true;
|
||||
bool m_pathExists = false;
|
||||
bool m_pathIsFile = false;
|
||||
@@ -224,11 +237,14 @@ CMakeToolItemModel::CMakeToolItemModel()
|
||||
|
||||
}
|
||||
|
||||
QModelIndex CMakeToolItemModel::addCMakeTool(const QString &name, const FilePath &executable,
|
||||
const bool autoRun, const bool autoCreate,
|
||||
QModelIndex CMakeToolItemModel::addCMakeTool(const QString &name,
|
||||
const FilePath &executable,
|
||||
const FilePath &qchFile,
|
||||
const bool autoRun,
|
||||
const bool autoCreate,
|
||||
const bool isAutoDetected)
|
||||
{
|
||||
auto item = new CMakeToolTreeItem(name, executable, autoRun, autoCreate, isAutoDetected);
|
||||
auto item = new CMakeToolTreeItem(name, executable, qchFile, autoRun, autoCreate, isAutoDetected);
|
||||
if (isAutoDetected)
|
||||
autoGroupItem()->appendChild(item);
|
||||
else
|
||||
@@ -265,7 +281,8 @@ void CMakeToolItemModel::reevaluateChangedFlag(CMakeToolTreeItem *item) const
|
||||
{
|
||||
CMakeTool *orig = CMakeToolManager::findById(item->m_id);
|
||||
item->m_changed = !orig || orig->displayName() != item->m_name
|
||||
|| orig->filePath() != item->m_executable;
|
||||
|| orig->filePath() != item->m_executable
|
||||
|| orig->qchFilePath() != item->m_qchFile;
|
||||
|
||||
//make sure the item is marked as changed when the default cmake was changed
|
||||
CMakeTool *origDefTool = CMakeToolManager::defaultCMakeTool();
|
||||
@@ -278,8 +295,11 @@ void CMakeToolItemModel::reevaluateChangedFlag(CMakeToolTreeItem *item) const
|
||||
item->update(); // Notify views.
|
||||
}
|
||||
|
||||
void CMakeToolItemModel::updateCMakeTool(const Core::Id &id, const QString &displayName,
|
||||
const FilePath &executable, bool autoRun,
|
||||
void CMakeToolItemModel::updateCMakeTool(const Core::Id &id,
|
||||
const QString &displayName,
|
||||
const FilePath &executable,
|
||||
const FilePath &qchFile,
|
||||
bool autoRun,
|
||||
bool autoCreate)
|
||||
{
|
||||
CMakeToolTreeItem *treeItem = cmakeToolItem(id);
|
||||
@@ -287,6 +307,7 @@ void CMakeToolItemModel::updateCMakeTool(const Core::Id &id, const QString &disp
|
||||
|
||||
treeItem->m_name = displayName;
|
||||
treeItem->m_executable = executable;
|
||||
treeItem->m_qchFile = qchFile;
|
||||
treeItem->m_isAutoRun = autoRun;
|
||||
treeItem->m_autoCreateBuildDirectory = autoCreate;
|
||||
|
||||
@@ -328,6 +349,7 @@ void CMakeToolItemModel::apply()
|
||||
if (CMakeTool *cmake = CMakeToolManager::findById(item->m_id)) {
|
||||
cmake->setDisplayName(item->m_name);
|
||||
cmake->setFilePath(item->m_executable);
|
||||
cmake->setQchFilePath(item->m_qchFile);
|
||||
cmake->setAutorun(item->m_isAutoRun);
|
||||
cmake->setAutoCreateBuildDirectory(item->m_autoCreateBuildDirectory);
|
||||
} else {
|
||||
@@ -341,6 +363,7 @@ void CMakeToolItemModel::apply()
|
||||
auto cmake = std::make_unique<CMakeTool>(detection, item->m_id);
|
||||
cmake->setDisplayName(item->m_name);
|
||||
cmake->setFilePath(item->m_executable);
|
||||
cmake->setQchFilePath(item->m_qchFile);
|
||||
if (!CMakeToolManager::registerCMakeTool(std::move(cmake)))
|
||||
item->m_changed = true;
|
||||
}
|
||||
@@ -392,11 +415,14 @@ public:
|
||||
void store() const;
|
||||
|
||||
private:
|
||||
void updateQchFilePath();
|
||||
|
||||
CMakeToolItemModel *m_model;
|
||||
QLineEdit *m_displayNameLineEdit;
|
||||
QCheckBox *m_autoRunCheckBox;
|
||||
QCheckBox *m_autoCreateBuildDirectoryCheckBox;
|
||||
PathChooser *m_binaryChooser;
|
||||
PathChooser *m_qchFileChooser;
|
||||
Core::Id m_id;
|
||||
bool m_loadingItem;
|
||||
};
|
||||
@@ -412,6 +438,13 @@ CMakeToolItemConfigWidget::CMakeToolItemConfigWidget(CMakeToolItemModel *model)
|
||||
m_binaryChooser->setHistoryCompleter(QLatin1String("Cmake.Command.History"));
|
||||
m_binaryChooser->setCommandVersionArguments({"--version"});
|
||||
|
||||
m_qchFileChooser = new PathChooser(this);
|
||||
m_qchFileChooser->setExpectedKind(PathChooser::File);
|
||||
m_qchFileChooser->setMinimumWidth(400);
|
||||
m_qchFileChooser->setHistoryCompleter(QLatin1String("Cmake.qchFile.History"));
|
||||
m_qchFileChooser->setPromptDialogFilter("*.qch");
|
||||
m_qchFileChooser->setPromptDialogTitle(tr("CMake .qch File"));
|
||||
|
||||
m_autoRunCheckBox = new QCheckBox;
|
||||
m_autoRunCheckBox->setText(tr("Autorun CMake"));
|
||||
m_autoRunCheckBox->setToolTip(tr("Automatically run CMake after changes to CMake project files."));
|
||||
@@ -424,13 +457,17 @@ CMakeToolItemConfigWidget::CMakeToolItemConfigWidget(CMakeToolItemModel *model)
|
||||
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
formLayout->addRow(new QLabel(tr("Name:")), m_displayNameLineEdit);
|
||||
formLayout->addRow(new QLabel(tr("Path:")), m_binaryChooser);
|
||||
formLayout->addRow(new QLabel(tr("Help File:")), m_qchFileChooser);
|
||||
formLayout->addRow(m_autoRunCheckBox);
|
||||
formLayout->addRow(m_autoCreateBuildDirectoryCheckBox);
|
||||
|
||||
connect(m_binaryChooser, &PathChooser::rawPathChanged,
|
||||
this, &CMakeToolItemConfigWidget::store);
|
||||
connect(m_displayNameLineEdit, &QLineEdit::textChanged,
|
||||
this, &CMakeToolItemConfigWidget::store);
|
||||
connect(m_binaryChooser, &PathChooser::rawPathChanged, this, [this]() {
|
||||
updateQchFilePath();
|
||||
m_qchFileChooser->setBaseFileName(m_binaryChooser->fileName().parentDir());
|
||||
store();
|
||||
});
|
||||
connect(m_qchFileChooser, &PathChooser::rawPathChanged, this, &CMakeToolItemConfigWidget::store);
|
||||
connect(m_displayNameLineEdit, &QLineEdit::textChanged, this, &CMakeToolItemConfigWidget::store);
|
||||
connect(m_autoRunCheckBox, &QCheckBox::toggled,
|
||||
this, &CMakeToolItemConfigWidget::store);
|
||||
connect(m_autoCreateBuildDirectoryCheckBox, &QCheckBox::toggled,
|
||||
@@ -440,11 +477,20 @@ CMakeToolItemConfigWidget::CMakeToolItemConfigWidget(CMakeToolItemModel *model)
|
||||
void CMakeToolItemConfigWidget::store() const
|
||||
{
|
||||
if (!m_loadingItem && m_id.isValid())
|
||||
m_model->updateCMakeTool(m_id, m_displayNameLineEdit->text(), m_binaryChooser->fileName(),
|
||||
m_model->updateCMakeTool(m_id,
|
||||
m_displayNameLineEdit->text(),
|
||||
m_binaryChooser->fileName(),
|
||||
m_qchFileChooser->fileName(),
|
||||
m_autoRunCheckBox->checkState() == Qt::Checked,
|
||||
m_autoCreateBuildDirectoryCheckBox->checkState() == Qt::Checked);
|
||||
}
|
||||
|
||||
void CMakeToolItemConfigWidget::updateQchFilePath()
|
||||
{
|
||||
if (m_qchFileChooser->fileName().isEmpty())
|
||||
m_qchFileChooser->setFileName(CMakeTool::searchQchFile(m_binaryChooser->fileName()));
|
||||
}
|
||||
|
||||
void CMakeToolItemConfigWidget::load(const CMakeToolTreeItem *item)
|
||||
{
|
||||
m_loadingItem = true; // avoid intermediate signal handling
|
||||
@@ -461,6 +507,10 @@ void CMakeToolItemConfigWidget::load(const CMakeToolTreeItem *item)
|
||||
m_binaryChooser->setReadOnly(item->m_autodetected);
|
||||
m_binaryChooser->setFileName(item->m_executable);
|
||||
|
||||
m_qchFileChooser->setReadOnly(item->m_autodetected);
|
||||
m_qchFileChooser->setBaseFileName(item->m_executable.parentDir());
|
||||
m_qchFileChooser->setFileName(item->m_qchFile);
|
||||
|
||||
m_autoRunCheckBox->setChecked(item->m_isAutoRun);
|
||||
m_autoCreateBuildDirectoryCheckBox->setChecked(item->m_autoCreateBuildDirectory);
|
||||
|
||||
@@ -568,8 +618,10 @@ void CMakeToolConfigWidget::cloneCMakeTool()
|
||||
|
||||
QModelIndex newItem = m_model.addCMakeTool(tr("Clone of %1").arg(m_currentItem->m_name),
|
||||
m_currentItem->m_executable,
|
||||
m_currentItem->m_qchFile,
|
||||
m_currentItem->m_isAutoRun,
|
||||
m_currentItem->m_autoCreateBuildDirectory, false);
|
||||
m_currentItem->m_autoCreateBuildDirectory,
|
||||
false);
|
||||
|
||||
m_cmakeToolsView->setCurrentIndex(newItem);
|
||||
}
|
||||
@@ -577,7 +629,11 @@ void CMakeToolConfigWidget::cloneCMakeTool()
|
||||
void CMakeToolConfigWidget::addCMakeTool()
|
||||
{
|
||||
QModelIndex newItem = m_model.addCMakeTool(m_model.uniqueDisplayName(tr("New CMake")),
|
||||
FilePath(), true, false, false);
|
||||
FilePath(),
|
||||
FilePath(),
|
||||
true,
|
||||
false,
|
||||
false);
|
||||
|
||||
m_cmakeToolsView->setCurrentIndex(newItem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user