forked from qt-creator/qt-creator
ProjectExplorer: Move KitAspect related layout code
... from KitManagerConfigWidget to KitAspectWidget (which is not really a widget, but...) The modification for the alignment handling only affect this use here. Long term I hope this can be handled centrally (e.g. always use the special form label alignment for labels in the first column when some LayoutBuilder bool property is set, instead of doing that for each use), so this is not necessarily a final API. Change-Id: I678dba45ee68ca9706569715d232f98363de8636 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -44,12 +44,14 @@
|
||||
#include <remotelinux/remotelinux_constants.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/persistentsettings.h>
|
||||
#include <utils/pointeralgorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QLabel>
|
||||
#include <QSettings>
|
||||
#include <QStyle>
|
||||
|
||||
@@ -729,6 +731,24 @@ Utils::Id KitAspectWidget::kitInformationId() const
|
||||
return m_kitInformation->id();
|
||||
}
|
||||
|
||||
void KitAspectWidget::addToLayout(LayoutBuilder &builder)
|
||||
{
|
||||
QTC_ASSERT(!m_label, delete m_label);
|
||||
m_label = new QLabel(m_kitInformation->displayName() + ':');
|
||||
m_label->setToolTip(m_kitInformation->description());
|
||||
|
||||
builder.addRow({{m_label, 1, LayoutBuilder::AlignAsFormLabel}, mainWidget(), buttonWidget()});
|
||||
}
|
||||
|
||||
void KitAspectWidget::setVisible(bool visible)
|
||||
{
|
||||
mainWidget()->setVisible(visible);
|
||||
if (buttonWidget())
|
||||
buttonWidget()->setVisible(visible);
|
||||
QTC_ASSERT(m_label, return);
|
||||
m_label->setVisible(visible);
|
||||
}
|
||||
|
||||
QString KitAspectWidget::msgManage()
|
||||
{
|
||||
return tr("Manage...");
|
||||
|
||||
@@ -37,9 +37,14 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLabel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class Environment;
|
||||
class FilePath;
|
||||
class LayoutBuilder;
|
||||
class MacroExpander;
|
||||
class OutputLineParser;
|
||||
} // namespace Utils
|
||||
@@ -136,6 +141,9 @@ public:
|
||||
virtual QWidget *mainWidget() const = 0;
|
||||
virtual QWidget *buttonWidget() const { return nullptr; }
|
||||
|
||||
void addToLayout(Utils::LayoutBuilder &builder);
|
||||
void setVisible(bool visible);
|
||||
|
||||
bool isSticky() const { return m_isSticky; }
|
||||
|
||||
static QString msgManage();
|
||||
@@ -149,6 +157,7 @@ protected:
|
||||
Kit *m_kit;
|
||||
const KitAspect *m_kitInformation;
|
||||
bool m_isSticky;
|
||||
QLabel *m_label = nullptr;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT KitManager : public QObject
|
||||
|
||||
@@ -46,16 +46,11 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QFileDialog>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QScrollArea>
|
||||
#include <QSizePolicy>
|
||||
#include <QStyle>
|
||||
|
||||
static const char WORKING_COPY_KIT_ID[] = "modified kit";
|
||||
|
||||
@@ -71,14 +66,12 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
|
||||
m_kit(k),
|
||||
m_modifiedKit(std::make_unique<Kit>(Utils::Id(WORKING_COPY_KIT_ID)))
|
||||
{
|
||||
static auto alignment
|
||||
= static_cast<const Qt::Alignment>(style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
|
||||
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
LayoutBuilder builder(this, LayoutBuilder::GridLayout);
|
||||
QLabel *label = createLabel(tr("Name:"), tr("Kit name and icon."));
|
||||
builder.addRow({{label, 1, alignment}, m_nameEdit, m_iconButton});
|
||||
QLabel *label = new QLabel(tr("Name:"));
|
||||
label->setToolTip(tr("Kit name and icon."));
|
||||
builder.addRow({{label, 1, LayoutBuilder::AlignAsFormLabel}, m_nameEdit, m_iconButton});
|
||||
|
||||
QString toolTip =
|
||||
tr("<html><head/><body><p>The name of the kit suitable for generating "
|
||||
@@ -90,8 +83,9 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
|
||||
Q_ASSERT(fileSystemFriendlyNameRegexp.isValid());
|
||||
m_fileSystemFriendlyNameLineEdit->setValidator(new QRegularExpressionValidator(fileSystemFriendlyNameRegexp, m_fileSystemFriendlyNameLineEdit));
|
||||
|
||||
label = createLabel(tr("File system name:"), toolTip);
|
||||
builder.addRow({{label, 1, alignment}, m_fileSystemFriendlyNameLineEdit});
|
||||
label = new QLabel(tr("File system name:"));
|
||||
label->setToolTip(toolTip);
|
||||
builder.addRow({{label, 1, LayoutBuilder::AlignAsFormLabel}, m_fileSystemFriendlyNameLineEdit});
|
||||
connect(m_fileSystemFriendlyNameLineEdit, &QLineEdit::textChanged,
|
||||
this, &KitManagerConfigWidget::setFileSystemFriendlyName);
|
||||
|
||||
@@ -222,9 +216,6 @@ void KitManagerConfigWidget::addAspectToWorkingCopy(KitAspect *aspect)
|
||||
QTC_ASSERT(widget, return);
|
||||
QTC_ASSERT(!m_widgets.contains(widget), return);
|
||||
|
||||
const QString name = aspect->displayName() + ':';
|
||||
QString toolTip = aspect->description();
|
||||
|
||||
auto action = new QAction(tr("Mark as Mutable"), nullptr);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(workingCopy()->isMutable(aspect->id()));
|
||||
@@ -239,14 +230,9 @@ void KitManagerConfigWidget::addAspectToWorkingCopy(KitAspect *aspect)
|
||||
|
||||
m_actions << action;
|
||||
|
||||
static auto alignment
|
||||
= static_cast<const Qt::Alignment>(style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
|
||||
|
||||
QLabel *label = createLabel(name, toolTip);
|
||||
LayoutBuilder builder(layout());
|
||||
builder.addRow({{label, 1, alignment}, widget->mainWidget(), widget->buttonWidget()});
|
||||
widget->addToLayout(builder);
|
||||
m_widgets.append(widget);
|
||||
m_labels.append(label);
|
||||
}
|
||||
|
||||
void KitManagerConfigWidget::updateVisibility()
|
||||
@@ -256,10 +242,7 @@ void KitManagerConfigWidget::updateVisibility()
|
||||
KitAspectWidget *widget = m_widgets.at(i);
|
||||
const bool visible = widget->visibleInKit()
|
||||
&& !m_modifiedKit->irrelevantAspects().contains(widget->kitInformationId());
|
||||
widget->mainWidget()->setVisible(visible);
|
||||
if (widget->buttonWidget())
|
||||
widget->buttonWidget()->setVisible(visible);
|
||||
m_labels.at(i)->setVisible(visible);
|
||||
widget->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,12 +393,5 @@ void KitManagerConfigWidget::showEvent(QShowEvent *event)
|
||||
widget->refresh();
|
||||
}
|
||||
|
||||
QLabel *KitManagerConfigWidget::createLabel(const QString &name, const QString &toolTip)
|
||||
{
|
||||
auto label = new QLabel(name);
|
||||
label->setToolTip(toolTip);
|
||||
return label;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -89,13 +89,11 @@ private:
|
||||
};
|
||||
|
||||
void showEvent(QShowEvent *event) override;
|
||||
QLabel *createLabel(const QString &name, const QString &toolTip);
|
||||
|
||||
QToolButton *m_iconButton;
|
||||
QLineEdit *m_nameEdit;
|
||||
QLineEdit *m_fileSystemFriendlyNameLineEdit;
|
||||
QList<KitAspectWidget *> m_widgets;
|
||||
QList<QLabel *> m_labels;
|
||||
Kit *m_kit;
|
||||
std::unique_ptr<Kit> m_modifiedKit;
|
||||
bool m_isDefaultKit = false;
|
||||
|
||||
Reference in New Issue
Block a user