vymview.cpp
author insilmaril
Mon, 27 Apr 2009 12:07:15 +0000
changeset 756 a8a5c7288f57
parent 753 25a77484ec72
child 759 bf3ea1f1520b
permissions -rw-r--r--
relinking branches and removing branches works
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@726
     8
insilmaril@732
     9
extern Main *mainWindow;
insilmaril@732
    10
insilmaril@732
    11
insilmaril@742
    12
VymView::VymView(VymModel *m)
insilmaril@726
    13
{
insilmaril@742
    14
	model=m;
insilmaril@742
    15
insilmaril@726
    16
	// Create TreeView
insilmaril@727
    17
	treeview=new QTreeView;
insilmaril@726
    18
	treeview->setModel ((QAbstractItemModel*)model);
insilmaril@726
    19
	treeview->setMinimumWidth (350);
insilmaril@726
    20
	treeview->setColumnWidth (0,350);
insilmaril@726
    21
insilmaril@727
    22
	selModel=treeview->selectionModel();
insilmaril@728
    23
	model->setSelectionModel (selModel);
insilmaril@727
    24
	connect (
insilmaril@727
    25
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@727
    26
		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@727
    27
insilmaril@726
    28
	// Create good old MapEditor
insilmaril@726
    29
	MapEditor* me=model->getMapEditor();
insilmaril@726
    30
	if (!me) me=new MapEditor (model);
insilmaril@728
    31
	connect (
insilmaril@728
    32
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@728
    33
		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@753
    34
		/*
insilmaril@729
    35
	connect (
insilmaril@729
    36
		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@729
    37
		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
insilmaril@753
    38
		*/
insilmaril@753
    39
		/*
insilmaril@753
    40
*/
insilmaril@753
    41
	connect (
insilmaril@753
    42
		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@753
    43
		me,SLOT (updateData(const QModelIndex &) ) );
insilmaril@726
    44
insilmaril@746
    45
	// VymModel may want to update selection or other data, e.g. during animation
insilmaril@728
    46
	connect (
insilmaril@728
    47
		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@728
    48
		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@745
    49
	connect (
insilmaril@745
    50
		model, SIGNAL (newChildObject(QModelIndex) ),
insilmaril@745
    51
		this,SLOT (updateChilds (QModelIndex) ) );
insilmaril@746
    52
	connect (
insilmaril@753
    53
		model, SIGNAL (noteHasChanged(QModelIndex) ),
insilmaril@753
    54
		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
insilmaril@746
    55
		
insilmaril@726
    56
insilmaril@746
    57
	//me->viewport()->setFocus();	//FIXME-3 needed?
insilmaril@732
    58
	me->setAntiAlias (mainWindow->isAliased());
insilmaril@732
    59
	me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
insilmaril@726
    60
insilmaril@726
    61
	addWidget (treeview);
insilmaril@726
    62
	addWidget (me);
insilmaril@726
    63
insilmaril@726
    64
	// Set geometry
insilmaril@726
    65
	QList <int> sizes;
insilmaril@735
    66
	sizes.append (120);
insilmaril@726
    67
	sizes.append (600);
insilmaril@726
    68
	setSizes (sizes);
insilmaril@726
    69
}
insilmaril@726
    70
insilmaril@726
    71
QItemSelectionModel* VymView::selectionModel() 
insilmaril@726
    72
{
insilmaril@728
    73
	if (treeview) 
insilmaril@728
    74
		return selModel;
insilmaril@728
    75
	else 
insilmaril@728
    76
		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
insilmaril@726
    77
	return NULL;
insilmaril@726
    78
}
insilmaril@726
    79
insilmaril@726
    80
insilmaril@745
    81
void VymView::updateChilds (QModelIndex ix)
insilmaril@745
    82
{
insilmaril@745
    83
	treeview->setExpanded (ix,true);
insilmaril@745
    84
}
insilmaril@745
    85
insilmaril@746
    86
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
insilmaril@727
    87
{
insilmaril@746
    88
	/*
insilmaril@746
    89
	cout <<"VymView::changeSelection (";
insilmaril@746
    90
	if (!newsel.indexes().isEmpty() )
insilmaril@746
    91
		cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
insilmaril@746
    92
	cout << " <- ";
insilmaril@746
    93
	if (!oldsel.indexes().isEmpty() )
insilmaril@746
    94
		cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
insilmaril@746
    95
	cout << ")\n";
insilmaril@746
    96
	*/
insilmaril@727
    97
insilmaril@746
    98
	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
insilmaril@746
    99
	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
insilmaril@727
   100
}
insilmaril@727
   101