vymview.cpp
changeset 801 16a8ef1d82b2
parent 800 959bd133cd1a
child 802 f076fdec767d
     1.1 --- a/vymview.cpp	Thu Oct 01 13:23:20 2009 +0000
     1.2 +++ b/vymview.cpp	Fri Oct 02 09:40:57 2009 +0000
     1.3 @@ -22,34 +22,45 @@
     1.4  	treeEditor->setColumnWidth (0,150);
     1.5  	treeEditor->setAnimated (true);
     1.6  
     1.7 -	
     1.8 -	selModel=treeEditor->selectionModel();
     1.9 +	proxySelModel=treeEditor->selectionModel();
    1.10 +	selModel=new QItemSelectionModel (model);
    1.11 +
    1.12 +	//model->setSelectionModel (proxySelModel);
    1.13  	model->setSelectionModel (selModel);
    1.14 -	connect (
    1.15 -		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.16 -		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    1.17  
    1.18  	// Create good old MapEditor
    1.19  	mapEditor=model->getMapEditor();
    1.20  	if (!mapEditor) mapEditor=new MapEditor (model);
    1.21 -	connect (
    1.22 -		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.23 -		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.24  
    1.25 +	// Connect selections
    1.26 +
    1.27 +		// Proxymodel changed
    1.28 +		connect (
    1.29 +			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.30 +			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
    1.31 +
    1.32 +		// Model changed	
    1.33 +		connect (
    1.34 +			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.35 +			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    1.36 +
    1.37 +		connect (
    1.38 +			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
    1.39 +			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.40 +			//FIXME-3 above and below necessary???
    1.41 +		connect (
    1.42 +			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.43 +			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.44 +
    1.45 +	// Connect data changed signals	
    1.46  	connect (
    1.47  		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    1.48  		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    1.49  
    1.50 -
    1.51  	connect (
    1.52  		model, SIGNAL (sortFilterChanged (const QString &)),
    1.53  		treeEditor, SLOT (setSortFilter (const QString &) ) );
    1.54  
    1.55 -	// VymModel may want to update selection or other data, e.g. during animation
    1.56 -	connect (
    1.57 -		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.58 -		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.59 -
    1.60  	connect (
    1.61  		model, SIGNAL (noteHasChanged(QModelIndex) ),
    1.62  		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    1.63 @@ -69,22 +80,10 @@
    1.64  	addWidget (treeEditor);
    1.65  	addWidget (mapEditor);
    1.66  
    1.67 -/*
    1.68 -	tv=new QTreeView;
    1.69 -	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    1.70 -	proxyModel->setDynamicSortFilter (true);
    1.71 -	proxyModel->setSourceModel(model);
    1.72 -	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
    1.73 -	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
    1.74 -	proxyModel->setFilterKeyColumn(0);
    1.75 -	tv->setModel (proxyModel);
    1.76 -	addWidget (tv);
    1.77 -*/
    1.78  	// Set geometry
    1.79  	QList <int> widths;
    1.80  	widths<<200;
    1.81  	widths<<600;
    1.82 -//	widths<<200;
    1.83  	setSizes(widths);
    1.84  }
    1.85  
    1.86 @@ -108,28 +107,29 @@
    1.87  	mapEditor->setFocus();
    1.88  }
    1.89  
    1.90 -QItemSelectionModel* VymView::selectionModel() 
    1.91 -{
    1.92 -	if (treeEditor) 
    1.93 -		return selModel;
    1.94 -	else 
    1.95 -		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
    1.96 -	return NULL;
    1.97 -}
    1.98 -
    1.99  void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   1.100  {
   1.101  	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   1.102  	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   1.103  	// would require to also get current model in mainWindow
   1.104 +	proxySelModel->select (
   1.105 +		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
   1.106 +		QItemSelectionModel::ClearAndSelect );
   1.107 +	showSelection();
   1.108 +}
   1.109  
   1.110 -	showSelection();	// if called here, no tmpParObj can be set...
   1.111 +void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   1.112 +{
   1.113 +	// Notify mainwindow to update satellites, but map selection to 
   1.114 +	// original model first
   1.115 +
   1.116 +	// Re-emit but map selection first
   1.117 +	model->emitSelectionChanged (treeEditor->getProxyModel()->mapSelectionToSource (newsel));
   1.118  }
   1.119  
   1.120  void VymView::expandAll()
   1.121  {
   1.122  	treeEditor->expandAll();
   1.123 -	//tv->expandAll();
   1.124  }
   1.125  
   1.126  void VymView::showSelection()