# HG changeset patch
# User insilmaril
# Date 1254476457 0
# Node ID 16a8ef1d82b29cfd970c67eb5da579aa7822c128
# Parent  959bd133cd1a3ba1c8d5f746d25a898cdbc689a2
using QSortFilterProxy now to enable filtering in TreeEditor

diff -r 959bd133cd1a -r 16a8ef1d82b2 branchpropwindow.cpp
--- a/branchpropwindow.cpp	Thu Oct 01 13:23:20 2009 +0000
+++ b/branchpropwindow.cpp	Fri Oct 02 09:40:57 2009 +0000
@@ -169,6 +169,7 @@
 
 void BranchPropertyWindow::setModel (VymModel *m)
 {
+return;
 	model=m;
 	if (model) 
 		setItem (model->getSelectedItem() );
diff -r 959bd133cd1a -r 16a8ef1d82b2 treeeditor.cpp
--- a/treeeditor.cpp	Thu Oct 01 13:23:20 2009 +0000
+++ b/treeeditor.cpp	Fri Oct 02 09:40:57 2009 +0000
@@ -17,15 +17,14 @@
 	model=m;
 
 /*
+*/
 //	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-1 trying to use proxy...
 	proxyModel = new QSortFilterProxyModel (this);
 
+//	proxyModel->setDynamicSortFilter (false);
+	setModel(proxyModel);
 	proxyModel->setSourceModel(model);
-
-	proxyModel->setDynamicSortFilter (false);
-	setModel(proxyModel);
-*/
-	setModel(model);
+//	setModel(model);
 
 	QAction *a;
 	// Shortcuts for navigating with cursor:
@@ -49,6 +48,11 @@
 	//cout <<"Destructor TreeEditor for "<<model->getMapName().toStdString()<<endl;
 }
 
+QSortFilterProxyModel* TreeEditor::getProxyModel()
+{
+	return proxyModel;
+}
+
 void TreeEditor::setSortFilter(QString s)
 {
 	cout << "TE::setting sortFilter to "<<s.toStdString()<<endl;
diff -r 959bd133cd1a -r 16a8ef1d82b2 treeeditor.h
--- a/treeeditor.h	Thu Oct 01 13:23:20 2009 +0000
+++ b/treeeditor.h	Fri Oct 02 09:40:57 2009 +0000
@@ -16,6 +16,7 @@
 public:
     TreeEditor(VymModel *m);
 	~TreeEditor();
+	QSortFilterProxyModel *getProxyModel();
 
 public slots:
 	void setSortFilter (QString f);
diff -r 959bd133cd1a -r 16a8ef1d82b2 treemodel.cpp
--- a/treemodel.cpp	Thu Oct 01 13:23:20 2009 +0000
+++ b/treemodel.cpp	Fri Oct 02 09:40:57 2009 +0000
@@ -247,11 +247,8 @@
 
 TreeItem *TreeModel::getItem(const QModelIndex &index) const
 {
-//FIXME-3	cout << "TM::getItem  "<<index.internalPointer()<<endl;
     if (index.isValid()) {
 		TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
-
-//		cout << "   item="<<item<<endl;
         if (item) return item;
     }
     return NULL;
diff -r 959bd133cd1a -r 16a8ef1d82b2 vymmodel.cpp
--- a/vymmodel.cpp	Thu Oct 01 13:23:20 2009 +0000
+++ b/vymmodel.cpp	Fri Oct 02 09:40:57 2009 +0000
@@ -4580,7 +4580,7 @@
 }
 */
 
-void VymModel::testslot()	//FIXME-3
+void VymModel::testslot()	//FIXME-3 Playing with DBUS
 {
 	cout << "VM::testslot called\n";
 }
diff -r 959bd133cd1a -r 16a8ef1d82b2 vymview.cpp
--- a/vymview.cpp	Thu Oct 01 13:23:20 2009 +0000
+++ b/vymview.cpp	Fri Oct 02 09:40:57 2009 +0000
@@ -22,34 +22,45 @@
 	treeEditor->setColumnWidth (0,150);
 	treeEditor->setAnimated (true);
 
-	
-	selModel=treeEditor->selectionModel();
+	proxySelModel=treeEditor->selectionModel();
+	selModel=new QItemSelectionModel (model);
+
+	//model->setSelectionModel (proxySelModel);
 	model->setSelectionModel (selModel);
-	connect (
-		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
 
 	// Create good old MapEditor
 	mapEditor=model->getMapEditor();
 	if (!mapEditor) mapEditor=new MapEditor (model);
-	connect (
-		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
 
+	// Connect selections
+
+		// Proxymodel changed
+		connect (
+			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
+			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
+
+		// Model changed	
+		connect (
+			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
+			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
+
+		connect (
+			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
+			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
+			//FIXME-3 above and below necessary???
+		connect (
+			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
+			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
+
+	// Connect data changed signals	
 	connect (
 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
 
-
 	connect (
 		model, SIGNAL (sortFilterChanged (const QString &)),
 		treeEditor, SLOT (setSortFilter (const QString &) ) );
 
-	// VymModel may want to update selection or other data, e.g. during animation
-	connect (
-		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
-
 	connect (
 		model, SIGNAL (noteHasChanged(QModelIndex) ),
 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
@@ -69,22 +80,10 @@
 	addWidget (treeEditor);
 	addWidget (mapEditor);
 
-/*
-	tv=new QTreeView;
-	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
-	proxyModel->setDynamicSortFilter (true);
-	proxyModel->setSourceModel(model);
-	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
-	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
-	proxyModel->setFilterKeyColumn(0);
-	tv->setModel (proxyModel);
-	addWidget (tv);
-*/
 	// Set geometry
 	QList <int> widths;
 	widths<<200;
 	widths<<600;
-//	widths<<200;
 	setSizes(widths);
 }
 
@@ -108,28 +107,29 @@
 	mapEditor->setFocus();
 }
 
-QItemSelectionModel* VymView::selectionModel() 
-{
-	if (treeEditor) 
-		return selModel;
-	else 
-		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
-	return NULL;
-}
-
 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
 {
 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
 	// would require to also get current model in mainWindow
+	proxySelModel->select (
+		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
+		QItemSelectionModel::ClearAndSelect );
+	showSelection();
+}
 
-	showSelection();	// if called here, no tmpParObj can be set...
+void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
+{
+	// Notify mainwindow to update satellites, but map selection to 
+	// original model first
+
+	// Re-emit but map selection first
+	model->emitSelectionChanged (treeEditor->getProxyModel()->mapSelectionToSource (newsel));
 }
 
 void VymView::expandAll()
 {
 	treeEditor->expandAll();
-	//tv->expandAll();
 }
 
 void VymView::showSelection()
diff -r 959bd133cd1a -r 16a8ef1d82b2 vymview.h
--- a/vymview.h	Thu Oct 01 13:23:20 2009 +0000
+++ b/vymview.h	Fri Oct 02 09:40:57 2009 +0000
@@ -20,17 +20,17 @@
 	VymModel* getModel();
 	MapEditor* getMapEditor();
 	void initFocus();
-	QItemSelectionModel* selectionModel();
 
 public slots:
 	void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
+	void changeProxySelection (const QItemSelection &newSel, const QItemSelection &delSel);
 	void expandAll ();
 	void showSelection ();
 
 private:
 	VymModel *model;
 	TreeEditor *treeEditor;
-	QTreeView *tv;	//FIXME-3 testing only
+	QItemSelectionModel *proxySelModel;
 	QItemSelectionModel *selModel;
 	MapEditor *mapEditor;
 };