CMake: Apply build directory change on editingFinished

Otherwise every time a character is typed, a dialog pops up, and that
dialog is closed without triggering a cmake run, the value is reset.

Add that behavior optionally to StringAspect.

Change-Id: I6831d1622f08acae6df43d4ceb2bf7367c96a747
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Eike Ziller
2021-06-22 13:54:16 +02:00
parent e13c2b7403
commit 1d600101ee
3 changed files with 39 additions and 5 deletions

View File

@@ -658,6 +658,10 @@ public:
bool m_showToolTipOnLabel = false;
bool m_fileDialogOnly = false;
bool m_useResetButton = false;
bool m_autoApplyOnEditingFinished = false;
// Used to block recursive editingFinished signals for example when return is pressed, and
// the validation changes focus by opening a dialog
bool m_blockAutoApply = false;
template<class Widget> void updateWidgetFromCheckStatus(StringAspect *aspect, Widget *w)
{
@@ -1015,6 +1019,11 @@ void StringAspect::setOpenTerminalHandler(const std::function<void ()> &openTerm
d->m_pathChooserDisplay->setOpenTerminalHandler(openTerminal);
}
void StringAspect::setAutoApplyOnEditingFinished(bool applyOnEditingFinished)
{
d->m_autoApplyOnEditingFinished = applyOnEditingFinished;
}
void StringAspect::validateInput()
{
if (d->m_pathChooserDisplay)
@@ -1059,8 +1068,19 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
addLabeledItem(builder, d->m_pathChooserDisplay);
useMacroExpander(d->m_pathChooserDisplay->lineEdit());
if (isAutoApply()) {
connect(d->m_pathChooserDisplay, &PathChooser::pathChanged, this, [this] {
setValue(d->m_pathChooserDisplay->path()); });
if (d->m_autoApplyOnEditingFinished) {
connect(d->m_pathChooserDisplay, &PathChooser::editingFinished, this, [this] {
if (d->m_blockAutoApply)
return;
d->m_blockAutoApply = true;
setValue(d->m_pathChooserDisplay->path());
d->m_blockAutoApply = false;
});
} else {
connect(d->m_pathChooserDisplay, &PathChooser::pathChanged, this, [this] {
setValue(d->m_pathChooserDisplay->path());
});
}
}
break;
case LineEditDisplay:
@@ -1075,8 +1095,20 @@ void StringAspect::addToLayout(LayoutBuilder &builder)
addLabeledItem(builder, d->m_lineEditDisplay);
useMacroExpander(d->m_lineEditDisplay);
if (isAutoApply()) {
connect(d->m_lineEditDisplay, &FancyLineEdit::textEdited,
this, &StringAspect::setValue);
if (d->m_autoApplyOnEditingFinished) {
connect(d->m_lineEditDisplay, &FancyLineEdit::editingFinished, this, [this] {
if (d->m_blockAutoApply)
return;
d->m_blockAutoApply = true;
setValue(d->m_lineEditDisplay->text());
d->m_blockAutoApply = false;
});
} else {
connect(d->m_lineEditDisplay,
&FancyLineEdit::textEdited,
this,
&StringAspect::setValue);
}
}
if (d->m_useResetButton) {
auto resetButton = createSubWidget<QPushButton>(tr("Reset"));

View File

@@ -307,6 +307,7 @@ public:
void setUseResetButton();
void setValidationFunction(const Utils::FancyLineEdit::ValidationFunction &validator);
void setOpenTerminalHandler(const std::function<void()> &openTerminal);
void setAutoApplyOnEditingFinished(bool applyOnEditingFinished);
void validateInput();

View File

@@ -182,6 +182,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
container->setWidget(details);
auto buildDirAspect = bc->buildDirectoryAspect();
buildDirAspect->setAutoApplyOnEditingFinished(true);
connect(buildDirAspect, &BaseAspect::changed, this, [this]() {
m_configModel->flush(); // clear out config cache...;
});
@@ -851,7 +852,7 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Id id)
return newDir;
if (QDir(oldDir).exists("CMakeCache.txt") && !QDir(newDir).exists("CMakeCache.txt")) {
if (QMessageBox::information(nullptr,
if (QMessageBox::information(Core::ICore::dialogParent(),
tr("Changing Build Directory"),
tr("Change the build directory and start with a "
"basic CMake configuration?"),