예제 #1
0
MatchCheckingWidget::MatchCheckingWidget(QWidget* parent, Qt::WindowFlags f)
  : QWidget(parent, f)
{
  QVBoxLayout *layout = new QVBoxLayout(this);

  m_lineEdit = new QLineEdit();

  connect(m_lineEdit, SIGNAL(textChanged(QString)), SLOT(matchChanged(QString)));


  m_dynamicTreeRadioButton = new QRadioButton("Dynamic Tree Model", this);
  m_selectionModelRadioButton = new QRadioButton("Selection Model", this);

  layout->addWidget(m_lineEdit);
  layout->addWidget(m_dynamicTreeRadioButton);
  layout->addWidget(m_selectionModelRadioButton);

  QSplitter *splitter = new QSplitter(this);
  layout->addWidget(splitter);
  DynamicTreeModel *dynamicTreeModel = new DynamicTreeModel(this);

  m_dynamicTreeWidget = new DynamicTreeWidget(dynamicTreeModel, this);

  splitter->addWidget(m_dynamicTreeWidget);

  KSelectionProxyModel *selectionProxyModel = new KSelectionProxyModel(m_dynamicTreeWidget->treeView()->selectionModel(), this);
  selectionProxyModel->setSourceModel(dynamicTreeModel);

  m_selectionTreeView = new QTreeView(this);
  m_selectionTreeView->setModel(selectionProxyModel);
  splitter->addWidget(m_selectionTreeView);
}
예제 #2
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);
}
예제 #3
0
SelectionProxyWidget::SelectionProxyWidget(QWidget *parent): QWidget(parent)
{
    QHBoxLayout *layout = new QHBoxLayout(this);
    QSplitter *splitter = new QSplitter(this);
    layout->addWidget(splitter);

    m_rootModel = new DynamicTreeModel(this);

    DynamicTreeWidget *dynTreeWidget = new DynamicTreeWidget(m_rootModel, splitter);

    dynTreeWidget->setInitialTree(
        QLatin1String("- 1"
        "- 2"
        "- - 3"
        "- - 3"
        "- - - 4"
        "- - - 4"
        "- - - - 4"
        "- - 4"
        "- - 5"
        "- - - 4"
        "- - - - 4"
        "- - 5"
        "- 6"
        "- 7"
        "- - 8"
        "- - - 9"
        "- - - 10"
        "- - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - - - - 9"
        "- - - - - - - - 10"
        "- - - - - - - - 9"
        "- - - - - - - 10"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 9"
        "- - - - - 10"
        "- - - - - - 9"
        "- - - - - - 10"
        "- - - - 10"
        "- - 11"
        "- - 12"
        "- 13"
        "- 14"
        "- 15"
        "- - 16"
        "- - - 17"
        "- - - 18"
        "- 19"
        "- 20"
        "- 21"));

    QTreeView *selectionTree = createLabelledView(QStringLiteral("Selection"), splitter);
    selectionTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
    selectionTree->setModel(m_rootModel);
    selectionTree->expandAll();

#define SUBTREES
#define SUBTREEROOTS
#define SUBTREESWITHOUTROOTS
#define EXACTSELECTION
#define CHILDRENOFEXACTSELECTION

#ifdef SUBTREES
    KSelectionProxyModel *selectedBranchesModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesModel->setSourceModel(m_rootModel);
    selectedBranchesModel->setFilterBehavior(KSelectionProxyModel::SubTrees);

    QTreeView *selectedBranchesView = createLabelledView(QStringLiteral("SubTrees"), splitter);
    selectedBranchesView->setModel(selectedBranchesModel);
#endif

#ifdef SUBTREEROOTS
    KSelectionProxyModel *selectedBranchesRootsModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesRootsModel->setSourceModel(m_rootModel);
    selectedBranchesRootsModel->setFilterBehavior(KSelectionProxyModel::SubTreeRoots);

    QTreeView *selectedBranchesRootsView = createLabelledView(QStringLiteral("SubTreeRoots"), splitter);
    selectedBranchesRootsView->setModel(selectedBranchesRootsModel);
#endif

#ifdef SUBTREESWITHOUTROOTS
    KSelectionProxyModel *selectedBranchesChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    selectedBranchesChildrenModel->setSourceModel(m_rootModel);
    selectedBranchesChildrenModel->setFilterBehavior(KSelectionProxyModel::SubTreesWithoutRoots);

    QTreeView *selectedBranchesChildrenView = createLabelledView(QStringLiteral("SubTreesWithoutRoots"), splitter);
    selectedBranchesChildrenView->setModel(selectedBranchesChildrenModel);
#endif

#ifdef EXACTSELECTION
    KSelectionProxyModel *onlySelectedModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    onlySelectedModel->setSourceModel(m_rootModel);
    onlySelectedModel->setFilterBehavior(KSelectionProxyModel::ExactSelection);

    QTreeView *onlySelectedView = createLabelledView(QStringLiteral("ExactSelection"), splitter);
    onlySelectedView->setModel(onlySelectedModel);
#endif

#ifdef CHILDRENOFEXACTSELECTION
    KSelectionProxyModel *onlySelectedChildrenModel = new KSelectionProxyModel(selectionTree->selectionModel(), this);
    onlySelectedChildrenModel->setSourceModel(m_rootModel);
    onlySelectedChildrenModel->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection);

    QTreeView *onlySelectedChildrenView = createLabelledView(QStringLiteral("ChildrenOfExactSelection"), splitter);
    onlySelectedChildrenView->setModel(onlySelectedChildrenModel);
#endif
}