Beispiel #1
0
QModelIndex ChapterModel::createNewChapter(const QModelIndex& index)
{
  ChapterFile *file = dynamic_cast<ChapterFile*>(priv::treeItem(index));
  if( file == 0 ) {
    return QModelIndex();
  }
  ChapterNode *sources = dynamic_cast<ChapterNode*>(file->parentItem());
  if( sources == 0  ||  !sources->isSource() ) {
    return QModelIndex();
  }

  const int count = index.row()+1;

  const QStringList files = sources->files(count);

  const QModelIndex parent = ChapterModel::parent(index);
  beginRemoveRows(parent, 0, count-1);
  sources->remove(count);
  endRemoveRows();

  ChapterRoot *root = dynamic_cast<ChapterRoot*>(_root);
  beginInsertRows(QModelIndex(), sources->row(), sources->row());
  ChapterNode *newNode = new ChapterNode(root);
  root->insert(newNode);
  newNode->setTitle(tr("New Chapter"));
  newNode->setFiles(files);
  endInsertRows();

  return ChapterModel::index(newNode->row(), 0, QModelIndex());
}