forked from qt-creator/qt-creator
Core: Add a ActionBuilder::setOnToggled function
... and use it in the setup of some IOutputPane actions. Change-Id: If4c79d4f8ae73ca320e8c35d5f1e2f30a8c7050f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -146,11 +146,6 @@ void ActionBuilder::setOnTriggered(const std::function<void ()> &func)
|
||||
QObject::connect(d->contextAction, &QAction::triggered, d->contextAction, func);
|
||||
}
|
||||
|
||||
void ActionBuilder::setOnToggled(QObject *guard, const std::function<void (bool)> &func)
|
||||
{
|
||||
QObject::connect(d->contextAction, &QAction::toggled, guard, func);
|
||||
}
|
||||
|
||||
void ActionBuilder::setDefaultKeySequence(const QKeySequence &seq)
|
||||
{
|
||||
d->command->setDefaultKeySequence(seq);
|
||||
|
@@ -44,7 +44,6 @@ public:
|
||||
void setCommandDescription(const QString &desc);
|
||||
void setContainer(Utils::Id containerId, Utils::Id groupId = {}, bool needsToExist = true);
|
||||
void setOnTriggered(const std::function<void()> &func);
|
||||
void setOnToggled(QObject *guard, const std::function<void(bool)> &func);
|
||||
|
||||
template<class T, typename F>
|
||||
void setOnTriggered(T *guard,
|
||||
@@ -58,6 +57,18 @@ public:
|
||||
connectionType);
|
||||
}
|
||||
|
||||
template<class T, typename F>
|
||||
void setOnToggled(T *guard,
|
||||
F &&function,
|
||||
Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
{
|
||||
QObject::connect(contextAction(),
|
||||
&QAction::toggled,
|
||||
guard,
|
||||
std::forward<F>(function),
|
||||
connectionType);
|
||||
}
|
||||
|
||||
void setDefaultKeySequence(const QKeySequence &seq);
|
||||
void setDefaultKeySequences(const QList<QKeySequence> &seqs);
|
||||
void setDefaultKeySequence(const QString &mac, const QString &nonMac);
|
||||
|
@@ -9,15 +9,6 @@
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
class CommandButton;
|
||||
class IContext;
|
||||
@@ -114,9 +105,6 @@ private:
|
||||
int m_priority = -1;
|
||||
Core::CommandButton * const m_zoomInButton;
|
||||
Core::CommandButton * const m_zoomOutButton;
|
||||
QAction *m_filterActionRegexp = nullptr;
|
||||
QAction *m_filterActionCaseSensitive = nullptr;
|
||||
QAction *m_invertFilterAction = nullptr;
|
||||
Utils::FancyLineEdit *m_filterOutputLineEdit = nullptr;
|
||||
bool m_filterRegexp = false;
|
||||
bool m_invertFilter = false;
|
||||
|
@@ -176,29 +176,25 @@ void IOutputPane::setWheelZoomEnabled(bool enabled)
|
||||
|
||||
void IOutputPane::setupFilterUi(const Key &historyKey)
|
||||
{
|
||||
m_filterOutputLineEdit = new FancyLineEdit;
|
||||
m_filterActionRegexp = new QAction(this);
|
||||
m_filterActionRegexp->setCheckable(true);
|
||||
m_filterActionRegexp->setText(Tr::tr("Use Regular Expressions"));
|
||||
connect(m_filterActionRegexp, &QAction::toggled, this, &IOutputPane::setRegularExpressions);
|
||||
Core::ActionManager::registerAction(m_filterActionRegexp, filterRegexpActionId());
|
||||
ActionBuilder filterRegexpAction(this, filterRegexpActionId());
|
||||
filterRegexpAction.setText(Tr::tr("Use Regular Expressions"));
|
||||
filterRegexpAction.setCheckable(true);
|
||||
filterRegexpAction.setOnToggled(this, &IOutputPane::setRegularExpressions);
|
||||
|
||||
m_filterActionCaseSensitive = new QAction(this);
|
||||
m_filterActionCaseSensitive->setCheckable(true);
|
||||
m_filterActionCaseSensitive->setText(Tr::tr("Case Sensitive"));
|
||||
connect(m_filterActionCaseSensitive, &QAction::toggled, this, &IOutputPane::setCaseSensitive);
|
||||
Core::ActionManager::registerAction(m_filterActionCaseSensitive,
|
||||
filterCaseSensitivityActionId());
|
||||
ActionBuilder filterCaseSensitiveAction(this, filterCaseSensitivityActionId());
|
||||
filterCaseSensitiveAction.setText(Tr::tr("Case Sensitive"));
|
||||
filterCaseSensitiveAction.setCheckable(true);
|
||||
filterCaseSensitiveAction.setOnToggled(this, &IOutputPane::setCaseSensitive);
|
||||
|
||||
m_invertFilterAction = new QAction(this);
|
||||
m_invertFilterAction->setCheckable(true);
|
||||
m_invertFilterAction->setText(Tr::tr("Show Non-matching Lines"));
|
||||
connect(m_invertFilterAction, &QAction::toggled, this, [this] {
|
||||
m_invertFilter = m_invertFilterAction->isChecked();
|
||||
ActionBuilder invertFilterAction(this, filterInvertedActionId());
|
||||
invertFilterAction.setText(Tr::tr("Show Non-matching Lines"));
|
||||
invertFilterAction.setCheckable(true);
|
||||
invertFilterAction.setOnToggled(this, [this, action=invertFilterAction.contextAction()] {
|
||||
m_invertFilter = action->isChecked();
|
||||
updateFilter();
|
||||
});
|
||||
Core::ActionManager::registerAction(m_invertFilterAction, filterInvertedActionId());
|
||||
|
||||
m_filterOutputLineEdit = new FancyLineEdit;
|
||||
m_filterOutputLineEdit->setPlaceholderText(Tr::tr("Filter output..."));
|
||||
m_filterOutputLineEdit->setButtonVisible(FancyLineEdit::Left, true);
|
||||
m_filterOutputLineEdit->setButtonIcon(FancyLineEdit::Left, Icons::MAGNIFIER.icon());
|
||||
|
Reference in New Issue
Block a user