forked from qt-creator/qt-creator
Vcpkg: streamline vcpkgmanifesteditor.cpp a bit
Change-Id: Iabb1056f789b1e30f95d469ea18ccfb04e978b46 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -29,47 +29,18 @@
|
||||
#include <QPlainTextEdit>
|
||||
#include <QToolBar>
|
||||
|
||||
using namespace TextEditor;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Vcpkg::Internal {
|
||||
|
||||
class CMakeCodeDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
explicit CMakeCodeDialog(const QStringList &packages, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
static QString cmakeCodeForPackage(const QString &package);
|
||||
static QString cmakeCodeForPackages(const QStringList &packages);
|
||||
};
|
||||
|
||||
CMakeCodeDialog::CMakeCodeDialog(const QStringList &packages, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
resize(600, 600);
|
||||
|
||||
auto codeBrowser = new QPlainTextEdit;
|
||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::fontSettings();
|
||||
codeBrowser->setFont(fs.font());
|
||||
codeBrowser->setPlainText(cmakeCodeForPackages(packages));
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
|
||||
using namespace Layouting;
|
||||
Column {
|
||||
Tr::tr("Copy paste the required lines into your CMakeLists.txt:"),
|
||||
codeBrowser,
|
||||
buttonBox,
|
||||
}.attachTo(this);
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
QString CMakeCodeDialog::cmakeCodeForPackage(const QString &package)
|
||||
static QString cmakeCodeForPackage(const QString &package)
|
||||
{
|
||||
QString result;
|
||||
|
||||
const Utils::FilePath usageFile = settings().vcpkgRoot() / "ports" / package / "usage";
|
||||
const FilePath usageFile = settings().vcpkgRoot() / "ports" / package / "usage";
|
||||
if (usageFile.exists()) {
|
||||
Utils::FileReader reader;
|
||||
FileReader reader;
|
||||
if (reader.fetch(usageFile))
|
||||
result = QString::fromUtf8(reader.data());
|
||||
} else {
|
||||
@@ -78,14 +49,13 @@ R"(The package %1 provides CMake targets:
|
||||
|
||||
# this is heuristically generated, and may not be correct
|
||||
find_package(%1 CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE %1::%1))"
|
||||
).arg(package);
|
||||
target_link_libraries(main PRIVATE %1::%1))" ).arg(package);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString CMakeCodeDialog::cmakeCodeForPackages(const QStringList &packages)
|
||||
static QString cmakeCodeForPackages(const QStringList &packages)
|
||||
{
|
||||
QString result;
|
||||
for (const QString &package : packages)
|
||||
@@ -93,7 +63,31 @@ QString CMakeCodeDialog::cmakeCodeForPackages(const QStringList &packages)
|
||||
return result;
|
||||
}
|
||||
|
||||
class VcpkgManifestEditorWidget : public TextEditor::TextEditorWidget
|
||||
class CMakeCodeDialog final : public QDialog
|
||||
{
|
||||
public:
|
||||
explicit CMakeCodeDialog(const QStringList &packages)
|
||||
{
|
||||
resize(600, 600);
|
||||
|
||||
auto codeBrowser = new QPlainTextEdit;
|
||||
codeBrowser->setFont(TextEditorSettings::fontSettings().font());
|
||||
codeBrowser->setPlainText(cmakeCodeForPackages(packages));
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
|
||||
using namespace Layouting;
|
||||
Column {
|
||||
Tr::tr("Copy paste the required lines into your CMakeLists.txt:"),
|
||||
codeBrowser,
|
||||
buttonBox,
|
||||
}.attachTo(this);
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
};
|
||||
|
||||
class VcpkgManifestEditorWidget final : public TextEditor::TextEditorWidget
|
||||
{
|
||||
public:
|
||||
VcpkgManifestEditorWidget()
|
||||
@@ -147,9 +141,9 @@ private:
|
||||
QAction *m_cmakeCodeAction;
|
||||
};
|
||||
|
||||
static TextEditor::TextDocument *createVcpkgManifestDocument()
|
||||
static TextDocument *createVcpkgManifestDocument()
|
||||
{
|
||||
auto doc = new TextEditor::TextDocument;
|
||||
auto doc = new TextDocument;
|
||||
doc->setId(Constants::VCPKGMANIFEST_EDITOR_ID);
|
||||
return doc;
|
||||
}
|
||||
@@ -164,7 +158,7 @@ QByteArray addDependencyToManifest(const QByteArray &manifest, const QString &pa
|
||||
return QJsonDocument(jsonObject).toJson();
|
||||
}
|
||||
|
||||
class VcpkgManifestEditorFactory final : public TextEditor::TextEditorFactory
|
||||
class VcpkgManifestEditorFactory final : public TextEditorFactory
|
||||
{
|
||||
public:
|
||||
VcpkgManifestEditorFactory()
|
||||
|
Reference in New Issue
Block a user