forked from qt-creator/qt-creator
Macros: Inline macrooptionswidget.ui
Change-Id: Ib35fd2816b7da5d2720f09ca89903549c7d3e66f Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -9,7 +9,7 @@ add_qtc_plugin(Macros
|
||||
macrolocatorfilter.cpp macrolocatorfilter.h
|
||||
macromanager.cpp macromanager.h
|
||||
macrooptionspage.cpp macrooptionspage.h
|
||||
macrooptionswidget.cpp macrooptionswidget.h macrooptionswidget.ui
|
||||
macrooptionswidget.cpp macrooptionswidget.h
|
||||
macros.qrc
|
||||
macrosconstants.h
|
||||
macrosplugin.cpp macrosplugin.h
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "macrooptionswidget.h"
|
||||
#include "ui_macrooptionswidget.h"
|
||||
|
||||
#include "macrosconstants.h"
|
||||
#include "macromanager.h"
|
||||
#include "macro.h"
|
||||
@@ -34,48 +34,77 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QGroupBox>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTreeWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace {
|
||||
int NAME_ROLE = Qt::UserRole;
|
||||
int WRITE_ROLE = Qt::UserRole+1;
|
||||
}
|
||||
namespace Macros::Internal {
|
||||
|
||||
using namespace Macros;
|
||||
using namespace Macros::Internal;
|
||||
const int NAME_ROLE = Qt::UserRole;
|
||||
const int WRITE_ROLE = Qt::UserRole + 1;
|
||||
|
||||
|
||||
MacroOptionsWidget::MacroOptionsWidget() :
|
||||
m_ui(new Ui::MacroOptionsWidget)
|
||||
MacroOptionsWidget::MacroOptionsWidget()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_treeWidget = new QTreeWidget;
|
||||
m_treeWidget->setTextElideMode(Qt::ElideLeft);
|
||||
m_treeWidget->setUniformRowHeights(true);
|
||||
m_treeWidget->setSortingEnabled(true);
|
||||
m_treeWidget->setColumnCount(3);
|
||||
m_treeWidget->header()->setSortIndicatorShown(true);
|
||||
m_treeWidget->header()->setStretchLastSection(true);
|
||||
m_treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
m_treeWidget->setHeaderLabels({tr("Name"), tr("Description)"), tr("Shortcut")});
|
||||
|
||||
connect(m_ui->treeWidget, &QTreeWidget::currentItemChanged,
|
||||
m_description = new QLineEdit;
|
||||
|
||||
m_removeButton = new QPushButton(tr("Remove"));
|
||||
|
||||
m_macroGroup = new QGroupBox(tr("Macro"), this);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Row {
|
||||
tr("Description:"), m_description
|
||||
}.attachTo(m_macroGroup);
|
||||
|
||||
Column {
|
||||
Group {
|
||||
Title(tr("Preferences")),
|
||||
Row {
|
||||
m_treeWidget,
|
||||
Column { m_removeButton, Stretch() },
|
||||
}
|
||||
},
|
||||
m_macroGroup
|
||||
}.attachTo(this);
|
||||
|
||||
connect(m_treeWidget, &QTreeWidget::currentItemChanged,
|
||||
this, &MacroOptionsWidget::changeCurrentItem);
|
||||
connect(m_ui->removeButton, &QPushButton::clicked,
|
||||
connect(m_removeButton, &QPushButton::clicked,
|
||||
this, &MacroOptionsWidget::remove);
|
||||
connect(m_ui->description, &QLineEdit::textChanged,
|
||||
connect(m_description, &QLineEdit::textChanged,
|
||||
this, &MacroOptionsWidget::changeDescription);
|
||||
|
||||
m_ui->treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
MacroOptionsWidget::~MacroOptionsWidget()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
MacroOptionsWidget::~MacroOptionsWidget() = default;
|
||||
|
||||
void MacroOptionsWidget::initialize()
|
||||
{
|
||||
m_macroToRemove.clear();
|
||||
m_macroToChange.clear();
|
||||
m_ui->treeWidget->clear();
|
||||
m_treeWidget->clear();
|
||||
changeCurrentItem(nullptr);
|
||||
|
||||
// Create the treeview
|
||||
createTable();
|
||||
@@ -88,7 +117,7 @@ void MacroOptionsWidget::createTable()
|
||||
for (Macro *macro : MacroManager::macros()) {
|
||||
QFileInfo fileInfo(macro->fileName());
|
||||
if (fileInfo.absoluteDir() == dir.absolutePath()) {
|
||||
auto macroItem = new QTreeWidgetItem(m_ui->treeWidget);
|
||||
auto macroItem = new QTreeWidgetItem(m_treeWidget);
|
||||
macroItem->setText(0, macro->displayName());
|
||||
macroItem->setText(1, macro->description());
|
||||
macroItem->setData(0, NAME_ROLE, macro->displayName());
|
||||
@@ -107,22 +136,20 @@ void MacroOptionsWidget::createTable()
|
||||
void MacroOptionsWidget::changeCurrentItem(QTreeWidgetItem *current)
|
||||
{
|
||||
m_changingCurrent = true;
|
||||
m_removeButton->setEnabled(current);
|
||||
m_macroGroup->setEnabled(current);
|
||||
if (!current) {
|
||||
m_ui->removeButton->setEnabled(false);
|
||||
m_ui->description->clear();
|
||||
m_ui->macroGroup->setEnabled(false);
|
||||
m_description->clear();
|
||||
} else {
|
||||
m_ui->removeButton->setEnabled(true);
|
||||
m_ui->description->setText(current->text(1));
|
||||
m_ui->description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
||||
m_ui->macroGroup->setEnabled(true);
|
||||
m_description->setText(current->text(1));
|
||||
m_description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
||||
}
|
||||
m_changingCurrent = false;
|
||||
}
|
||||
|
||||
void MacroOptionsWidget::remove()
|
||||
{
|
||||
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||
QTreeWidgetItem *current = m_treeWidget->currentItem();
|
||||
m_macroToRemove.append(current->data(0, NAME_ROLE).toString());
|
||||
delete current;
|
||||
}
|
||||
@@ -145,7 +172,7 @@ void MacroOptionsWidget::apply()
|
||||
|
||||
void MacroOptionsWidget::changeDescription(const QString &description)
|
||||
{
|
||||
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||
QTreeWidgetItem *current = m_treeWidget->currentItem();
|
||||
if (m_changingCurrent || !current)
|
||||
return;
|
||||
|
||||
@@ -156,3 +183,5 @@ void MacroOptionsWidget::changeDescription(const QString &description)
|
||||
font.setItalic(true);
|
||||
current->setFont(1, font);
|
||||
}
|
||||
|
||||
} // Macros::Internal
|
||||
|
||||
@@ -31,14 +31,16 @@
|
||||
#include <QMap>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGroupBox;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QTreeWidget;
|
||||
class QTreeWidgetItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Macros {
|
||||
namespace Internal {
|
||||
|
||||
namespace Ui { class MacroOptionsWidget; }
|
||||
|
||||
class MacroOptionsWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -60,11 +62,15 @@ private:
|
||||
void changeDescription(const QString &description);
|
||||
|
||||
private:
|
||||
Ui::MacroOptionsWidget *m_ui;
|
||||
QStringList m_macroToRemove;
|
||||
bool m_changingCurrent = false;
|
||||
|
||||
QMap<QString, QString> m_macroToChange;
|
||||
|
||||
QTreeWidget *m_treeWidget;
|
||||
QPushButton *m_removeButton;
|
||||
QGroupBox *m_macroGroup;
|
||||
QLineEdit *m_description;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Macros::Internal::MacroOptionsWidget</class>
|
||||
<widget class="QWidget" name="Macros::Internal::MacroOptionsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>464</width>
|
||||
<height>473</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="directoryGroupBox">
|
||||
<property name="title">
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::ElideLeft</enum>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<attribute name="headerShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Shortcut</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<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>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="macroGroup">
|
||||
<property name="title">
|
||||
<string>Macro</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Description:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="description"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -31,7 +31,6 @@ QtcPlugin {
|
||||
"macrooptionspage.h",
|
||||
"macrooptionswidget.cpp",
|
||||
"macrooptionswidget.h",
|
||||
"macrooptionswidget.ui",
|
||||
"macros.qrc",
|
||||
"macrosconstants.h",
|
||||
"macrosplugin.cpp",
|
||||
|
||||
Reference in New Issue
Block a user