using QSortFilterProxy now to enable filtering in TreeEditor
authorinsilmaril
Fri Oct 02 09:40:57 2009 +0000 (2009-10-02)
changeset 80116a8ef1d82b2
parent 800 959bd133cd1a
child 802 f076fdec767d
using QSortFilterProxy now to enable filtering in TreeEditor
branchpropwindow.cpp
treeeditor.cpp
treeeditor.h
treemodel.cpp
vymmodel.cpp
vymview.cpp
vymview.h
     1.1 --- a/branchpropwindow.cpp	Thu Oct 01 13:23:20 2009 +0000
     1.2 +++ b/branchpropwindow.cpp	Fri Oct 02 09:40:57 2009 +0000
     1.3 @@ -169,6 +169,7 @@
     1.4  
     1.5  void BranchPropertyWindow::setModel (VymModel *m)
     1.6  {
     1.7 +return;
     1.8  	model=m;
     1.9  	if (model) 
    1.10  		setItem (model->getSelectedItem() );
     2.1 --- a/treeeditor.cpp	Thu Oct 01 13:23:20 2009 +0000
     2.2 +++ b/treeeditor.cpp	Fri Oct 02 09:40:57 2009 +0000
     2.3 @@ -17,15 +17,14 @@
     2.4  	model=m;
     2.5  
     2.6  /*
     2.7 +*/
     2.8  //	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-1 trying to use proxy...
     2.9  	proxyModel = new QSortFilterProxyModel (this);
    2.10  
    2.11 +//	proxyModel->setDynamicSortFilter (false);
    2.12 +	setModel(proxyModel);
    2.13  	proxyModel->setSourceModel(model);
    2.14 -
    2.15 -	proxyModel->setDynamicSortFilter (false);
    2.16 -	setModel(proxyModel);
    2.17 -*/
    2.18 -	setModel(model);
    2.19 +//	setModel(model);
    2.20  
    2.21  	QAction *a;
    2.22  	// Shortcuts for navigating with cursor:
    2.23 @@ -49,6 +48,11 @@
    2.24  	//cout <<"Destructor TreeEditor for "<<model->getMapName().toStdString()<<endl;
    2.25  }
    2.26  
    2.27 +QSortFilterProxyModel* TreeEditor::getProxyModel()
    2.28 +{
    2.29 +	return proxyModel;
    2.30 +}
    2.31 +
    2.32  void TreeEditor::setSortFilter(QString s)
    2.33  {
    2.34  	cout << "TE::setting sortFilter to "<<s.toStdString()<<endl;
     3.1 --- a/treeeditor.h	Thu Oct 01 13:23:20 2009 +0000
     3.2 +++ b/treeeditor.h	Fri Oct 02 09:40:57 2009 +0000
     3.3 @@ -16,6 +16,7 @@
     3.4  public:
     3.5      TreeEditor(VymModel *m);
     3.6  	~TreeEditor();
     3.7 +	QSortFilterProxyModel *getProxyModel();
     3.8  
     3.9  public slots:
    3.10  	void setSortFilter (QString f);
     4.1 --- a/treemodel.cpp	Thu Oct 01 13:23:20 2009 +0000
     4.2 +++ b/treemodel.cpp	Fri Oct 02 09:40:57 2009 +0000
     4.3 @@ -247,11 +247,8 @@
     4.4  
     4.5  TreeItem *TreeModel::getItem(const QModelIndex &index) const
     4.6  {
     4.7 -//FIXME-3	cout << "TM::getItem  "<<index.internalPointer()<<endl;
     4.8      if (index.isValid()) {
     4.9  		TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
    4.10 -
    4.11 -//		cout << "   item="<<item<<endl;
    4.12          if (item) return item;
    4.13      }
    4.14      return NULL;
     5.1 --- a/vymmodel.cpp	Thu Oct 01 13:23:20 2009 +0000
     5.2 +++ b/vymmodel.cpp	Fri Oct 02 09:40:57 2009 +0000
     5.3 @@ -4580,7 +4580,7 @@
     5.4  }
     5.5  */
     5.6  
     5.7 -void VymModel::testslot()	//FIXME-3
     5.8 +void VymModel::testslot()	//FIXME-3 Playing with DBUS
     5.9  {
    5.10  	cout << "VM::testslot called\n";
    5.11  }
     6.1 --- a/vymview.cpp	Thu Oct 01 13:23:20 2009 +0000
     6.2 +++ b/vymview.cpp	Fri Oct 02 09:40:57 2009 +0000
     6.3 @@ -22,34 +22,45 @@
     6.4  	treeEditor->setColumnWidth (0,150);
     6.5  	treeEditor->setAnimated (true);
     6.6  
     6.7 -	
     6.8 -	selModel=treeEditor->selectionModel();
     6.9 +	proxySelModel=treeEditor->selectionModel();
    6.10 +	selModel=new QItemSelectionModel (model);
    6.11 +
    6.12 +	//model->setSelectionModel (proxySelModel);
    6.13  	model->setSelectionModel (selModel);
    6.14 -	connect (
    6.15 -		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.16 -		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    6.17  
    6.18  	// Create good old MapEditor
    6.19  	mapEditor=model->getMapEditor();
    6.20  	if (!mapEditor) mapEditor=new MapEditor (model);
    6.21 -	connect (
    6.22 -		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.23 -		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    6.24  
    6.25 +	// Connect selections
    6.26 +
    6.27 +		// Proxymodel changed
    6.28 +		connect (
    6.29 +			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.30 +			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
    6.31 +
    6.32 +		// Model changed	
    6.33 +		connect (
    6.34 +			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.35 +			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    6.36 +
    6.37 +		connect (
    6.38 +			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
    6.39 +			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    6.40 +			//FIXME-3 above and below necessary???
    6.41 +		connect (
    6.42 +			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.43 +			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    6.44 +
    6.45 +	// Connect data changed signals	
    6.46  	connect (
    6.47  		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    6.48  		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    6.49  
    6.50 -
    6.51  	connect (
    6.52  		model, SIGNAL (sortFilterChanged (const QString &)),
    6.53  		treeEditor, SLOT (setSortFilter (const QString &) ) );
    6.54  
    6.55 -	// VymModel may want to update selection or other data, e.g. during animation
    6.56 -	connect (
    6.57 -		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    6.58 -		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    6.59 -
    6.60  	connect (
    6.61  		model, SIGNAL (noteHasChanged(QModelIndex) ),
    6.62  		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    6.63 @@ -69,22 +80,10 @@
    6.64  	addWidget (treeEditor);
    6.65  	addWidget (mapEditor);
    6.66  
    6.67 -/*
    6.68 -	tv=new QTreeView;
    6.69 -	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    6.70 -	proxyModel->setDynamicSortFilter (true);
    6.71 -	proxyModel->setSourceModel(model);
    6.72 -	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
    6.73 -	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
    6.74 -	proxyModel->setFilterKeyColumn(0);
    6.75 -	tv->setModel (proxyModel);
    6.76 -	addWidget (tv);
    6.77 -*/
    6.78  	// Set geometry
    6.79  	QList <int> widths;
    6.80  	widths<<200;
    6.81  	widths<<600;
    6.82 -//	widths<<200;
    6.83  	setSizes(widths);
    6.84  }
    6.85  
    6.86 @@ -108,28 +107,29 @@
    6.87  	mapEditor->setFocus();
    6.88  }
    6.89  
    6.90 -QItemSelectionModel* VymView::selectionModel() 
    6.91 -{
    6.92 -	if (treeEditor) 
    6.93 -		return selModel;
    6.94 -	else 
    6.95 -		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
    6.96 -	return NULL;
    6.97 -}
    6.98 -
    6.99  void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   6.100  {
   6.101  	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   6.102  	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   6.103  	// would require to also get current model in mainWindow
   6.104 +	proxySelModel->select (
   6.105 +		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
   6.106 +		QItemSelectionModel::ClearAndSelect );
   6.107 +	showSelection();
   6.108 +}
   6.109  
   6.110 -	showSelection();	// if called here, no tmpParObj can be set...
   6.111 +void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   6.112 +{
   6.113 +	// Notify mainwindow to update satellites, but map selection to 
   6.114 +	// original model first
   6.115 +
   6.116 +	// Re-emit but map selection first
   6.117 +	model->emitSelectionChanged (treeEditor->getProxyModel()->mapSelectionToSource (newsel));
   6.118  }
   6.119  
   6.120  void VymView::expandAll()
   6.121  {
   6.122  	treeEditor->expandAll();
   6.123 -	//tv->expandAll();
   6.124  }
   6.125  
   6.126  void VymView::showSelection()
     7.1 --- a/vymview.h	Thu Oct 01 13:23:20 2009 +0000
     7.2 +++ b/vymview.h	Fri Oct 02 09:40:57 2009 +0000
     7.3 @@ -20,17 +20,17 @@
     7.4  	VymModel* getModel();
     7.5  	MapEditor* getMapEditor();
     7.6  	void initFocus();
     7.7 -	QItemSelectionModel* selectionModel();
     7.8  
     7.9  public slots:
    7.10  	void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
    7.11 +	void changeProxySelection (const QItemSelection &newSel, const QItemSelection &delSel);
    7.12  	void expandAll ();
    7.13  	void showSelection ();
    7.14  
    7.15  private:
    7.16  	VymModel *model;
    7.17  	TreeEditor *treeEditor;
    7.18 -	QTreeView *tv;	//FIXME-3 testing only
    7.19 +	QItemSelectionModel *proxySelModel;
    7.20  	QItemSelectionModel *selModel;
    7.21  	MapEditor *mapEditor;
    7.22  };