Small fixes to delegate chooser implementation
This commit is contained in:
parent
c37495fae2
commit
c8f97216fa
@ -5,7 +5,7 @@ import com.github.nheko 1.0
|
|||||||
import "./delegates"
|
import "./delegates"
|
||||||
|
|
||||||
DelegateChooser {
|
DelegateChooser {
|
||||||
role: "type"
|
//role: "type" //< not supported in our custom implementation, have to use roleValue
|
||||||
width: chat.width
|
width: chat.width
|
||||||
roleValue: model.type
|
roleValue: model.type
|
||||||
|
|
||||||
@ -46,7 +46,6 @@ DelegateChooser {
|
|||||||
TimelineRow { view: chat; Redacted { id: kid } }
|
TimelineRow { view: chat; Redacted { id: kid } }
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
//roleValue: MtxEvent.Redacted
|
|
||||||
TimelineRow { view: chat; Placeholder { id: kid } }
|
TimelineRow { view: chat; Placeholder { id: kid } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,15 @@ Rectangle {
|
|||||||
onMovementEnded: updatePosition()
|
onMovementEnded: updatePosition()
|
||||||
|
|
||||||
spacing: 4
|
spacing: 4
|
||||||
delegate: RowDelegateChooser {}
|
delegate: RowDelegateChooser {
|
||||||
|
function isFullyVisible() {
|
||||||
|
return height > 1 && (y - chat.contentY - 1) + height < chat.height
|
||||||
|
}
|
||||||
|
function getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
property: "section"
|
property: "section"
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
// uses private API, which moved between versions
|
// uses private API, which moved between versions
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
||||||
#include <QtQmlModels/private/qqmladaptormodel_p.h>
|
|
||||||
#else
|
|
||||||
#include <QtQml/private/qqmladaptormodel_p.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QQmlComponent *
|
QQmlComponent *
|
||||||
DelegateChoice::delegate() const
|
DelegateChoice::delegate() const
|
||||||
@ -70,44 +65,11 @@ DelegateChooser::choices()
|
|||||||
&DelegateChooser::clearChoices);
|
&DelegateChooser::clearChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
|
||||||
DelegateChooser::role() const
|
|
||||||
{
|
|
||||||
return role_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DelegateChooser::setRole(const QString &role)
|
|
||||||
{
|
|
||||||
if (role != role_) {
|
|
||||||
role_ = role;
|
|
||||||
emit roleChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QQmlComponent *
|
|
||||||
DelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int row, int column) const
|
|
||||||
{
|
|
||||||
auto value = adaptorModel->value(adaptorModel->indexAt(row, column), role_);
|
|
||||||
|
|
||||||
for (const auto choice : choices_) {
|
|
||||||
auto choiceValue = choice->roleValue();
|
|
||||||
if (!value.isValid() || choiceValue == value) {
|
|
||||||
nhlog::ui()->debug("Returned delegate for {}", role_.toStdString());
|
|
||||||
return choice->delegate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nhlog::ui()->debug("Returned null delegate");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DelegateChooser::appendChoice(QQmlListProperty<DelegateChoice> *p, DelegateChoice *c)
|
DelegateChooser::appendChoice(QQmlListProperty<DelegateChoice> *p, DelegateChoice *c)
|
||||||
{
|
{
|
||||||
DelegateChooser *dc = static_cast<DelegateChooser *>(p->object);
|
DelegateChooser *dc = static_cast<DelegateChooser *>(p->object);
|
||||||
dc->choices_.append(c);
|
dc->choices_.append(c);
|
||||||
// dc->recalcChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -132,8 +94,6 @@ DelegateChooser::recalcChild()
|
|||||||
for (const auto choice : choices_) {
|
for (const auto choice : choices_) {
|
||||||
auto choiceValue = choice->roleValue();
|
auto choiceValue = choice->roleValue();
|
||||||
if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
|
if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
|
||||||
nhlog::ui()->debug("Returned delegate for {}", role_.toStdString());
|
|
||||||
|
|
||||||
if (child) {
|
if (child) {
|
||||||
// delete child;
|
// delete child;
|
||||||
child = nullptr;
|
child = nullptr;
|
||||||
|
@ -44,19 +44,13 @@ class DelegateChooser : public QQuickItem
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Q_PROPERTY(QQmlListProperty<DelegateChoice> choices READ choices CONSTANT)
|
Q_PROPERTY(QQmlListProperty<DelegateChoice> choices READ choices CONSTANT)
|
||||||
Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged)
|
|
||||||
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
||||||
|
|
||||||
QQmlListProperty<DelegateChoice> choices();
|
QQmlListProperty<DelegateChoice> choices();
|
||||||
|
|
||||||
QString role() const;
|
|
||||||
void setRole(const QString &role);
|
|
||||||
|
|
||||||
QVariant roleValue() const;
|
QVariant roleValue() const;
|
||||||
void setRoleValue(const QVariant &value);
|
void setRoleValue(const QVariant &value);
|
||||||
|
|
||||||
QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = 0) const;
|
|
||||||
|
|
||||||
void recalcChild();
|
void recalcChild();
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
|
||||||
@ -65,7 +59,6 @@ signals:
|
|||||||
void roleValueChanged();
|
void roleValueChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString role_;
|
|
||||||
QVariant roleValue_;
|
QVariant roleValue_;
|
||||||
QList<DelegateChoice *> choices_;
|
QList<DelegateChoice *> choices_;
|
||||||
QQuickItem *child;
|
QQuickItem *child;
|
||||||
|
Loading…
Reference in New Issue
Block a user