CMakeProjectManager: Allow copying of CMake variables

In the context menu of the CMake variables there is now a "Copy"
entry that will copy to clipboard the -D<var>:<typ>=<val> or -U<var>
values.

Task-number: QTCREATORBUG-22482
Fixes: QTCREATORBUG-24781
Change-Id: Iaa70e64fd0593398732ccb8d9036571b308b5f12
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2021-02-25 15:21:01 +01:00
parent 93ec7862f2
commit faa21ef378
2 changed files with 48 additions and 0 deletions

View File

@@ -68,8 +68,10 @@
#include <utils/stringutils.h>
#include <utils/variablechooser.h>
#include <QApplication>
#include <QBoxLayout>
#include <QCheckBox>
#include <QClipboard>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDir>
@@ -707,6 +709,23 @@ bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
if ((action = createForceAction(ConfigModel::DataItem::STRING, idx)))
menu->addAction(action);
auto copy = new QAction(tr("Copy"), this);
menu->addAction(copy);
connect(copy, &QAction::triggered, this, [this] {
const QModelIndexList selectedIndexes = m_configView->selectionModel()->selectedIndexes();
const QModelIndexList validIndexes = Utils::filtered(selectedIndexes, [](const QModelIndex &index) {
return index.isValid() && index.flags().testFlag(Qt::ItemIsSelectable);
});
const QStringList variableList = Utils::transform(validIndexes, [this](const QModelIndex &index) {
return ConfigModel::dataItemFromIndex(index)
.toCMakeConfigItem().toArgument(m_buildConfiguration->macroExpander());
});
QApplication::clipboard()->setText(variableList.join('\n'), QClipboard::Clipboard);
});
menu->move(e->globalPos());
menu->show();

View File

@@ -83,6 +83,35 @@ public:
}
}
CMakeConfigItem toCMakeConfigItem() const {
CMakeConfigItem cmi;
cmi.key = key.toUtf8();
cmi.value = value.toUtf8();
switch (type) {
case DataItem::BOOLEAN:
cmi.type = CMakeConfigItem::BOOL;
break;
case DataItem::FILE:
cmi.type = CMakeConfigItem::FILEPATH;
break;
case DataItem::DIRECTORY:
cmi.type = CMakeConfigItem::PATH;
break;
case DataItem::STRING:
cmi.type = CMakeConfigItem::STRING;
break;
case DataItem::UNKNOWN:
cmi.type = CMakeConfigItem::INTERNAL;
break;
}
cmi.isUnset = isUnset;
cmi.isAdvanced = isAdvanced;
cmi.values = values;
cmi.documentation = description.toUtf8();
return cmi;
}
enum Type { BOOLEAN, FILE, DIRECTORY, STRING, UNKNOWN};
QString key;