Commit d56117d6 authored by René J.V. Bertin's avatar René J.V. Bertin

advanced configuration settings for the CMake ProjectManager

Introduces the equivalent of all fields available when first creating a
CMake project in the project configuration dialog,
under the CMake/Advanced button.

REVIEW: 129416
parent 752a4101
......@@ -27,6 +27,7 @@ set( cmakecommon_SRCS
# parser/cmakeduchaintypes.cpp
# parser/generationexpressionsolver.cpp
cmakeutils.cpp
cmakeextraargumentshistory.cpp
cmakebuilddirchooser.cpp
debug.cpp
......
......@@ -37,12 +37,6 @@
using namespace KDevelop;
namespace {
const int maxExtraArgumentsInHistory = 15;
}
CMakeBuildDirChooser::CMakeBuildDirChooser(QWidget* parent)
: QDialog(parent)
{
......@@ -67,14 +61,7 @@ CMakeBuildDirChooser::CMakeBuildDirChooser(QWidget* parent)
setCMakeBinary(Path(CMake::findExecutable()));
KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser");
QStringList lastExtraArguments = config.readEntry("LastExtraArguments", QStringList());;
m_chooserUi->extraArguments->addItem("");
m_chooserUi->extraArguments->addItems(lastExtraArguments);
m_chooserUi->extraArguments->setInsertPolicy(QComboBox::InsertAtTop);
KCompletion *comp = m_chooserUi->extraArguments->completionObject();
connect(m_chooserUi->extraArguments, static_cast<void(KComboBox::*)(const QString&)>(&KComboBox::returnPressed), comp, static_cast<void(KCompletion::*)(const QString&)>(&KCompletion::addItem));
comp->insertItems(lastExtraArguments);
m_extraArgumentsHistory = new CMakeExtraArgumentsHistory(m_chooserUi->extraArguments);
connect(m_chooserUi->cmakeBin, &KUrlRequester::textChanged, this, &CMakeBuildDirChooser::updated);
connect(m_chooserUi->buildFolder, &KUrlRequester::textChanged, this, &CMakeBuildDirChooser::updated);
......@@ -86,9 +73,7 @@ CMakeBuildDirChooser::CMakeBuildDirChooser(QWidget* parent)
CMakeBuildDirChooser::~CMakeBuildDirChooser()
{
KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser");
config.writeEntry("LastExtraArguments", extraArgumentsHistory());
config.sync();
delete m_extraArgumentsHistory;
delete m_chooserUi;
}
......@@ -324,20 +309,3 @@ Path CMakeBuildDirChooser::buildFolder() const { return Path(m_chooserUi->buildF
QString CMakeBuildDirChooser::buildType() const { return m_chooserUi->buildType->currentText(); }
QString CMakeBuildDirChooser::extraArguments() const { return m_chooserUi->extraArguments->currentText(); }
QStringList CMakeBuildDirChooser::extraArgumentsHistory() const
{
QStringList list;
KComboBox* extraArguments = m_chooserUi->extraArguments;
if (!extraArguments->currentText().isEmpty()) {
list << extraArguments->currentText();
}
for (int i = 0; i < qMin(maxExtraArgumentsInHistory, extraArguments->count()); ++i) {
if (!extraArguments->itemText(i).isEmpty() &&
(extraArguments->currentText() != extraArguments->itemText(i))) {
list << extraArguments->itemText(i);
}
}
return list;
}
......@@ -26,6 +26,7 @@
#include <util/path.h>
#include "cmakeextraargumentshistory.h"
#include "cmakecommonexport.h"
class QDialogButtonBox;
......@@ -76,7 +77,8 @@ class KDEVCMAKECOMMON_EXPORT CMakeBuildDirChooser : public QDialog
QString& srcDir,
QString& installDir,
QString& buildType);
QStringList extraArgumentsHistory() const;
CMakeExtraArgumentsHistory* m_extraArgumentsHistory;
Ui::CMakeBuildDirChooser* m_chooserUi;
QDialogButtonBox* m_buttonBox;
......
/* KDevelop CMake Support
*
* Copyright 2016 René J.V. Bertin <rjvbertin@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <QObject>
#include <KSharedConfig>
#include <KConfigGroup>
#include "cmakeextraargumentshistory.h"
namespace {
const int maxExtraArgumentsInHistory = 15;
}
CMakeExtraArgumentsHistory::CMakeExtraArgumentsHistory(KComboBox* widget)
: m_arguments(widget)
{
if (m_arguments) {
KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser");
QStringList lastExtraArguments = config.readEntry("LastExtraArguments", QStringList());;
m_arguments->addItem("");
m_arguments->addItems(lastExtraArguments);
m_arguments->setInsertPolicy(QComboBox::InsertAtTop);
KCompletion *comp = m_arguments->completionObject();
KComboBox::connect(m_arguments, static_cast<void(KComboBox::*)(const QString&)>(&KComboBox::returnPressed),
comp, static_cast<void(KCompletion::*)(const QString&)>(&KCompletion::addItem));
comp->insertItems(lastExtraArguments);
} else {
qFatal("CMakeExtraArgumentsHistory initialised with invalid widget");
}
}
CMakeExtraArgumentsHistory::~CMakeExtraArgumentsHistory()
{
KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser");
config.writeEntry("LastExtraArguments", list());
config.sync();
}
QStringList CMakeExtraArgumentsHistory::list() const
{
QStringList list;
if (!m_arguments->currentText().isEmpty()) {
list << m_arguments->currentText();
}
for (int i = 0; i < qMin(maxExtraArgumentsInHistory, m_arguments->count()); ++i) {
if (!m_arguments->itemText(i).isEmpty() &&
(m_arguments->currentText() != m_arguments->itemText(i))) {
list << m_arguments->itemText(i);
}
}
return list;
}
/* KDevelop CMake Support
*
* Copyright 2016 René J.V. Bertin <rjvbertin@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef CMAKEEXTRAARGUMENTS_H
#define CMAKEEXTRAARGUMENTS_H
#include <QString>
#include <QStringList>
#include <KComboBox>
#include "cmakecommonexport.h"
namespace Ui {
class CMakeExtraArgumentsHistory;
}
/**
* This class augments CMake's extra arguments widget with a history feature.
* @author René Bertin
*/
class KDEVCMAKECOMMON_EXPORT CMakeExtraArgumentsHistory
{
public:
CMakeExtraArgumentsHistory(KComboBox* widget);
~CMakeExtraArgumentsHistory();
QStringList list() const;
private:
KComboBox* m_arguments;
};
#endif
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>605</width>
<height>537</height>
<height>547</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -110,14 +110,78 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="installationPrefixLabel">
<property name="text">
<string>Installation Prefix</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KUrlRequester" name="installationPrefix"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="buildTypeLabel">
<property name="text">
<string>Build Type</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="buildType">
<property name="editable">
<bool>true</bool>
</property>
<item>
<property name="text">
<string notr="true">Debug</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Release</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">RelWithDebInfo</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">MinSizeRel</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="extraArgumentsLabel">
<property name="text">
<string>Extra Arguments</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KComboBox" name="extraArguments">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Configure Environment</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="KDevelop::EnvironmentSelectionWidget" name="environment">
......@@ -137,13 +201,23 @@
</item>
</layout>
</item>
<item row="2" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="showInternal">
<property name="text">
<string>Show Advanced Values</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="KUrlRequester" name="cMakeBinary"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="cMakeBinaryLabel">
<property name="text">
<string>CMake Binary</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -155,6 +229,11 @@
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
</customwidget>
<customwidget>
<class>KDevelop::EnvironmentSelectionWidget</class>
<extends>KComboBox</extends>
......
......@@ -30,6 +30,7 @@
#include <QFile>
#include <QDir>
#include <QHeaderView>
#include <QComboBox>
#include "ui_cmakebuildsettings.h"
#include "cmakecachedelegate.h"
......@@ -66,6 +67,11 @@ CMakePreferences::CMakePreferences(IPlugin* plugin, const ProjectConfigOptions&
m_prefsUi->cacheList->horizontalHeader()->setStretchLastSection(true);
m_prefsUi->cacheList->verticalHeader()->hide();
// configure the extraArguments widget to span the advanced box width but not
// expand the dialog to the width of the longest element in the argument history.
m_prefsUi->extraArguments->setMinimumWidth(dynamic_cast<QComboBox*>(m_prefsUi->extraArguments)->minimumSizeHint().width());
m_extraArgumentsHistory = new CMakeExtraArgumentsHistory(m_prefsUi->extraArguments);
connect(m_prefsUi->buildDirs, static_cast<void(KComboBox::*)(int)>(&KComboBox::currentIndexChanged),
this, &CMakePreferences::buildDirChanged);
connect(m_prefsUi->showInternal, &QCheckBox::stateChanged,
......@@ -78,6 +84,19 @@ CMakePreferences::CMakePreferences(IPlugin* plugin, const ProjectConfigOptions&
connect(m_prefsUi->configureEnvironment, &EnvironmentConfigureButton::environmentConfigured,
this, &CMakePreferences::changed);
connect(m_prefsUi->installationPrefix, &KUrlRequester::textChanged,
this, &CMakePreferences::changed);
connect(m_prefsUi->buildType, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
this, &CMakePreferences::changed);
connect(m_prefsUi->buildType, &QComboBox::currentTextChanged,
this, &CMakePreferences::changed);
connect(m_prefsUi->extraArguments, &KComboBox::currentTextChanged,
this, &CMakePreferences::changed);
connect(m_prefsUi->extraArguments, &KComboBox::editTextChanged,
this, &CMakePreferences::changed);
connect(m_prefsUi->cMakeBinary, &KUrlRequester::textChanged,
this, &CMakePreferences::changed);
showInternal(m_prefsUi->showInternal->checkState());
m_subprojFolder = Path(options.projectTempFile).parent();
......@@ -97,9 +116,23 @@ CMakePreferences::CMakePreferences(IPlugin* plugin, const ProjectConfigOptions&
CMakePreferences::~CMakePreferences()
{
CMake::removeOverrideBuildDirIndex(m_project);
delete m_extraArgumentsHistory;
delete m_prefsUi;
}
void CMakePreferences::initAdvanced()
{
m_prefsUi->environment->setCurrentProfile( CMake::currentEnvironment(m_project) );
m_prefsUi->installationPrefix->setText(CMake::currentInstallDir(m_project).toLocalFile());
const QString buildType = CMake::currentBuildType(m_project);
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->cMakeBinary->setText(CMake::currentCMakeBinary(m_project).toLocalFile());
}
void CMakePreferences::reset()
{
qCDebug(CMAKE) << "********loading";
......@@ -107,7 +140,8 @@ void CMakePreferences::reset()
m_prefsUi->buildDirs->addItems( CMake::allBuildDirs(m_project) );
CMake::removeOverrideBuildDirIndex(m_project); // addItems() triggers buildDirChanged(), compensate for it
m_prefsUi->buildDirs->setCurrentIndex( CMake::currentBuildDirIndex(m_project) );
m_prefsUi->environment->setCurrentProfile( CMake::currentEnvironment(m_project) );
initAdvanced();
m_srcFolder = m_project->path();
......@@ -132,6 +166,15 @@ void CMakePreferences::apply()
CMake::setCurrentEnvironment( m_project, m_prefsUi->environment->currentProfile() );
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::setCurrentExtraArguments( m_project, m_prefsUi->extraArguments->currentText() );
CMake::setCurrentCMakeBinary( m_project, Path(m_prefsUi->cMakeBinary->text()) );
qCDebug(CMAKE) << "writing to cmake config: using builddir " << CMake::currentBuildDirIndex(m_project);
qCDebug(CMAKE) << "writing to cmake config: builddir path " << CMake::currentBuildDir(m_project);
qCDebug(CMAKE) << "writing to cmake config: installdir " << CMake::currentInstallDir(m_project);
......@@ -231,7 +274,7 @@ void CMakePreferences::buildDirChanged(int index)
{
CMake::setOverrideBuildDirIndex( m_project, index );
const Path buildDir = CMake::currentBuildDir(m_project);
m_prefsUi->environment->setCurrentProfile( CMake::currentEnvironment( m_project ) );
initAdvanced();
updateCache(buildDir);
qCDebug(CMAKE) << "builddir Changed" << buildDir;
emit changed();
......
......@@ -23,6 +23,7 @@
#define CMAKEPREFERENCES_H
#include "cmakecachemodel.h"
#include "cmakeextraargumentshistory.h"
#include <project/projectconfigpage.h>
#include <util/path.h>
......@@ -63,6 +64,7 @@ class CMakePreferences : public KDevelop::ConfigPage
void configureCacheView();
private:
void configure();
void initAdvanced();
KDevelop::IProject* m_project;
KDevelop::Path m_srcFolder;
......@@ -70,6 +72,7 @@ class CMakePreferences : public KDevelop::ConfigPage
void updateCache( const KDevelop::Path & );
Ui::CMakeBuildSettings* m_prefsUi;
CMakeCacheModel* m_currentModel;
CMakeExtraArgumentsHistory* m_extraArgumentsHistory;
};
#endif
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