Ejemplo n.º 1
0
bool CQFunctionDM::removeRows(QModelIndexList rows, const QModelIndex&)
{
  if (rows.isEmpty())
    return false;

  assert(mpDataModel != NULL);
  CModel * pModel = mpDataModel->getModel();

  if (pModel == NULL)
    return false;

//Build the list of pointers to items to be deleted
//before actually deleting any item.
  QList <CEvaluationTree *> pFunctions;
  CFunction * pFunction;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      if (!isDefaultRow(*i) &&
          (pFunction = &CRootContainer::getFunctionList()->loadedFunctions()[i->row()]) != NULL &&
          !pFunction->isReadOnly())
        pFunctions.append(&CRootContainer::getFunctionList()->loadedFunctions()[i->row()]);
    }

  QList <CEvaluationTree *>::const_iterator j;

  for (j = pFunctions.begin(); j != pFunctions.end(); ++j)
    {
      CEvaluationTree * pFunction = *j;

      size_t delRow =
        CRootContainer::getFunctionList()->loadedFunctions().CDataVector< CFunction >::getIndex(pFunction);

      if (delRow != C_INVALID_INDEX)
        {
          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "function",
                                        FROM_UTF8(pFunction->getObjectName()),
                                        pFunction);

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}