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