void KviOptionsWidget::childEvent(QChildEvent * e) { // handle reparents of child widgets if(e->type() == QEvent::ChildRemoved) { if(e->child()->inherits("KviOptionsWidget")) { KviOptionsWidget * pWidget = static_cast<KviOptionsWidget *>(e->child()); Q_ASSERT(pWidget); QObject::disconnect(pWidget,SIGNAL(destroyed()),this,SLOT(childOptionsWidgetDestroyed())); m_pSelectorInterfaceList->removeRef(pWidget); } } QFrame::childEvent(e); }
void KviOptionsWidget::addOptionsWidget(const QString & szText, const QIcon & iconSet, KviOptionsWidget * pWidget) { if(m_pSelectorInterfaceList->findRef(pWidget) >= 0) return; // already there ? if(pWidget->layout()) pWidget->layout()->setMargin(8); m_pTabWidget->addTab(pWidget, iconSet, szText); // add the widget to the selector interface *after* adding its widget to m_pTabWidget, // or it will we removed from m_pSelectorInterfaceList because of the addTab() call: // QTabWidget::addTab => QTabWidget::insertTab => KviOptionsWidget::eventFilter(m_pTabWidget, QEvent::ChildRemoved); m_pSelectorInterfaceList->append(pWidget); QObject::connect(pWidget, SIGNAL(destroyed()), this, SLOT(childOptionsWidgetDestroyed())); }
bool KviOptionsWidget::eventFilter(QObject * watched,QEvent * e) { // this is the tab widget if((watched == m_pTabWidget) && (e->type() == QEvent::ChildRemoved)) { QChildEvent * ev = static_cast<QChildEvent *>(e); if(ev->child()->inherits("KviOptionsWidget")) { KviOptionsWidget * pWidget = static_cast<KviOptionsWidget *>(ev->child()); Q_ASSERT(pWidget); QObject::disconnect(pWidget,SIGNAL(destroyed()),this,SLOT(childOptionsWidgetDestroyed())); m_pSelectorInterfaceList->removeRef(pWidget); return false; // continue processing } } return QFrame::eventFilter(watched,e); }