forked from qt-creator/qt-creator
CMake: make it possible to insert new vars in project settings
Task-number: QTCREATORBUG-16238 Change-Id: If98acc4f27cabbb606b2fc1017096da626ba1144 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Tobias Hunger
parent
e6e2c1771b
commit
c1d735503b
@@ -48,6 +48,7 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -153,6 +154,20 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
|
|||||||
mainLayout->addWidget(findWrapper, row, 0, 1, 2);
|
mainLayout->addWidget(findWrapper, row, 0, 1, 2);
|
||||||
|
|
||||||
auto buttonLayout = new QVBoxLayout;
|
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"));
|
m_editButton = new QPushButton(tr("&Edit"));
|
||||||
buttonLayout->addWidget(m_editButton);
|
buttonLayout->addWidget(m_editButton);
|
||||||
m_resetButton = new QPushButton(tr("&Reset"));
|
m_resetButton = new QPushButton(tr("&Reset"));
|
||||||
@@ -213,6 +228,20 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
|
|||||||
m_configView->setCurrentIndex(idx);
|
m_configView->setCurrentIndex(idx);
|
||||||
m_configView->edit(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::errorOccured, this, &CMakeBuildSettingsWidget::setError);
|
||||||
connect(bc, &CMakeBuildConfiguration::warningOccured, this, &CMakeBuildSettingsWidget::setWarning);
|
connect(bc, &CMakeBuildConfiguration::warningOccured, this, &CMakeBuildSettingsWidget::setWarning);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class QLabel;
|
|||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
class QMenu;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
@@ -65,6 +66,8 @@ private:
|
|||||||
ConfigModel *m_configModel;
|
ConfigModel *m_configModel;
|
||||||
QSortFilterProxyModel *m_configFilterModel;
|
QSortFilterProxyModel *m_configFilterModel;
|
||||||
Utils::ProgressIndicator *m_progressIndicator;
|
Utils::ProgressIndicator *m_progressIndicator;
|
||||||
|
QPushButton *m_addButton;
|
||||||
|
QMenu *m_addButtonMenu;
|
||||||
QPushButton *m_editButton;
|
QPushButton *m_editButton;
|
||||||
QPushButton *m_resetButton;
|
QPushButton *m_resetButton;
|
||||||
QCheckBox *m_showAdvancedCheckBox;
|
QCheckBox *m_showAdvancedCheckBox;
|
||||||
|
|||||||
@@ -72,7 +72,10 @@ Qt::ItemFlags ConfigModel::flags(const QModelIndex &index) const
|
|||||||
else
|
else
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
|
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
|
||||||
} else {
|
} 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());
|
InternalDataItem &item = itemAtRow(index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
if (!item.key.isEmpty())
|
if (!item.key.isEmpty() && !item.isUserNew)
|
||||||
return false;
|
return false;
|
||||||
item.key = newValue;
|
item.key = newValue;
|
||||||
item.isUserNew = true;
|
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)
|
void ConfigModel::setConfiguration(const QList<ConfigModel::DataItem> &config)
|
||||||
{
|
{
|
||||||
QList<DataItem> tmp = config;
|
QList<DataItem> tmp = config;
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ public:
|
|||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const 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 setConfiguration(const QList<DataItem> &config);
|
||||||
void flush();
|
void flush();
|
||||||
void resetAllChanges();
|
void resetAllChanges();
|
||||||
|
|||||||
Reference in New Issue
Block a user