vymview.cpp
author insilmaril
Tue May 26 11:24:51 2009 +0000 (2009-05-26)
changeset 774 2f002657dada
parent 769 a6931cd6309a
child 775 6e4b586aa88a
permissions -rw-r--r--
added missing new files
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@769
    19
	treeEditor->setModel ((QAbstractItemModel*)model);
insilmaril@769
    20
	//treeEditor->setMinimumWidth (50);
insilmaril@761
    21
insilmaril@769
    22
	treeEditor->setColumnWidth (0,350);
insilmaril@726
    23
insilmaril@769
    24
	selModel=treeEditor->selectionModel();
insilmaril@728
    25
	model->setSelectionModel (selModel);
insilmaril@727
    26
	connect (
insilmaril@727
    27
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@727
    28
		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@727
    29
insilmaril@726
    30
	// Create good old MapEditor
insilmaril@761
    31
	mapEditor=model->getMapEditor();
insilmaril@761
    32
	if (!mapEditor) mapEditor=new MapEditor (model);
insilmaril@728
    33
	connect (
insilmaril@728
    34
		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@761
    35
		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@772
    36
insilmaril@753
    37
	connect (
insilmaril@753
    38
		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@761
    39
		mapEditor,SLOT (updateData(const QModelIndex &) ) );
insilmaril@726
    40
insilmaril@746
    41
	// VymModel may want to update selection or other data, e.g. during animation
insilmaril@728
    42
	connect (
insilmaril@728
    43
		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@761
    44
		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@761
    45
insilmaril@746
    46
	connect (
insilmaril@753
    47
		model, SIGNAL (noteHasChanged(QModelIndex) ),
insilmaril@753
    48
		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
insilmaril@746
    49
		
insilmaril@763
    50
	connect (
insilmaril@763
    51
		model, SIGNAL (expandAll() ),
insilmaril@763
    52
		this, SLOT (expandAll () ) );
insilmaril@763
    53
		
insilmaril@763
    54
	connect (
insilmaril@763
    55
		model, SIGNAL (showSelection() ),
insilmaril@763
    56
		this, SLOT (showSelection() ) );
insilmaril@763
    57
		
insilmaril@726
    58
insilmaril@761
    59
	mapEditor->setAntiAlias (mainWindow->isAliased());
insilmaril@761
    60
	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
insilmaril@726
    61
insilmaril@769
    62
	addWidget (treeEditor);
insilmaril@761
    63
	addWidget (mapEditor);
insilmaril@726
    64
insilmaril@726
    65
	// Set geometry
insilmaril@761
    66
	QList <int> widths;
insilmaril@761
    67
	widths<<120;
insilmaril@761
    68
	widths<<600;
insilmaril@761
    69
	setSizes(widths);
insilmaril@726
    70
}
insilmaril@726
    71
insilmaril@772
    72
VymView::~VymView()
insilmaril@772
    73
{
insilmaril@772
    74
	//cout << "Destructor VymView\n";
insilmaril@772
    75
}
insilmaril@772
    76
insilmaril@772
    77
VymModel* VymView::getModel()
insilmaril@772
    78
{
insilmaril@772
    79
	return model;
insilmaril@772
    80
}
insilmaril@772
    81
insilmaril@772
    82
MapEditor* VymView::getMapEditor()
insilmaril@772
    83
{
insilmaril@772
    84
	return mapEditor;
insilmaril@772
    85
}
insilmaril@772
    86
insilmaril@769
    87
void VymView::initFocus()
insilmaril@769
    88
{
insilmaril@769
    89
	mapEditor->setFocus();
insilmaril@769
    90
}
insilmaril@769
    91
insilmaril@726
    92
QItemSelectionModel* VymView::selectionModel() 
insilmaril@726
    93
{
insilmaril@769
    94
	if (treeEditor) 
insilmaril@728
    95
		return selModel;
insilmaril@728
    96
	else 
insilmaril@769
    97
		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
insilmaril@726
    98
	return NULL;
insilmaril@726
    99
}
insilmaril@726
   100
insilmaril@746
   101
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
insilmaril@727
   102
{
insilmaril@746
   103
	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
insilmaril@746
   104
	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
insilmaril@767
   105
	showSelection();
insilmaril@727
   106
}
insilmaril@727
   107
insilmaril@763
   108
void VymView::expandAll()
insilmaril@763
   109
{
insilmaril@769
   110
	treeEditor->expandAll();
insilmaril@763
   111
}
insilmaril@763
   112
insilmaril@763
   113
void VymView::showSelection()
insilmaril@763
   114
{
insilmaril@772
   115
	QModelIndex ix=model->getSelectedIndex();
insilmaril@772
   116
	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
insilmaril@772
   117
	mapEditor->scrollTo ( ix);
insilmaril@763
   118
}
insilmaril@763
   119