vymview.cpp
author insilmaril
Fri, 02 Oct 2009 13:24:55 +0000
changeset 802 f076fdec767d
parent 801 16a8ef1d82b2
child 803 338ebdc9b947
permissions -rw-r--r--
More fixes for using proxy
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@801
    25
	proxySelModel=treeEditor->selectionModel();
insilmaril@801
    26
	selModel=new QItemSelectionModel (model);
insilmaril@801
    27
insilmaril@801
    28
	//model->setSelectionModel (proxySelModel);
insilmaril@728
    29
	model->setSelectionModel (selModel);
insilmaril@727
    30
insilmaril@726
    31
	// Create good old MapEditor
insilmaril@761
    32
	mapEditor=model->getMapEditor();
insilmaril@761
    33
	if (!mapEditor) mapEditor=new MapEditor (model);
insilmaril@772
    34
insilmaril@801
    35
	// Connect selections
insilmaril@801
    36
insilmaril@801
    37
		// Proxymodel changed
insilmaril@801
    38
		connect (
insilmaril@801
    39
			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@801
    40
			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
insilmaril@801
    41
insilmaril@801
    42
		// Model changed	
insilmaril@801
    43
		connect (
insilmaril@801
    44
			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@801
    45
			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@801
    46
insilmaril@801
    47
		connect (
insilmaril@801
    48
			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
insilmaril@801
    49
			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@801
    50
			//FIXME-3 above and below necessary???
insilmaril@801
    51
		connect (
insilmaril@801
    52
			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
insilmaril@801
    53
			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
insilmaril@801
    54
insilmaril@801
    55
	// Connect data changed signals	
insilmaril@753
    56
	connect (
insilmaril@753
    57
		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
insilmaril@761
    58
		mapEditor,SLOT (updateData(const QModelIndex &) ) );
insilmaril@726
    59
insilmaril@800
    60
	connect (
insilmaril@800
    61
		model, SIGNAL (sortFilterChanged (const QString &)),
insilmaril@800
    62
		treeEditor, SLOT (setSortFilter (const QString &) ) );
insilmaril@800
    63
insilmaril@746
    64
	connect (
insilmaril@753
    65
		model, SIGNAL (noteHasChanged(QModelIndex) ),
insilmaril@753
    66
		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
insilmaril@746
    67
		
insilmaril@763
    68
	connect (
insilmaril@763
    69
		model, SIGNAL (expandAll() ),
insilmaril@763
    70
		this, SLOT (expandAll () ) );
insilmaril@763
    71
		
insilmaril@763
    72
	connect (
insilmaril@763
    73
		model, SIGNAL (showSelection() ),
insilmaril@763
    74
		this, SLOT (showSelection() ) );
insilmaril@763
    75
		
insilmaril@726
    76
insilmaril@761
    77
	mapEditor->setAntiAlias (mainWindow->isAliased());
insilmaril@761
    78
	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
insilmaril@726
    79
insilmaril@769
    80
	addWidget (treeEditor);
insilmaril@761
    81
	addWidget (mapEditor);
insilmaril@726
    82
insilmaril@726
    83
	// Set geometry
insilmaril@761
    84
	QList <int> widths;
insilmaril@788
    85
	widths<<200;
insilmaril@761
    86
	widths<<600;
insilmaril@761
    87
	setSizes(widths);
insilmaril@726
    88
}
insilmaril@726
    89
insilmaril@772
    90
VymView::~VymView()
insilmaril@772
    91
{
insilmaril@772
    92
	//cout << "Destructor VymView\n";
insilmaril@772
    93
}
insilmaril@772
    94
insilmaril@772
    95
VymModel* VymView::getModel()
insilmaril@772
    96
{
insilmaril@772
    97
	return model;
insilmaril@772
    98
}
insilmaril@772
    99
insilmaril@772
   100
MapEditor* VymView::getMapEditor()
insilmaril@772
   101
{
insilmaril@772
   102
	return mapEditor;
insilmaril@772
   103
}
insilmaril@772
   104
insilmaril@769
   105
void VymView::initFocus()
insilmaril@769
   106
{
insilmaril@769
   107
	mapEditor->setFocus();
insilmaril@769
   108
}
insilmaril@769
   109
insilmaril@746
   110
void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
insilmaril@727
   111
{
insilmaril@746
   112
	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
insilmaril@777
   113
	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
insilmaril@777
   114
	// would require to also get current model in mainWindow
insilmaril@801
   115
	proxySelModel->select (
insilmaril@801
   116
		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
insilmaril@801
   117
		QItemSelectionModel::ClearAndSelect );
insilmaril@801
   118
	showSelection();
insilmaril@801
   119
}
insilmaril@777
   120
insilmaril@801
   121
void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
insilmaril@801
   122
{
insilmaril@801
   123
	// Notify mainwindow to update satellites, but map selection to 
insilmaril@801
   124
	// original model first
insilmaril@801
   125
insilmaril@801
   126
	// Re-emit but map selection first
insilmaril@802
   127
	selModel->select (treeEditor->getProxyModel()->mapSelectionToSource (newsel),
insilmaril@802
   128
		QItemSelectionModel::ClearAndSelect );
insilmaril@802
   129
	//showSelection();
insilmaril@727
   130
}
insilmaril@727
   131
insilmaril@763
   132
void VymView::expandAll()
insilmaril@763
   133
{
insilmaril@769
   134
	treeEditor->expandAll();
insilmaril@763
   135
}
insilmaril@763
   136
insilmaril@763
   137
void VymView::showSelection()
insilmaril@763
   138
{
insilmaril@772
   139
	QModelIndex ix=model->getSelectedIndex();
insilmaril@772
   140
	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
insilmaril@772
   141
	mapEditor->scrollTo ( ix);
insilmaril@763
   142
}
insilmaril@763
   143