void NickListWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
  Q_ASSERT(model());
  if(!parent.isValid()) {
    // ok this means that whole networks are about to be removed
    // we can't determine which buffers are affect, so we hope that all nets are removed
    // this is the most common case (for example disconnecting from the core or terminating the clint)
    NickView *nickView;
    QHash<BufferId, NickView *>::iterator iter = nickViews.begin();
    while(iter != nickViews.end()) {
      nickView = *iter;
      iter = nickViews.erase(iter);
      ui.stackedWidget->removeWidget(nickView);
      QAbstractItemModel *model = nickView->model();
      nickView->setModel(0);
      if(QSortFilterProxyModel *filter = qobject_cast<QSortFilterProxyModel *>(model))
	filter->setSourceModel(0);
      model->deleteLater();
      nickView->deleteLater();
    }
  } else {
    // check if there are explicitly buffers removed
    for(int i = start; i <= end; i++) {
      QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole);
      if(!variant.isValid())
	continue;

      BufferId bufferId = qVariantValue<BufferId>(variant);
      removeBuffer(bufferId);
    }
  }
}
bool CoaToolsSqlBrowser::exec()
{
   BEGIN;
   if (m_isValid != true) RETURN(false);

   CoaSqlQueryModel *model = new CoaSqlQueryModel(m_table);
   CoaSqlQuery query(m_connectionWidget->currentDatabase());
   query.execChecked(m_sqlEdit->toPlainText());
   model->setQuery(query);

   QAbstractItemModel *oldmodel = m_table->model();
   m_table->setModel(model);
   if (oldmodel != 0) oldmodel->deleteLater();
   m_table->reset();

   if (model->lastError().type() != QSqlError::NoError){
      emit statusMessage(model->lastError().text());
      RETURN(false);
   } else if (model->query().isSelect()) {
      emit statusMessage(tr("Query OK."));
      RETURN(true);
   } else {
      emit statusMessage(tr("Query OK, number of affected rows: %1").arg(model->query().numRowsAffected()));
      RETURN(true);
   }
}
示例#3
0
void ctkPluginBrowser::pluginSelected(const QModelIndex &index)
{
    QVariant v = index.data(Qt::UserRole);

    QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->getPlugin(v.toLongLong());
    if (!plugin) return;
    updatePluginToolbar(plugin);

    QAbstractItemModel* oldModel = ui.pluginResourcesTreeView->model();
    ui.pluginResourcesTreeView->setModel(new ctkPluginResourcesTreeModel(plugin, this));
    if (oldModel) oldModel->deleteLater();;
}
void NickListWidget::removeBuffer(BufferId bufferId) {
  if(!nickViews.contains(bufferId))
    return;

  NickView *view = nickViews.take(bufferId);
  ui.stackedWidget->removeWidget(view);
  QAbstractItemModel *model = view->model();
  view->setModel(0);
  if(QSortFilterProxyModel *filter = qobject_cast<QSortFilterProxyModel *>(model))
    filter->setSourceModel(0);
  model->deleteLater();
  view->deleteLater();
}
示例#5
0
/**
 * @brief MainWindow::setDocumentModel
 *
 * Will be called whe a new q2d::Project is created, to link the projects
 * document model with the appropriate list view in the UI.
 * @param model
 */
void
MainWindow::slot_setDocumentModel(QStandardItemModel* model) {

    // close all tabs related to the old model
    m_ui->schematicsTabWidget->clear();

    QListView* documentView = m_ui->documentListView;

    documentView->clearSelection();
    QAbstractItemModel* oldModel = documentView->model();

    m_ui->documentListView->setModel(model);

    if (oldModel != nullptr) {
        oldModel->disconnect();
        oldModel->deleteLater();
    }
}
void CoaToolsSqlBrowser::slotShowTable(const CoaString &t)
{
   BEGIN;

   if (m_isValid != true) return;
   INF(CoaString("Show Table %1").arg(t));

   CoaSqlTableModel *model = new CoaSqlTableModel(m_table, m_connectionWidget->currentDatabase());

   model->setTable(t);
   model->select();
   if (model->lastError().type() != QSqlError::NoError)
        emit statusMessage(model->lastError().text());

   QAbstractItemModel *oldmodel = m_table->model();
   m_table->setModel(model);
   if (oldmodel != 0) oldmodel->deleteLater();

}