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