Commit 14038d14 authored by hjk's avatar hjk
Browse files

BaseTreeView: Add a way to let models request item expansion



Change-Id: Ib964af4411fe7665dcb0947b52fc100eacba6a16
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 6ebdc18f
......@@ -268,18 +268,36 @@ BaseTreeView::~BaseTreeView()
void BaseTreeView::setModel(QAbstractItemModel *m)
{
struct ExtraConnection {
const char *signature;
const char *qsignal;
QObject *receiver;
const char *qslot;
};
#define DESC(sign, receiver, slot) { #sign, SIGNAL(sig), receiver, SLOT(slot) }
const ExtraConnection c[] = {
DESC(columnAdjustmentRequested(), d, resizeColumns()),
DESC(requestExpansion(QModelIndex), this, expand(QModelIndex))
};
#undef DESC
QAbstractItemModel *oldModel = model();
const char *sig = "columnAdjustmentRequested()";
if (oldModel) {
int index = model()->metaObject()->indexOfSignal(sig);
for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); ++i) {
int index = model()->metaObject()->indexOfSignal(c[i].signature);
if (index != -1)
disconnect(model(), SIGNAL(columnAdjustmentRequested()), d, SLOT(resizeColumns()));
disconnect(model(), c[i].qsignal, c[i].receiver, c[i].qslot);
}
}
TreeView::setModel(m);
if (m) {
int index = m->metaObject()->indexOfSignal(sig);
for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); ++i) {
int index = m->metaObject()->indexOfSignal(c[i].signature);
if (index != -1)
connect(m, SIGNAL(columnAdjustmentRequested()), d, SLOT(resizeColumns()));
connect(model(), c[i].qsignal, c[i].receiver, c[i].qslot);
}
d->restoreState();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment