40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#include "widget.h"
|
|
#include "tools.h"
|
|
|
|
#include <QPushButton>
|
|
#include <QTreeView>
|
|
#include <QVBoxLayout>
|
|
|
|
Widget::Widget(QWidget *parent)
|
|
: QWidget(parent), model(new QStandardItemModel(this))
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
auto widget = new QTreeView(this);
|
|
layout->addWidget(widget);
|
|
widget->setModel(model);
|
|
|
|
|
|
Tools::ModelSyncs<QString>* xmodel = new Tools::ModelSyncs<QString>(model,
|
|
[](const QString &d, QStandardItem *n){return d == n->text();},
|
|
[](const QString &d, QStandardItem *i){i->setText(d);});
|
|
|
|
model->appendRow(new QStandardItem("sldkjflkdf"));
|
|
|
|
auto button = new QPushButton("click");
|
|
layout->addWidget(button);
|
|
|
|
connect(button, &QPushButton::clicked, [this, xmodel](){
|
|
xmodel->presentSync([](const QString &x){
|
|
if(x.length() > 3)
|
|
return QList<QString>();
|
|
|
|
return QList<QString>() << x + "a" << x + "b" << x + "c" << x + "d";
|
|
});
|
|
});
|
|
}
|
|
|
|
Widget::~Widget()
|
|
{
|
|
}
|
|
|