Skip to content

Commit

Permalink
Build fix for -no-feature-action
Browse files Browse the repository at this point in the history
Change-Id: I62291af347dca7c1bb4a53d2cb698e4f1a38743d
Reviewed-by: Lars Knoll <[email protected]>
  • Loading branch information
paulolav authored and sbinner committed Mar 1, 2017
1 parent 782e1ca commit e97d6fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/widgets/widgets/qlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ bool QLineEdit::hasFrame() const
\since 5.2
*/

#if QT_CONFIG(action)
/*!
\overload
Expand Down Expand Up @@ -466,7 +467,7 @@ QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position)
addAction(result, position);
return result;
}

#endif // QT_CONFIG(action)
/*!
\property QLineEdit::clearButtonEnabled
\brief Whether the line edit displays a clear button when it is not empty.
Expand All @@ -483,6 +484,7 @@ static const char clearButtonActionNameC[] = "_q_qlineeditclearaction";

void QLineEdit::setClearButtonEnabled(bool enable)
{
#if QT_CONFIG(action)
Q_D(QLineEdit);
if (enable == isClearButtonEnabled())
return;
Expand All @@ -497,11 +499,16 @@ void QLineEdit::setClearButtonEnabled(bool enable)
d->removeAction(clearAction);
delete clearAction;
}
#endif // QT_CONFIG(action)
}

bool QLineEdit::isClearButtonEnabled() const
{
#if QT_CONFIG(action)
return findChild<QAction *>(QLatin1String(clearButtonActionNameC));
#else
return false;
#endif
}

void QLineEdit::setFrame(bool enable)
Expand Down Expand Up @@ -1432,8 +1439,10 @@ bool QLineEdit::event(QEvent * e)
|| style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
d->setCursorVisible(true);
}
#if QT_CONFIG(action)
} else if (e->type() == QEvent::ActionRemoved) {
d->removeAction(static_cast<QActionEvent *>(e)->action());
#endif
} else if (e->type() == QEvent::Resize) {
d->positionSideWidgets();
}
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/widgets/qlineedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ class Q_WIDGETS_EXPORT QLineEdit : public QWidget
void getTextMargins(int *left, int *top, int *right, int *bottom) const;
QMargins textMargins() const;

#if QT_CONFIG(action)
using QWidget::addAction;
void addAction(QAction *action, ActionPosition position);
QAction *addAction(const QIcon &icon, ActionPosition position);
#endif

public Q_SLOTS:
void setText(const QString &);
Expand Down
10 changes: 10 additions & 0 deletions src/widgets/widgets/qlineedit_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,14 @@ QIcon QLineEditPrivate::clearButtonIcon() const

void QLineEditPrivate::setClearButtonEnabled(bool enabled)
{
#if QT_CONFIG(action)
for (const SideWidgetEntry &e : trailingSideWidgets) {
if (e.flags & SideWidgetClearButton) {
e.action->setEnabled(enabled);
break;
}
}
#endif
}

void QLineEditPrivate::positionSideWidgets()
Expand All @@ -467,14 +469,18 @@ void QLineEditPrivate::positionSideWidgets()
QSize(p.widgetWidth, p.widgetHeight));
for (const SideWidgetEntry &e : leftSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
#if QT_CONFIG(action)
if (e.action->isVisible())
widgetGeometry.moveLeft(widgetGeometry.left() + delta);
#endif
}
widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin);
for (const SideWidgetEntry &e : rightSideWidgetList()) {
e.widget->setGeometry(widgetGeometry);
#if QT_CONFIG(action)
if (e.action->isVisible())
widgetGeometry.moveLeft(widgetGeometry.left() - delta);
#endif
}
}
}
Expand Down Expand Up @@ -508,10 +514,12 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE
QWidget *w = 0;
// Store flags about QWidgetAction here since removeAction() may be called from ~QAction,
// in which a qobject_cast<> no longer works.
#if QT_CONFIG(action)
if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(newAction)) {
if ((w = widgetAction->requestWidget(q)))
flags |= SideWidgetCreatedByWidgetAction;
}
#endif
if (!w) {
#if QT_CONFIG(toolbutton)
QLineEditIconButton *toolButton = new QLineEditIconButton(q);
Expand All @@ -538,6 +546,7 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE

void QLineEditPrivate::removeAction(QAction *action)
{
#if QT_CONFIG(action)
Q_Q(QLineEdit);
const PositionIndexPair positionIndex = findSideWidget(action);
if (positionIndex.second == -1)
Expand All @@ -553,6 +562,7 @@ void QLineEditPrivate::removeAction(QAction *action)
if (!hasSideWidgets()) // Last widget, remove connection
QObject::disconnect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString)));
q->update();
#endif // QT_CONFIG(action)
}

static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e)
Expand Down

0 comments on commit e97d6fd

Please sign in to comment.