forked from qt-creator/qt-creator
Utils/Core: Make an aspect container layoutable
Most aspect containers end in a widget at some time. Let them declare how. The optionspages don't need a layouter anymore when using their settings' one. There was only one case where there was none, fix that one (perforce). Change-Id: Ibd39bcd4af98c3eae1daafa59f6c1d6e7a571989 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -2430,6 +2430,7 @@ public:
|
|||||||
QList<BaseAspect *> m_ownedItems; // Owned only.
|
QList<BaseAspect *> m_ownedItems; // Owned only.
|
||||||
bool m_autoApply = true;
|
bool m_autoApply = true;
|
||||||
QStringList m_settingsGroup;
|
QStringList m_settingsGroup;
|
||||||
|
std::function<Layouting::LayoutItem ()> m_layouter;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
@@ -2483,6 +2484,16 @@ AspectContainer::const_iterator AspectContainer::end() const
|
|||||||
return d->m_items.cend();
|
return d->m_items.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AspectContainer::setLayouter(const std::function<Layouting::LayoutItem ()> &layouter)
|
||||||
|
{
|
||||||
|
d->m_layouter = layouter;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::function<LayoutItem ()> AspectContainer::layouter() const
|
||||||
|
{
|
||||||
|
return d->m_layouter;
|
||||||
|
}
|
||||||
|
|
||||||
const QList<BaseAspect *> &AspectContainer::aspects() const
|
const QList<BaseAspect *> &AspectContainer::aspects() const
|
||||||
{
|
{
|
||||||
return d->m_items;
|
return d->m_items;
|
||||||
|
@@ -710,6 +710,9 @@ public:
|
|||||||
const_iterator begin() const;
|
const_iterator begin() const;
|
||||||
const_iterator end() const;
|
const_iterator end() const;
|
||||||
|
|
||||||
|
void setLayouter(const std::function<Layouting::LayoutItem()> &layouter);
|
||||||
|
std::function<Layouting::LayoutItem()> layouter() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void applied();
|
void applied();
|
||||||
void changed();
|
void changed();
|
||||||
|
@@ -136,6 +136,13 @@ QWidget *IOptionsPage::widget()
|
|||||||
if (!m_widget) {
|
if (!m_widget) {
|
||||||
if (m_widgetCreator) {
|
if (m_widgetCreator) {
|
||||||
m_widget = m_widgetCreator();
|
m_widget = m_widgetCreator();
|
||||||
|
} else if (m_settings) {
|
||||||
|
m_widget = new IOptionsPageWidget;
|
||||||
|
if (auto layouter = m_settings->layouter()) {
|
||||||
|
layouter().attachTo(m_widget);
|
||||||
|
} else {
|
||||||
|
QTC_CHECK(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
}
|
}
|
||||||
@@ -199,15 +206,6 @@ void IOptionsPage::setSettings(AspectContainer *settings)
|
|||||||
m_settings = settings;
|
m_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IOptionsPage::setLayouter(const std::function<Layouting::LayoutItem ()> &layouter)
|
|
||||||
{
|
|
||||||
m_widgetCreator = [layouter] {
|
|
||||||
auto widget = new IOptionsPageWidget;
|
|
||||||
layouter().attachTo(widget);
|
|
||||||
return widget;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void Core::IOptionsPage::setId(Utils::Id id)
|
\fn void Core::IOptionsPage::setId(Utils::Id id)
|
||||||
|
|
||||||
|
@@ -74,7 +74,6 @@ protected:
|
|||||||
void setCategoryIcon(const Utils::Icon &categoryIcon) { m_categoryIcon = categoryIcon; }
|
void setCategoryIcon(const Utils::Icon &categoryIcon) { m_categoryIcon = categoryIcon; }
|
||||||
void setCategoryIconPath(const Utils::FilePath &categoryIconPath);
|
void setCategoryIconPath(const Utils::FilePath &categoryIconPath);
|
||||||
void setSettings(Utils::AspectContainer *settings);
|
void setSettings(Utils::AspectContainer *settings);
|
||||||
void setLayouter(const std::function<Layouting::LayoutItem()> &layouter);
|
|
||||||
|
|
||||||
// Used in FontSettingsPage. FIXME?
|
// Used in FontSettingsPage. FIXME?
|
||||||
QPointer<QWidget> m_widget; // Used in conjunction with m_widgetCreator
|
QPointer<QWidget> m_widget; // Used in conjunction with m_widgetCreator
|
||||||
|
@@ -77,6 +77,70 @@ PerforceSettings::PerforceSettings()
|
|||||||
autoOpen.setSettingsKey("PromptToOpen");
|
autoOpen.setSettingsKey("PromptToOpen");
|
||||||
autoOpen.setDefaultValue(true);
|
autoOpen.setDefaultValue(true);
|
||||||
autoOpen.setLabelText(Tr::tr("Automatically open files when editing"));
|
autoOpen.setLabelText(Tr::tr("Automatically open files when editing"));
|
||||||
|
|
||||||
|
setLayouter([this] {
|
||||||
|
using namespace Layouting;
|
||||||
|
|
||||||
|
auto errorLabel = new InfoLabel({}, InfoLabel::None);
|
||||||
|
errorLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||||
|
errorLabel->setFilled(true);
|
||||||
|
auto testButton = new QPushButton(Tr::tr("Test"));
|
||||||
|
QObject::connect(testButton, &QPushButton::clicked, errorLabel,
|
||||||
|
[this, errorLabel, testButton] {
|
||||||
|
testButton->setEnabled(false);
|
||||||
|
auto checker = new PerforceChecker(errorLabel);
|
||||||
|
checker->setUseOverideCursor(true);
|
||||||
|
QObject::connect(checker, &PerforceChecker::failed, errorLabel,
|
||||||
|
[errorLabel, testButton, checker](const QString &t) {
|
||||||
|
errorLabel->setType(InfoLabel::Error);
|
||||||
|
errorLabel->setText(t);
|
||||||
|
testButton->setEnabled(true);
|
||||||
|
checker->deleteLater();
|
||||||
|
});
|
||||||
|
QObject::connect(checker, &PerforceChecker::succeeded, errorLabel,
|
||||||
|
[errorLabel, testButton, checker](const FilePath &repo) {
|
||||||
|
errorLabel->setType(InfoLabel::Ok);
|
||||||
|
errorLabel->setText(Tr::tr("Test succeeded (%1).")
|
||||||
|
.arg(repo.toUserOutput()));
|
||||||
|
testButton->setEnabled(true);
|
||||||
|
checker->deleteLater();
|
||||||
|
});
|
||||||
|
|
||||||
|
errorLabel->setType(InfoLabel::Information);
|
||||||
|
errorLabel->setText(Tr::tr("Testing..."));
|
||||||
|
|
||||||
|
const FilePath p4Bin = FilePath::fromUserInput(
|
||||||
|
p4BinaryPath.volatileValue().toString());
|
||||||
|
checker->start(p4Bin, {}, commonP4Arguments_volatile(), 10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
Group config {
|
||||||
|
title(Tr::tr("Configuration")),
|
||||||
|
Row { p4BinaryPath }
|
||||||
|
};
|
||||||
|
|
||||||
|
Group environment {
|
||||||
|
title(Tr::tr("Environment Variables")),
|
||||||
|
customEnv.groupChecker(),
|
||||||
|
Row { p4Port, p4Client, p4User }
|
||||||
|
};
|
||||||
|
|
||||||
|
Group misc {
|
||||||
|
title(Tr::tr("Miscellaneous")),
|
||||||
|
Column {
|
||||||
|
Row { logCount, timeOutS, st },
|
||||||
|
autoOpen
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Column {
|
||||||
|
config,
|
||||||
|
environment,
|
||||||
|
misc,
|
||||||
|
Row { errorLabel, st, testButton },
|
||||||
|
st
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------PerforceSettings
|
// --------------------PerforceSettings
|
||||||
@@ -216,70 +280,6 @@ PerforceSettingsPage::PerforceSettingsPage(PerforceSettings *settings)
|
|||||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
|
|
||||||
setLayouter([settings] {
|
|
||||||
PerforceSettings &s = *settings;
|
|
||||||
using namespace Layouting;
|
|
||||||
|
|
||||||
auto errorLabel = new InfoLabel({}, InfoLabel::None);
|
|
||||||
errorLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
|
||||||
errorLabel->setFilled(true);
|
|
||||||
auto testButton = new QPushButton(Tr::tr("Test"));
|
|
||||||
QObject::connect(testButton, &QPushButton::clicked, errorLabel,
|
|
||||||
[settings, errorLabel, testButton] {
|
|
||||||
testButton->setEnabled(false);
|
|
||||||
auto checker = new PerforceChecker(errorLabel);
|
|
||||||
checker->setUseOverideCursor(true);
|
|
||||||
QObject::connect(checker, &PerforceChecker::failed, errorLabel,
|
|
||||||
[errorLabel, testButton, checker](const QString &t) {
|
|
||||||
errorLabel->setType(InfoLabel::Error);
|
|
||||||
errorLabel->setText(t);
|
|
||||||
testButton->setEnabled(true);
|
|
||||||
checker->deleteLater();
|
|
||||||
});
|
|
||||||
QObject::connect(checker, &PerforceChecker::succeeded, errorLabel,
|
|
||||||
[errorLabel, testButton, checker](const FilePath &repo) {
|
|
||||||
errorLabel->setType(InfoLabel::Ok);
|
|
||||||
errorLabel->setText(Tr::tr("Test succeeded (%1).")
|
|
||||||
.arg(repo.toUserOutput()));
|
|
||||||
testButton->setEnabled(true);
|
|
||||||
checker->deleteLater();
|
|
||||||
});
|
|
||||||
|
|
||||||
errorLabel->setType(InfoLabel::Information);
|
|
||||||
errorLabel->setText(Tr::tr("Testing..."));
|
|
||||||
|
|
||||||
const FilePath p4Bin = FilePath::fromUserInput(
|
|
||||||
settings->p4BinaryPath.volatileValue().toString());
|
|
||||||
checker->start(p4Bin, {}, settings->commonP4Arguments_volatile(), 10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
Group config {
|
|
||||||
title(Tr::tr("Configuration")),
|
|
||||||
Row { s.p4BinaryPath }
|
|
||||||
};
|
|
||||||
|
|
||||||
Group environment {
|
|
||||||
title(Tr::tr("Environment Variables")),
|
|
||||||
s.customEnv.groupChecker(),
|
|
||||||
Row { s.p4Port, s.p4Client, s.p4User }
|
|
||||||
};
|
|
||||||
|
|
||||||
Group misc {
|
|
||||||
title(Tr::tr("Miscellaneous")),
|
|
||||||
Column {
|
|
||||||
Row { s.logCount, s.timeOutS, st },
|
|
||||||
s.autoOpen
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return Column {
|
|
||||||
config,
|
|
||||||
environment,
|
|
||||||
misc,
|
|
||||||
Row { errorLabel, st, testButton },
|
|
||||||
st
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Perforce::Internal
|
} // Perforce::Internal
|
||||||
|
Reference in New Issue
Block a user