QbsProjectManager: inline customqbspropertiesdialog.ui

Change-Id: I752c101dcdd1ee47880b43ffe61597bbdf67521f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Alessandro Portale
2022-08-18 13:32:01 +02:00
parent 706a2af1e1
commit fa033876e6
5 changed files with 56 additions and 151 deletions

View File

@@ -4,7 +4,7 @@ add_qtc_plugin(QbsProjectManager
IDE_LIBRARY_BASENAME="${IDE_LIBRARY_BASE_PATH}"
PLUGIN_DEPENDS Core ProjectExplorer CppEditor QtSupport QmlJSTools
SOURCES
customqbspropertiesdialog.cpp customqbspropertiesdialog.h customqbspropertiesdialog.ui
customqbspropertiesdialog.cpp customqbspropertiesdialog.h
defaultpropertyprovider.cpp defaultpropertyprovider.h
propertyprovider.h
qbsbuildconfiguration.cpp qbsbuildconfiguration.h

View File

@@ -2,80 +2,103 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "customqbspropertiesdialog.h"
#include "ui_customqbspropertiesdialog.h"
#include "qbsprofilemanager.h"
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QPushButton>
#include <QTableWidgetItem>
namespace QbsProjectManager {
namespace Internal {
CustomQbsPropertiesDialog::CustomQbsPropertiesDialog(const QVariantMap &properties, QWidget *parent)
: QDialog(parent), m_ui(new Ui::CustomQbsPropertiesDialog)
: QDialog(parent)
{
m_ui->setupUi(this);
m_ui->propertiesTable->setRowCount(properties.count());
m_ui->propertiesTable->setHorizontalHeaderLabels(QStringList() << tr("Key") << tr("Value"));
setWindowTitle(tr("Custom Properties"));
m_propertiesTable = new QTableWidget;
m_propertiesTable->setColumnCount(2);
m_propertiesTable->setRowCount(properties.count());
m_propertiesTable->setHorizontalHeaderLabels(QStringList() << tr("Key") << tr("Value"));
m_propertiesTable->horizontalHeader()->setStretchLastSection(true);
m_propertiesTable->verticalHeader()->setVisible(false);
int currentRow = 0;
for (QVariantMap::ConstIterator it = properties.constBegin(); it != properties.constEnd();
++it) {
auto * const nameItem = new QTableWidgetItem;
nameItem->setData(Qt::DisplayRole, it.key());
m_ui->propertiesTable->setItem(currentRow, 0, nameItem);
m_propertiesTable->setItem(currentRow, 0, nameItem);
auto * const valueItem = new QTableWidgetItem;
valueItem->setData(Qt::DisplayRole, toJSLiteral(it.value()));
m_ui->propertiesTable->setItem(currentRow, 1, valueItem);
m_propertiesTable->setItem(currentRow, 1, valueItem);
++currentRow;
}
connect(m_ui->addButton, &QAbstractButton::clicked,
this, &CustomQbsPropertiesDialog::addProperty);
connect(m_ui->removeButton, &QAbstractButton::clicked,
m_removeButton = new QPushButton(tr("&Remove"));
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
using namespace Utils::Layouting;
Column {
Row {
m_propertiesTable,
Column {
PushButton {
text(tr("&Add")),
onClicked([this] { addProperty(); } ),
},
m_removeButton,
st
},
},
buttonBox,
}.attachTo(this);
connect(m_removeButton, &QAbstractButton::clicked,
this, &CustomQbsPropertiesDialog::removeSelectedProperty);
connect(m_ui->propertiesTable, &QTableWidget::currentItemChanged,
connect(m_propertiesTable, &QTableWidget::currentItemChanged,
this, &CustomQbsPropertiesDialog::handleCurrentItemChanged);
connect(buttonBox, &QDialogButtonBox::accepted, this, &CustomQbsPropertiesDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &CustomQbsPropertiesDialog::reject);
handleCurrentItemChanged();
}
QVariantMap CustomQbsPropertiesDialog::properties() const
{
QVariantMap properties;
for (int row = 0; row < m_ui->propertiesTable->rowCount(); ++row) {
const QTableWidgetItem * const nameItem = m_ui->propertiesTable->item(row, 0);
for (int row = 0; row < m_propertiesTable->rowCount(); ++row) {
const QTableWidgetItem * const nameItem = m_propertiesTable->item(row, 0);
const QString name = nameItem->text();
if (name.isEmpty())
continue;
properties.insert(name, fromJSLiteral(m_ui->propertiesTable->item(row, 1)->text()));
properties.insert(name, fromJSLiteral(m_propertiesTable->item(row, 1)->text()));
}
return properties;
}
CustomQbsPropertiesDialog::~CustomQbsPropertiesDialog()
{
delete m_ui;
}
void CustomQbsPropertiesDialog::addProperty()
{
const int row = m_ui->propertiesTable->rowCount();
m_ui->propertiesTable->insertRow(row);
m_ui->propertiesTable->setItem(row, 0, new QTableWidgetItem);
m_ui->propertiesTable->setItem(row, 1, new QTableWidgetItem);
const int row = m_propertiesTable->rowCount();
m_propertiesTable->insertRow(row);
m_propertiesTable->setItem(row, 0, new QTableWidgetItem);
m_propertiesTable->setItem(row, 1, new QTableWidgetItem);
}
void CustomQbsPropertiesDialog::removeSelectedProperty()
{
const QTableWidgetItem * const currentItem = m_ui->propertiesTable->currentItem();
const QTableWidgetItem * const currentItem = m_propertiesTable->currentItem();
QTC_ASSERT(currentItem, return);
m_ui->propertiesTable->removeRow(currentItem->row());
m_propertiesTable->removeRow(currentItem->row());
}
void CustomQbsPropertiesDialog::handleCurrentItemChanged()
{
m_ui->removeButton->setEnabled(m_ui->propertiesTable->currentItem());
m_removeButton->setEnabled(m_propertiesTable->currentItem());
}
} // namespace Internal

View File

@@ -6,9 +6,12 @@
#include <QVariantMap>
#include <QDialog>
QT_BEGIN_NAMESPACE
class QTableWidget;
QT_END_NAMESPACE
namespace QbsProjectManager {
namespace Internal {
namespace Ui { class CustomQbsPropertiesDialog; }
class CustomQbsPropertiesDialog : public QDialog
{
@@ -18,7 +21,6 @@ public:
explicit CustomQbsPropertiesDialog(const QVariantMap &properties, QWidget *parent = nullptr);
QVariantMap properties() const;
~CustomQbsPropertiesDialog() override;
private:
void addProperty();
@@ -26,7 +28,8 @@ private:
void handleCurrentItemChanged();
private:
Ui::CustomQbsPropertiesDialog * const m_ui;
QTableWidget *m_propertiesTable;
QPushButton *m_removeButton;
};
} // namespace Internal

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QbsProjectManager::Internal::CustomQbsPropertiesDialog</class>
<widget class="QDialog" name="QbsProjectManager::Internal::CustomQbsPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Custom Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableWidget" name="propertiesTable">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
<column/>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QbsProjectManager::Internal::CustomQbsPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QbsProjectManager::Internal::CustomQbsPropertiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -21,7 +21,6 @@ QtcPlugin {
files: [
"customqbspropertiesdialog.h",
"customqbspropertiesdialog.cpp",
"customqbspropertiesdialog.ui",
"defaultpropertyprovider.cpp",
"defaultpropertyprovider.h",
"propertyprovider.h",