Skip to content

Commit

Permalink
refactor: remove superfluous signal to slot connection
Browse files Browse the repository at this point in the history
Now Filter::filterChanged and Sorter::sorterChanged are both protected
functions and not anymore signals.
Derived classes call these functions directly to indicated that they have
changed.
  • Loading branch information
oKcerG committed Jun 7, 2017
1 parent e109c91 commit 070597a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
33 changes: 16 additions & 17 deletions filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace qqsfpm {

Filter::Filter(QObject *parent) : QObject(parent)
{
connect(this, &Filter::filterChanged, this, &Filter::onFilterChanged);
}

bool Filter::enabled() const
Expand Down Expand Up @@ -35,7 +34,7 @@ void Filter::setInverted(bool inverted)

m_inverted = inverted;
Q_EMIT invertedChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool Filter::filterAcceptsRow(const QModelIndex &sourceIndex) const
Expand All @@ -53,7 +52,7 @@ void Filter::proxyModelCompleted()

}

void Filter::onFilterChanged()
void Filter::filterChanged()
{
if (m_enabled)
invalidate();
Expand All @@ -71,7 +70,7 @@ void RoleFilter::setRoleName(const QString& roleName)

m_roleName = roleName;
Q_EMIT roleNameChanged();
Q_EMIT filterChanged();
filterChanged();
}

QVariant RoleFilter::sourceData(const QModelIndex &sourceIndex) const
Expand All @@ -91,7 +90,7 @@ void ValueFilter::setValue(const QVariant& value)

m_value = value;
Q_EMIT valueChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool ValueFilter::filterRow(const QModelIndex& sourceIndex) const
Expand All @@ -111,7 +110,7 @@ void IndexFilter::setMinimumIndex(const QVariant& minimumIndex)

m_minimumIndex = minimumIndex;
Q_EMIT minimumIndexChanged();
Q_EMIT filterChanged();
filterChanged();
}

const QVariant& IndexFilter::maximumIndex() const
Expand All @@ -126,7 +125,7 @@ void IndexFilter::setMaximumIndex(const QVariant& maximumIndex)

m_maximumIndex = maximumIndex;
Q_EMIT maximumIndexChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool IndexFilter::filterRow(const QModelIndex& sourceIndex) const
Expand Down Expand Up @@ -159,8 +158,8 @@ void RegExpFilter::setPattern(const QString& pattern)

m_pattern = pattern;
m_regExp.setPattern(pattern);
Q_EMIT filterChanged();
Q_EMIT patternChanged();
filterChanged();
}

QQmlSortFilterProxyModel::PatternSyntax RegExpFilter::syntax() const
Expand All @@ -175,8 +174,8 @@ void RegExpFilter::setSyntax(QQmlSortFilterProxyModel::PatternSyntax syntax)

m_syntax = syntax;
m_regExp.setPatternSyntax(static_cast<QRegExp::PatternSyntax>(syntax));
Q_EMIT filterChanged();
Q_EMIT syntaxChanged();
filterChanged();
}

Qt::CaseSensitivity RegExpFilter::caseSensitivity() const
Expand All @@ -191,8 +190,8 @@ void RegExpFilter::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)

m_caseSensitivity = caseSensitivity;
m_regExp.setCaseSensitivity(caseSensitivity);
Q_EMIT filterChanged();
Q_EMIT caseSensitivityChanged();
filterChanged();
}

bool RegExpFilter::filterRow(const QModelIndex& sourceIndex) const
Expand All @@ -213,7 +212,7 @@ void RangeFilter::setMinimumValue(QVariant minimumValue)

m_minimumValue = minimumValue;
Q_EMIT minimumValueChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool RangeFilter::minimumInclusive() const
Expand All @@ -228,7 +227,7 @@ void RangeFilter::setMinimumInclusive(bool minimumInclusive)

m_minimumInclusive = minimumInclusive;
Q_EMIT minimumInclusiveChanged();
Q_EMIT filterChanged();
filterChanged();
}

QVariant RangeFilter::maximumValue() const
Expand All @@ -243,7 +242,7 @@ void RangeFilter::setMaximumValue(QVariant maximumValue)

m_maximumValue = maximumValue;
Q_EMIT maximumValueChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool RangeFilter::maximumInclusive() const
Expand All @@ -258,7 +257,7 @@ void RangeFilter::setMaximumInclusive(bool maximumInclusive)

