Commit fbb4b8d5 authored by Milian Wolff's avatar Milian Wolff

Sync CMake build type between cache and kdevelop settings

We store the cmake build type also in the kdevelo project settings
in order to recreate the build dir on demand if it gets wiped.
But when the user now manually changes it through the cmake cache
value for an existing build dir, the values could get out of sync.
Prevent that by keeping the two values in sync, i.e. once in the
list of cache values and once in the project setting drop down.

BUG: 429605
parent e3ddd046
......@@ -146,7 +146,9 @@ bool CMakeCacheModel::setData(const QModelIndex& index, const QVariant& value, i
{
bool ret = QStandardItemModel::setData(index, value, role);
if (ret) {
m_modifiedRows.insert(index.row());
const auto i = index.row();
m_modifiedRows.insert(i);
emit valueChanged(item(i, 0)->text(), item(i, 2)->text());
}
return ret;
}
......
......@@ -51,7 +51,10 @@ class CMakeCacheModel : public QStandardItemModel
KDevelop::Path filePath() const;
void read();
QVariantMap changedValues() const;
Q_SIGNALS:
void valueChanged(const QString& name, const QString& value) const;
public Q_SLOTS:
void reset();
......
......@@ -114,13 +114,20 @@ void CMakePreferences::initAdvanced()
m_prefsUi->environment->setCurrentProfile( CMake::currentEnvironment(m_project) );
m_prefsUi->installationPrefix->setText(CMake::currentInstallDir(m_project).toLocalFile());
m_prefsUi->installationPrefix->setMode(KFile::Directory);
const QString buildType = CMake::currentBuildType(m_project);
setBuildType(CMake::currentBuildType(m_project));
m_prefsUi->extraArguments->setEditText(CMake::currentExtraArguments(m_project));
m_prefsUi->cMakeExecutable->setText(CMake::currentCMakeExecutable(m_project).toLocalFile());
}
void CMakePreferences::setBuildType(const QString& buildType)
{
if (m_prefsUi->buildType->currentText() == buildType)
return;
if (m_prefsUi->buildType->findText(buildType) == -1) {
m_prefsUi->buildType->addItem(buildType);
}
m_prefsUi->buildType->setCurrentIndex(m_prefsUi->buildType->findText(buildType));
m_prefsUi->extraArguments->setEditText(CMake::currentExtraArguments(m_project));
m_prefsUi->cMakeExecutable->setText(CMake::currentCMakeExecutable(m_project).toLocalFile());
}
void CMakePreferences::reset()
......@@ -158,10 +165,7 @@ void CMakePreferences::apply()
CMake::setCurrentInstallDir( m_project, Path(m_prefsUi->installationPrefix->text()) );
const QString buildType = m_prefsUi->buildType->currentText();
if (m_prefsUi->buildType->findText(buildType) == -1) {
m_prefsUi->buildType->addItem(buildType);
}
CMake::setCurrentBuildType( m_project, buildType );
CMake::setCurrentBuildType(m_project, buildType);
CMake::setCurrentExtraArguments( m_project, m_prefsUi->extraArguments->currentText() );
CMake::setCurrentCMakeExecutable( m_project, Path(m_prefsUi->cMakeExecutable->text()) );
......@@ -223,6 +227,20 @@ void CMakePreferences::updateCache(const Path &newBuildDir)
this, &CMakePreferences::configureCacheView);
connect(m_prefsUi->cacheList->selectionModel(), &QItemSelectionModel::currentChanged,
this, &CMakePreferences::listSelectionChanged);
connect(m_currentModel, &CMakeCacheModel::valueChanged, this,
[this](const QString& name, const QString& value) {
if (name == QLatin1String("CMAKE_BUILD_TYPE")) {
setBuildType(value);
}
});
connect(m_prefsUi->buildType, &QComboBox::currentTextChanged, m_currentModel, [this](const QString& value) {
if (!m_currentModel)
return;
const auto items = m_currentModel->findItems(QStringLiteral("CMAKE_BUILD_TYPE"));
for (auto* item : items) {
m_currentModel->setData(m_currentModel->index(item->row(), 2), value);
}
});
}
else
{
......
......@@ -64,7 +64,8 @@ class CMakePreferences : public KDevelop::ConfigPage
private:
void configure();
void initAdvanced();
void setBuildType(const QString& buildType);
KDevelop::IProject* m_project;
KDevelop::Path m_srcFolder;
KDevelop::Path m_subprojFolder;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment