forked from qt-creator/qt-creator
CMake: Enable type forcing for CMake configuation values
Allow to force the type for CMake configuration values, now that this type changes how you can edit the values. Change-Id: Id89e0ec8547b778fc0aff9a2e00c0d7406cbcac1 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -378,6 +378,33 @@ void CMakeBuildSettingsWidget::updateSelection(const QModelIndex ¤t, const
|
|||||||
m_editButton->setEnabled(currentModelIndex.flags().testFlag(Qt::ItemIsEditable));
|
m_editButton->setEnabled(currentModelIndex.flags().testFlag(Qt::ItemIsEditable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAction *CMakeBuildSettingsWidget::createForceAction(int type, const QModelIndex &idx)
|
||||||
|
{
|
||||||
|
ConfigModel::DataItem::Type t = static_cast<ConfigModel::DataItem::Type>(type);
|
||||||
|
QString typeString;
|
||||||
|
switch (type) {
|
||||||
|
case ConfigModel::DataItem::BOOLEAN:
|
||||||
|
typeString = tr("bool", "display string for cmake type BOOLEAN");
|
||||||
|
break;
|
||||||
|
case ConfigModel::DataItem::FILE:
|
||||||
|
typeString = tr("file", "display string for cmake type FILE");
|
||||||
|
break;
|
||||||
|
case ConfigModel::DataItem::DIRECTORY:
|
||||||
|
typeString = tr("directory", "display string for cmake type DIRECTORY");
|
||||||
|
break;
|
||||||
|
case ConfigModel::DataItem::STRING:
|
||||||
|
typeString = tr("string", "display string for cmake type STRING");
|
||||||
|
break;
|
||||||
|
case ConfigModel::DataItem::UNKNOWN:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
QAction *forceAction = new QAction(tr("Force to %1").arg(typeString));
|
||||||
|
forceAction->setEnabled(m_configModel->canForceTo(idx, t));
|
||||||
|
connect(forceAction, &QAction::triggered,
|
||||||
|
this, [this, idx, t]() { m_configModel->forceTo(idx, t); });
|
||||||
|
return forceAction;
|
||||||
|
}
|
||||||
|
|
||||||
bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
|
bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
|
||||||
{
|
{
|
||||||
// handle context menu events:
|
// handle context menu events:
|
||||||
@@ -392,10 +419,15 @@ bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
|
|||||||
QMenu *menu = new QMenu(this);
|
QMenu *menu = new QMenu(this);
|
||||||
connect(menu, &QMenu::triggered, menu, &QMenu::deleteLater);
|
connect(menu, &QMenu::triggered, menu, &QMenu::deleteLater);
|
||||||
|
|
||||||
QAction *forceToStringAction = new QAction(tr("Force to String"), nullptr);
|
QAction *action = nullptr;
|
||||||
forceToStringAction->setEnabled(m_configModel->canForceToString(idx));
|
if ((action = createForceAction(ConfigModel::DataItem::BOOLEAN, idx)))
|
||||||
menu->addAction(forceToStringAction);
|
menu->addAction(action);
|
||||||
connect(forceToStringAction, &QAction::triggered, this, [this, idx]() { m_configModel->forceToString(idx); });
|
if ((action = createForceAction(ConfigModel::DataItem::FILE, idx)))
|
||||||
|
menu->addAction(action);
|
||||||
|
if ((action = createForceAction(ConfigModel::DataItem::DIRECTORY, idx)))
|
||||||
|
menu->addAction(action);
|
||||||
|
if ((action = createForceAction(ConfigModel::DataItem::STRING, idx)))
|
||||||
|
menu->addAction(action);
|
||||||
|
|
||||||
menu->move(e->globalPos());
|
menu->move(e->globalPos());
|
||||||
menu->show();
|
menu->show();
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ private:
|
|||||||
void updateFromKit();
|
void updateFromKit();
|
||||||
|
|
||||||
void updateSelection(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateSelection(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
|
QAction *createForceAction(int type, const QModelIndex &idx);
|
||||||
|
|
||||||
bool eventFilter(QObject *target, QEvent *event);
|
bool eventFilter(QObject *target, QEvent *event);
|
||||||
|
|
||||||
|
|||||||
@@ -135,23 +135,23 @@ bool ConfigModel::hasCMakeChanges() const
|
|||||||
return Utils::contains(m_configuration, [](const InternalDataItem &i) { return i.isCMakeChanged; });
|
return Utils::contains(m_configuration, [](const InternalDataItem &i) { return i.isCMakeChanged; });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigModel::canForceToString(const QModelIndex &idx) const
|
bool ConfigModel::canForceTo(const QModelIndex &idx, const ConfigModel::DataItem::Type type) const
|
||||||
{
|
{
|
||||||
if (idx.model() != const_cast<ConfigModel *>(this) || idx.column() != 1)
|
if (idx.model() != const_cast<ConfigModel *>(this) || idx.column() != 1)
|
||||||
return false;
|
return false;
|
||||||
Utils::TreeItem *item = itemForIndex(idx);
|
Utils::TreeItem *item = itemForIndex(idx);
|
||||||
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
|
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
|
||||||
return cmti && (cmti->dataItem->type != DataItem::STRING);
|
return cmti && (cmti->dataItem->type != type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigModel::forceToString(const QModelIndex &idx)
|
void ConfigModel::forceTo(const QModelIndex &idx, const ConfigModel::DataItem::Type type)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(canForceToString(idx), return);
|
QTC_ASSERT(canForceTo(idx, type), return);
|
||||||
Utils::TreeItem *item = itemForIndex(idx);
|
Utils::TreeItem *item = itemForIndex(idx);
|
||||||
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
|
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
|
||||||
|
|
||||||
cmti->dataItem->type = DataItem::STRING;
|
cmti->dataItem->type = type;
|
||||||
const QModelIndex valueIdx = idx.sibling(1, idx.column());
|
const QModelIndex valueIdx = idx.sibling(idx.row(), 1);
|
||||||
emit dataChanged(valueIdx, valueIdx);
|
emit dataChanged(valueIdx, valueIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ public:
|
|||||||
bool hasChanges() const;
|
bool hasChanges() const;
|
||||||
bool hasCMakeChanges() const;
|
bool hasCMakeChanges() const;
|
||||||
|
|
||||||
bool canForceToString(const QModelIndex &idx) const;
|
bool canForceTo(const QModelIndex &idx, const DataItem::Type type) const;
|
||||||
void forceToString(const QModelIndex &idx);
|
void forceTo(const QModelIndex &idx, const DataItem::Type type);
|
||||||
|
|
||||||
static DataItem dataItemFromIndex(const QModelIndex &idx);
|
static DataItem dataItemFromIndex(const QModelIndex &idx);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user