treeeditor.cpp
author insilmaril
Wed, 25 Nov 2009 15:28:05 +0000
changeset 809 0a1abd218f36
parent 804 14f2b1b15242
child 822 c2ce9944148c
permissions -rw-r--r--
Removing unneeded findwindow.*
     1 #include "treeeditor.h"
     2 
     3 #include <QAction>
     4 #include <QRegExp>
     5 
     6 #include <iostream>
     7 using namespace std;
     8 
     9 #include "vymmodel.h"
    10 
    11 ///////////////////////////////////////////////////////////////////////
    12 ///////////////////////////////////////////////////////////////////////
    13 TreeEditor::TreeEditor(VymModel *m)
    14 {
    15 	model=m;
    16 
    17 	// FIXME-2 use proxmodel
    18 	//proxyModel = new MySortFilterProxyModel(this);	
    19 	//setModel(proxyModel);
    20 	setModel(m);
    21 	//proxyModel->setSourceModel(model);
    22 
    23 	QAction *a;
    24 	// Shortcuts for navigating with cursor:
    25     a = new QAction(tr( "Select upper object","Tree Editor" ), this);
    26 	a->setStatusTip ( tr( "Select upper object" ));
    27 	a->setShortcut (Qt::Key_Up );
    28 	a->setShortcutContext (Qt::WidgetShortcut);
    29 	addAction (a);
    30     connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
    31 
    32     a = new QAction( tr( "Select lower object","Tree Editor" ),this);
    33 	a->setStatusTip (tr( "Select lower object" ));
    34 	a->setShortcut ( Qt::Key_Down );
    35 	a->setShortcutContext (Qt::WidgetShortcut);
    36 	addAction (a);
    37     connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
    38 }
    39 
    40 TreeEditor::~TreeEditor()
    41 {
    42 	//cout <<"Destructor TreeEditor for "<<model->getMapName().toStdString()<<endl;
    43 }
    44 
    45 MySortFilterProxyModel* TreeEditor::getProxyModel()
    46 {
    47 	return proxyModel;
    48 }
    49 
    50 QModelIndex TreeEditor::getSelectedIndex()
    51 {
    52 	QModelIndexList list=selectionModel()->selectedIndexes();
    53 	if (list.isEmpty() )
    54 		return QModelIndex();
    55 	else
    56 		return list.first();
    57 }
    58 
    59 
    60 void TreeEditor::setSortFilter(QString s)
    61 {
    62 	proxyModel->setFilterRegExp(QRegExp(s, Qt::CaseInsensitive));
    63 	proxyModel->setFilterKeyColumn(0);
    64 	proxyModel->setDynamicSortFilter (true);
    65 }
    66 
    67 void TreeEditor::cursorUp()
    68 {
    69 	QModelIndex ix=getSelectedIndex();
    70 	// FIXME-2 useproxymodel ix=proxyModel->mapToSource (indexAbove(ix));
    71 	ix=indexAbove (ix);
    72 	if (ix.isValid())
    73 		model->select (ix );
    74 }
    75 
    76 void TreeEditor::cursorDown()
    77 {
    78 	QModelIndex ix=getSelectedIndex();
    79 	//FIXME-2 useProxymodel ix=proxyModel->mapToSource (indexBelow(ix));
    80 	ix=indexBelow (ix);
    81 	if (ix.isValid())
    82 		model->select (ix );
    83 }
    84