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