void tst_ModelTest::testInsertThroughProxy()
{
    DynamicTreeModel *model = new DynamicTreeModel(this);

    QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
    proxy->setSourceModel(model);

    new ModelTest(proxy, this);

    ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this);
    insertCommand->setNumCols(4);
    insertCommand->setStartRow(0);
    insertCommand->setEndRow(9);
    // Parent is QModelIndex()
    insertCommand->doCommand();

    insertCommand = new ModelInsertCommand(model, this);
    insertCommand->setNumCols(4);
    insertCommand->setAncestorRowNumbers(QList<int>() << 5);
    insertCommand->setStartRow(0);
    insertCommand->setEndRow(9);
    insertCommand->doCommand();

    ModelMoveCommand *moveCommand = new ModelMoveCommand(model, this);
    moveCommand->setNumCols(4);
    moveCommand->setStartRow(0);
    moveCommand->setEndRow(0);
    moveCommand->setDestRow(9);
    moveCommand->setDestAncestors(QList<int>() << 5);
    moveCommand->doCommand();
}
Esempio n. 2
0
void LessThanWidget::insertGrid(QList<int> address)
{
  ModelInsertCommand *ins = new ModelInsertCommand(m_coloredTreeModel, this);
  ins->setAncestorRowNumbers(address);
  ins->setNumCols(5);
  ins->setStartRow(0);
  ins->setEndRow(5);
  ins->doCommand();
}
Esempio n. 3
0
CheckableWidget::CheckableWidget(QWidget* parent, Qt::WindowFlags f)
  : QWidget(parent, f)
{
  QHBoxLayout *layout = new QHBoxLayout(this);
  QSplitter *vSplitter = new QSplitter( this );
  layout->addWidget(vSplitter);

  DynamicTreeModel *rootModel = new DynamicTreeModel(this);

  ModelInsertCommand *insert = new ModelInsertCommand(rootModel, this);
  insert->setStartRow(0);
  insert->interpret(
    "- 1"
    "- 1"
    "- 1"
    "- - 2"
    "- - 2"
    "- - 2"
    "- - 2"
    "- 1"
    "- 1"
    "- 1"
    "- - 2"
    "- - - 3"
    "- - - - 4"
    "- - - - 4"
    "- - - 3"
    "- - - 3"
    "- - - 3"
    "- - 2"
    "- - 2"
    "- - 2"
    "- 1"
    "- 1"
  );
  insert->doCommand();

  QItemSelectionModel *checkModel = new QItemSelectionModel(rootModel, this);
  KCheckableProxyModel *checkable = new KCheckableProxyModel(this);
  checkable->setSourceModel(rootModel);
  checkable->setSelectionModel(checkModel);

  QTreeView *tree1 = new QTreeView(vSplitter);
  tree1->setModel(checkable);
  tree1->expandAll();

  KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(checkModel, this);
  selectionProxy->setFilterBehavior(KSelectionProxyModel::ExactSelection);
  selectionProxy->setSourceModel(rootModel);

  QTreeView *tree2 = new QTreeView(vSplitter);
  tree2->setModel(selectionProxy);
}