forked from qt-creator/qt-creator
BaseTreeView: Add a way to let models request item expansion
Change-Id: Ib964af4411fe7665dcb0947b52fc100eacba6a16 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -268,18 +268,36 @@ BaseTreeView::~BaseTreeView()
|
|||||||
|
|
||||||
void BaseTreeView::setModel(QAbstractItemModel *m)
|
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();
|
QAbstractItemModel *oldModel = model();
|
||||||
const char *sig = "columnAdjustmentRequested()";
|
|
||||||
if (oldModel) {
|
if (oldModel) {
|
||||||
int index = model()->metaObject()->indexOfSignal(sig);
|
for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); ++i) {
|
||||||
if (index != -1)
|
int index = model()->metaObject()->indexOfSignal(c[i].signature);
|
||||||
disconnect(model(), SIGNAL(columnAdjustmentRequested()), d, SLOT(resizeColumns()));
|
if (index != -1)
|
||||||
|
disconnect(model(), c[i].qsignal, c[i].receiver, c[i].qslot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeView::setModel(m);
|
TreeView::setModel(m);
|
||||||
|
|
||||||
if (m) {
|
if (m) {
|
||||||
int index = m->metaObject()->indexOfSignal(sig);
|
for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); ++i) {
|
||||||
if (index != -1)
|
int index = m->metaObject()->indexOfSignal(c[i].signature);
|
||||||
connect(m, SIGNAL(columnAdjustmentRequested()), d, SLOT(resizeColumns()));
|
if (index != -1)
|
||||||
|
connect(model(), c[i].qsignal, c[i].receiver, c[i].qslot);
|
||||||
|
}
|
||||||
d->restoreState();
|
d->restoreState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user