m_maximumInclusive = maximumInclusive;
Q_EMIT maximumInclusiveChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool RangeFilter::filterRow(const QModelIndex& sourceIndex) const
Expand All @@ -285,7 +284,7 @@ void ExpressionFilter::setExpression(const QQmlScriptString& scriptString)
updateExpression();

Q_EMIT expressionChanged();
Q_EMIT filterChanged();
filterChanged();
}

bool ExpressionFilter::filterRow(const QModelIndex& sourceIndex) const
Expand Down Expand Up @@ -362,7 +361,7 @@ void ExpressionFilter::updateExpression()

delete m_expression;
m_expression = new QQmlExpression(m_scriptString, m_context, 0, this);
connect(m_expression, &QQmlExpression::valueChanged, this, &Filter::filterChanged);
connect(m_expression, &QQmlExpression::valueChanged, this, &ExpressionFilter::filterChanged);
m_expression->setNotifyOnValueChanged(true);
m_expression->evaluate();
}
Expand All @@ -383,7 +382,7 @@ void FilterContainer::append_filter(QQmlListProperty<Filter>* list, Filter* filt

FilterContainer* that = static_cast<FilterContainer*>(list->object);
that->m_filters.append(filter);
connect(filter, &Filter::invalidate, that, &Filter::filterChanged);
connect(filter, &Filter::invalidate, that, &FilterContainer::filterChanged);
that->filterChanged();
}

Expand Down
5 changes: 1 addition & 4 deletions filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ class Filter : public QObject
Q_SIGNALS:
void enabledChanged();
void invertedChanged();
void filterChanged();
void invalidate();

protected:
QQmlSortFilterProxyModel* proxyModel() const;
virtual bool filterRow(const QModelIndex &sourceIndex) const = 0;
virtual void proxyModelCompleted();

private Q_SLOTS:
void onFilterChanged();
void filterChanged();

private:
bool m_enabled = true;
Expand Down
11 changes: 5 additions & 6 deletions sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace qqsfpm {

Sorter::Sorter(QObject *parent) : QObject(parent)
{
connect(this, &Sorter::sorterChanged, this, &Sorter::onSorterChanged);
}

Sorter::~Sorter() = default;
Expand Down Expand Up @@ -37,7 +36,7 @@ void Sorter::setAscendingOrder(bool ascendingOrder)

m_ascendingOrder = ascendingOrder;
Q_EMIT ascendingOrderChanged();
Q_EMIT sorterChanged();
sorterChanged();
}

int Sorter::compareRows(const QModelIndex &source_left, const QModelIndex &source_right) const
Expand Down Expand Up @@ -72,7 +71,7 @@ void Sorter::proxyModelCompleted()

}

void Sorter::onSorterChanged()
void Sorter::sorterChanged()
{
if (m_enabled)
Q_EMIT invalidate();
Expand All @@ -90,7 +89,7 @@ void RoleSorter::setRoleName(const QString& roleName)

m_roleName = roleName;
Q_EMIT roleNameChanged();
Q_EMIT sorterChanged();
sorterChanged();
}

int RoleSorter::compare(const QModelIndex &sourceLeft, const QModelIndex& sourceRight) const
Expand Down Expand Up @@ -118,7 +117,7 @@ void ExpressionSorter::setExpression(const QQmlScriptString& scriptString)
updateExpression();

Q_EMIT expressionChanged();
Q_EMIT sorterChanged();
sorterChanged();
}

bool evaluateBoolExpression(QQmlExpression& expression)
Expand Down Expand Up @@ -205,7 +204,7 @@ void ExpressionSorter::updateExpression()

delete m_expression;
m_expression = new QQmlExpression(m_scriptString, m_context, 0, this);
connect(m_expression, &QQmlExpression::valueChanged, this, &Sorter::sorterChanged);
connect(m_expression, &QQmlExpression::valueChanged, this, &ExpressionSorter::sorterChanged);
m_expression->setNotifyOnValueChanged(true);
m_expression->evaluate();
}
Expand Down
5 changes: 1 addition & 4 deletions sorter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Sorter : public QObject
void enabledChanged();
void ascendingOrderChanged();

void sorterChanged();
void invalidate();

protected:
Expand All @@ -39,9 +38,7 @@ class Sorter : public QObject
virtual int compare(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const;
virtual bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const;
virtual void proxyModelCompleted();

private Q_SLOTS:
void onSorterChanged();
void sorterChanged();

private:
bool m_enabled = true;
Expand Down

0 comments on commit 070597a

Please sign in to comment.