+
+}
+
+void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *config) {
+ BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
+ if(filter) {
+ filter->setConfig(config);
+ setConfig(config);
+ return;
+ }
+
+ if(model()) {
+ disconnect(this, 0, model(), 0);
+ disconnect(model(), 0, this, 0);
+ }
+
+ if(!model_) {
+ setModel(model_);
+ } else {
+ BufferViewFilter *filter = new BufferViewFilter(model_, config);
+ setModel(filter);
+ connect(filter, SIGNAL(configChanged()), this, SLOT(on_configChanged()));
+ }
+ setConfig(config);
+}
+
+void BufferView::setSelectionModel(QItemSelectionModel *selectionModel) {
+ if(QTreeView::selectionModel())
+ disconnect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ model(), SIGNAL(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
+
+ QTreeView::setSelectionModel(selectionModel);
+ BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
+ if(filter) {
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ filter, SLOT(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
+ }
+}
+
+void BufferView::setConfig(BufferViewConfig *config) {
+ if(_config == config)
+ return;
+
+ if(_config) {
+ disconnect(_config, 0, this, 0);
+ }
+
+ _config = config;
+ if(config) {
+ connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(setRootIndexForNetworkId(const NetworkId &)));
+ setRootIndexForNetworkId(config->networkId());
+ } else {
+ setRootIndex(QModelIndex());
+ }
+}
+
+void BufferView::setRootIndexForNetworkId(const NetworkId &networkId) {
+ if(!networkId.isValid() || !model()) {
+ setRootIndex(QModelIndex());
+ } else {
+ int networkCount = model()->rowCount();
+ QModelIndex child;
+ for(int i = 0; i < networkCount; i++) {
+ child = model()->index(i, 0);
+ if(networkId == model()->data(child, NetworkModel::NetworkIdRole).value<NetworkId>())
+ setRootIndex(child);
+ }
+ }