forked from qt-creator/qt-creator
CMake: Add CMakeConfigurationKitInformation
Add CMakeConfigurationKitInformation and supporting classes. This KitInformation can hold CMake settings that are to be applied for all configurations when this kit is used. It contains e.g. the Qt version and toolchain configured in the kit by default, but can be extended to hold more. The UI will warn if the toolchain or Qt version set up in CMake does not match up with those used by the Kit, but it will allow the user to proceed. Change-Id: I73f06a6535ce14de323130d74af83b9cb2ec0f0f Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com> Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -33,9 +33,15 @@
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
@@ -263,5 +269,114 @@ QString CMakeGeneratorKitConfigWidget::toolTip() const
|
||||
"This setting is ignored when using other build systems.");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// CMakeConfigurationKitConfigWidget:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
CMakeConfigurationKitConfigWidget::CMakeConfigurationKitConfigWidget(Kit *kit,
|
||||
const KitInformation *ki) :
|
||||
KitConfigWidget(kit, ki),
|
||||
m_summaryLabel(new QLabel),
|
||||
m_manageButton(new QPushButton)
|
||||
{
|
||||
refresh();
|
||||
m_manageButton->setText(tr("Change..."));
|
||||
connect(m_manageButton, &QAbstractButton::clicked,
|
||||
this, &CMakeConfigurationKitConfigWidget::editConfigurationChanges);
|
||||
}
|
||||
|
||||
QString CMakeConfigurationKitConfigWidget::displayName() const
|
||||
{
|
||||
return tr("CMake Configuration");
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::makeReadOnly()
|
||||
{
|
||||
m_manageButton->setEnabled(false);
|
||||
if (m_dialog)
|
||||
m_dialog->reject();
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::refresh()
|
||||
{
|
||||
const QStringList current = CMakeConfigurationKitInformation::toStringList(kit());
|
||||
|
||||
QString shortSummary = current.join(QLatin1String("; "));
|
||||
QFontMetrics fm(m_summaryLabel->font());
|
||||
shortSummary = fm.elidedText(shortSummary, Qt::ElideRight, m_summaryLabel->width());
|
||||
m_summaryLabel->setText(current.isEmpty() ? tr("<No Changes to Apply>") : shortSummary);
|
||||
|
||||
if (m_editor)
|
||||
m_editor->setPlainText(current.join(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
QWidget *CMakeConfigurationKitConfigWidget::mainWidget() const
|
||||
{
|
||||
return m_summaryLabel;
|
||||
}
|
||||
|
||||
QWidget *CMakeConfigurationKitConfigWidget::buttonWidget() const
|
||||
{
|
||||
return m_manageButton;
|
||||
}
|
||||
|
||||
QString CMakeConfigurationKitConfigWidget::toolTip() const
|
||||
{
|
||||
return tr("Default configuration passed to CMake when setting up a project.");
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::editConfigurationChanges()
|
||||
{
|
||||
if (m_dialog) {
|
||||
m_dialog->activateWindow();
|
||||
m_dialog->raise();
|
||||
return;
|
||||
}
|
||||
|
||||
QTC_ASSERT(!m_editor, return);
|
||||
|
||||
m_dialog = new QDialog(m_summaryLabel);
|
||||
m_dialog->setWindowTitle(tr("Edit CMake Configuration"));
|
||||
QVBoxLayout *layout = new QVBoxLayout(m_dialog);
|
||||
m_editor = new QPlainTextEdit;
|
||||
m_editor->setToolTip(tr("Enter one variable per line with the variable name "
|
||||
"separated from the variable value by \"=\".<br>"
|
||||
"You may provide a type hint by adding \":TYPE\" before the \"=\"."));
|
||||
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Apply|QDialogButtonBox::Cancel);
|
||||
|
||||
layout->addWidget(m_editor);
|
||||
layout->addWidget(buttons);
|
||||
|
||||
connect(buttons, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, m_dialog, &QDialog::reject);
|
||||
connect(m_dialog, &QDialog::accepted, this, &CMakeConfigurationKitConfigWidget::acceptChangesDialog);
|
||||
connect(m_dialog, &QDialog::rejected, this, &CMakeConfigurationKitConfigWidget::closeChangesDialog);
|
||||
connect(buttons->button(QDialogButtonBox::Apply), &QAbstractButton::clicked,
|
||||
this, &CMakeConfigurationKitConfigWidget::applyChanges);
|
||||
|
||||
refresh();
|
||||
m_dialog->show();
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::applyChanges()
|
||||
{
|
||||
QTC_ASSERT(m_editor, return);
|
||||
CMakeConfigurationKitInformation::fromStringList(kit(), m_editor->toPlainText().split(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::closeChangesDialog()
|
||||
{
|
||||
m_dialog->deleteLater();
|
||||
m_dialog = nullptr;
|
||||
m_editor = nullptr;
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitConfigWidget::acceptChangesDialog()
|
||||
{
|
||||
applyChanges();
|
||||
closeChangesDialog();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
Reference in New Issue
Block a user