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