Commit c1d73550 authored by Stanislav Ionascu's avatar Stanislav Ionascu Committed by Tobias Hunger

CMake: make it possible to insert new vars in project settings

Task-number: QTCREATORBUG-16238
Change-Id: If98acc4f27cabbb606b2fc1017096da626ba1144
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent e6e2c177
......@@ -48,6 +48,7 @@
#include <QPushButton>
#include <QSortFilterProxyModel>
#include <QSpacerItem>
#include <QMenu>
namespace CMakeProjectManager {
namespace Internal {
......@@ -153,6 +154,20 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
mainLayout->addWidget(findWrapper, row, 0, 1, 2);
auto buttonLayout = new QVBoxLayout;
m_addButton = new QPushButton(tr("&Add"));
buttonLayout->addWidget(m_addButton);
{
m_addButtonMenu = new QMenu;
m_addButtonMenu->addAction(tr("&Boolean"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::BOOLEAN)));
m_addButtonMenu->addAction(tr("&String"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::STRING)));
m_addButtonMenu->addAction(tr("&Directory"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::DIRECTORY)));
m_addButtonMenu->addAction(tr("&File"))->setData(
QVariant::fromValue(static_cast<int>(ConfigModel::DataItem::FILE)));
m_addButton->setMenu(m_addButtonMenu);
}
m_editButton = new QPushButton(tr("&Edit"));
buttonLayout->addWidget(m_editButton);
m_resetButton = new QPushButton(tr("&Reset"));
......@@ -213,6 +228,20 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configView->setCurrentIndex(idx);
m_configView->edit(idx);
});
connect(m_addButtonMenu, &QMenu::triggered, this, [this](QAction *action) {
ConfigModel::DataItem::Type type =
static_cast<ConfigModel::DataItem::Type>(action->data().value<int>());
QString value = tr("<UNSET>");
if (type == ConfigModel::DataItem::BOOLEAN)
value = QString::fromLatin1("OFF");
m_configModel->appendConfiguration(tr("<UNSET>"), value, type);
QModelIndex idx;
idx = m_configView->model()->index(
m_configView->model()->rowCount(idx) - 1, 0);
m_configView->setCurrentIndex(idx);
m_configView->edit(idx);
});
connect(bc, &CMakeBuildConfiguration::errorOccured, this, &CMakeBuildSettingsWidget::setError);
connect(bc, &CMakeBuildConfiguration::warningOccured, this, &CMakeBuildSettingsWidget::setWarning);
......
......@@ -37,6 +37,7 @@ class QLabel;
class QPushButton;
class QTreeView;
class QSortFilterProxyModel;
class QMenu;
QT_END_NAMESPACE
namespace CMakeProjectManager {
......@@ -65,6 +66,8 @@ private:
ConfigModel *m_configModel;
QSortFilterProxyModel *m_configFilterModel;
Utils::ProgressIndicator *m_progressIndicator;
QPushButton *m_addButton;
QMenu *m_addButtonMenu;
QPushButton *m_editButton;
QPushButton *m_resetButton;
QCheckBox *m_showAdvancedCheckBox;
......
......@@ -72,7 +72,10 @@ Qt::ItemFlags ConfigModel::flags(const QModelIndex &index) const
else
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
} else {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (item.isUserNew)
return flags |= Qt::ItemIsEditable;
return flags;
}
}
......@@ -164,7 +167,7 @@ bool ConfigModel::setData(const QModelIndex &index, const QVariant &value, int r
InternalDataItem &item = itemAtRow(index.row());
switch (index.column()) {
case 0:
if (!item.key.isEmpty())
if (!item.key.isEmpty() && !item.isUserNew)
return false;
item.key = newValue;
item.isUserNew = true;
......@@ -203,6 +206,25 @@ QVariant ConfigModel::headerData(int section, Qt::Orientation orientation, int r
}
}
void ConfigModel::appendConfiguration(const QString &key,
const QString &value,
const ConfigModel::DataItem::Type type,
const QString &description)
{
DataItem item;
item.key = key;
item.type = type;
item.value = value;
item.description = description;
InternalDataItem internalItem(item);
internalItem.isUserNew = true;
beginResetModel();
m_configuration.append(internalItem);
endResetModel();
}
void ConfigModel::setConfiguration(const QList<ConfigModel::DataItem> &config)
{
QList<DataItem> tmp = config;
......
......@@ -55,6 +55,10 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void appendConfiguration(const QString &key,
const QString &value = QString(),
const DataItem::Type type = DataItem::UNKNOWN,
const QString &description = QString());
void setConfiguration(const QList<DataItem> &config);
void flush();
void resetAllChanges();
......
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