vymview.cpp
author insilmaril
Thu, 17 Sep 2009 09:41:09 +0000
changeset 795 6b0a5f4923d3
parent 791 f1006de05c54
child 798 d251c7b2de54
permissions -rw-r--r--
Fixed sort children and addMapReplaceInt
insilmaril@726
     1
#include "vymview.h"
insilmaril@726
     2
insilmaril@727
     3
#include <iostream>
insilmaril@742
     4
using namespace std;
insilmaril@727
     5
insilmaril@732
     6
#include "mainwindow.h"
insilmaril@726
     7
#include "mapeditor.h"
insilmaril@769
     8
#include "treeeditor.h"
insilmaril@726
     9
insilmaril@732
    10
extern Main *mainWindow;
insilmaril@732
    11
insilmaril@732
    12
insilmaril@742
    13
VymView::VymView(VymModel *m)
insilmaril@726
    14
{
insilmaril@742
    15
	model=m;
insilmaril@742
    16
insilmaril@726
    17
	// Create TreeView
insilmaril@769
    18
	treeEditor=new TreeEditor (model);
insilmaril@788
    19
	//treeEditor->setModel ((QAbstractItemModel*)model);
insilmaril@769
    20
	//treeEditor->setMinimumWidth (50);
insilmaril@761
    21
insilmaril@788
    22
	treeEditor->setColumnWidth (0,150);
insilmaril@788
    23
	treeEditor->setAnimated (true);
insilmaril@726
    24
insilmaril@788
    25
	
insilmaril@769
    26
	selModel=treeEditor->selectionModel();
insilmaril@728
    27
	model->setSelectionModel (selModel);
insilmaril@727
    28
	connect (
insilmaril@727
    29
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@727
    30
		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@727
    31
insilmaril@726
    32
	// Create good old MapEditor
insilmaril@761
    33
	mapEditor=model->getMapEditor();
insilmaril@761
    34
	if (!mapEditor) mapEditor=new MapEditor (model);
insilmaril@728
    35
	connect (
insilmaril@728
    36
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@761
    37
		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@772
    38
insilmaril@753
    39
	connect (
insilmaril@753
    40
		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@761
    41
		mapEditor,SLOT (updateData(const QModelIndex &) ) );
insilmaril@726
    42
insilmaril@746
    43
	// VymModel may want to update selection or other data, e.g. during animation
insilmaril@728
    44
	connect (
insilmaril@728
    45
		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@761
    46
		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@761
    47
insilmaril@746
    48
	connect (
insilmaril@753
    49
		model, SIGNAL (noteHasChanged(QModelIndex) ),
insilmaril@753
    50
		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
insilmaril@746
    51
		
insilmaril@763
    52
	connect (
insilmaril@763
    53
		model, SIGNAL (expandAll() ),
insilmaril@763
    54
		this, SLOT (expandAll () ) );
insilmaril@763
    55
		
insilmaril@763
    56
	connect (
insilmaril@763
    57
		model, SIGNAL (showSelection() ),
insilmaril@763
    58
		this, SLOT (showSelection() ) );
insilmaril@763
    59
		
insilmaril@726
    60
insilmaril@761
    61
	mapEditor->setAntiAlias (mainWindow->isAliased());
insilmaril@761
    62
	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
insilmaril@726
    63
insilmaril@769
    64
	addWidget (treeEditor);
insilmaril@761
    65
	addWidget (mapEditor);
insilmaril@726
    66
insilmaril@788
    67
/*
insilmaril@788
    68
	tv=new QTreeView;
insilmaril@788
    69
	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
insilmaril@788
    70
	proxyModel->setDynamicSortFilter (true);
insilmaril@788
    71
	proxyModel->setSourceModel(model);
insilmaril@788
    72
	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
insilmaril@788
    73
	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
insilmaril@788
    74
	proxyModel->setFilterKeyColumn(0);
insilmaril@788
    75
	tv->setModel (proxyModel);
insilmaril@788
    76
	addWidget (tv);
insilmaril@788
    77
*/
insilmaril@726
    78
	// Set geometry
insilmaril@761
    79
	QList <int> widths;
insilmaril@788
    80
	widths<<200;
insilmaril@761
    81
	widths<<600;
insilmaril@788
    82
//	widths<<200;
insilmaril@761
    83
	setSizes(widths);
insilmaril@726
    84
}
insilmaril@726
    85
insilmaril@772
    86
VymView::~VymView()
insilmaril@772
    87
{
insilmaril@772
    88
	//cout << "Destructor VymView\n";
insilmaril@772
    89
}
insilmaril@772
    90
insilmaril@772
    91
VymModel* VymView::getModel()
insilmaril@772
    92
{
insilmaril@772
    93
	return model;
insilmaril@772
    94
}
insilmaril@772
    95
insilmaril@772
    96
MapEditor* VymView::getMapEditor()
insilmaril@772
    97
{
insilmaril@772
    98
	return mapEditor;
insilmaril@772
    99
}
insilmaril@772
   100
insilmaril@769
   101
void VymView::initFocus()
insilmaril@769
   102
{
insilmaril@769
   103
	mapEditor->setFocus();
insilmaril@769
   104
}
insilmaril@769
   105
insilmaril@726
   106
QItemSelectionModel* VymView::selectionModel() 
insilmaril@726
   107
{
insilmaril@769
   108
	if (treeEditor) 
insilmaril@728
   109
		return selModel;
insilmaril@728
   110
	else 
insilmaril@769
   111
		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
insilmaril@726
   112
	return NULL;
insilmaril@726
   113
}
insilmaril@726
   114
insilmaril@746
   115
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
insilmaril@727
   116
{
insilmaril@746
   117
	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
insilmaril@777
   118
	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
insilmaril@777
   119
	// would require to also get current model in mainWindow
insilmaril@777
   120
insilmaril@775
   121
	//showSelection();
insilmaril@727
   122
}
insilmaril@727
   123
insilmaril@763
   124
void VymView::expandAll()
insilmaril@763
   125
{
insilmaril@769
   126
	treeEditor->expandAll();
insilmaril@788
   127
	//tv->expandAll();
insilmaril@763
   128
}
insilmaril@763
   129
insilmaril@763
   130
void VymView::showSelection()
insilmaril@763
   131
{
insilmaril@772
   132
	QModelIndex ix=model->getSelectedIndex();
insilmaril@772
   133
	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
insilmaril@772
   134
	mapEditor->scrollTo ( ix);
insilmaril@763
   135
}
insilmaril@763
   136