forked from qt-creator/qt-creator
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:
@@ -68,8 +68,10 @@
|
|||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/variablechooser.h>
|
#include <utils/variablechooser.h>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -707,6 +709,23 @@ bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
|
|||||||
if ((action = createForceAction(ConfigModel::DataItem::STRING, idx)))
|
if ((action = createForceAction(ConfigModel::DataItem::STRING, idx)))
|
||||||
menu->addAction(action);
|
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->move(e->globalPos());
|
||||||
menu->show();
|
menu->show();
|
||||||
|
|
||||||
|
|||||||
@@ -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};
|
enum Type { BOOLEAN, FILE, DIRECTORY, STRING, UNKNOWN};
|
||||||
|
|
||||||
QString key;
|
QString key;
|
||||||
|
|||||||
Reference in New Issue
Block a user