preparing sortFilter
authorinsilmaril
Thu, 01 Oct 2009 13:23:20 +0000
changeset 800959bd133cd1a
parent 799 2c42ad499ac3
child 801 16a8ef1d82b2
preparing sortFilter
mainwindow.cpp
mapeditor.cpp
treeeditor.cpp
treeeditor.h
vymmodel.cpp
vymmodel.h
vymview.cpp
     1.1 --- a/mainwindow.cpp	Thu Oct 01 11:48:58 2009 +0000
     1.2 +++ b/mainwindow.cpp	Thu Oct 01 13:23:20 2009 +0000
     1.3 @@ -3605,12 +3605,19 @@
     1.4  void Main::testFunction1()
     1.5  {
     1.6  	if (!currentMapEditor()) return;
     1.7 -	currentMapEditor()->testFunction1();
     1.8 +	//currentMapEditor()->testFunction1();
     1.9  	/*
    1.10 +	*/
    1.11  	VymModel *m=currentModel();
    1.12  	if (!m) return;
    1.13 -	m->clearItem (m->getSelectedItem());
    1.14 -	*/
    1.15 +
    1.16 +	bool ok;
    1.17 +	QString text = QInputDialog::getText(
    1.18 +			"VYM", "Enter Filter:", QLineEdit::Normal,	// FIXME-3 no translation yet
    1.19 +			m->getSortFilter(), &ok, NULL);
    1.20 +	if ( ok) 
    1.21 +		// user entered something and pressed OK
    1.22 +		m->setSortFilter (text);
    1.23  }
    1.24  
    1.25  void Main::testFunction2()
     2.1 --- a/mapeditor.cpp	Thu Oct 01 11:48:58 2009 +0000
     2.2 +++ b/mapeditor.cpp	Thu Oct 01 13:23:20 2009 +0000
     2.3 @@ -196,7 +196,6 @@
     2.4  		if (lmo) 
     2.5  		{
     2.6  			QRectF r=lmo->getBBox();
     2.7 -			cout << "ME::scrollTo "<<ti->getHeadingStd()<<"  tL="<<r.topLeft()<<"  bR="<<r.bottomRight()<<endl;
     2.8  			setScrollBarPosTarget (lmo->getBBox() );
     2.9  		}	
    2.10  	}
     3.1 --- a/treeeditor.cpp	Thu Oct 01 11:48:58 2009 +0000
     3.2 +++ b/treeeditor.cpp	Thu Oct 01 13:23:20 2009 +0000
     3.3 @@ -1,7 +1,6 @@
     3.4  #include "treeeditor.h"
     3.5  
     3.6  #include <QAction>
     3.7 -#include <QSortFilterProxyModel>
     3.8  #include <QRegExp>
     3.9  
    3.10  #include <iostream>
    3.11 @@ -19,14 +18,12 @@
    3.12  
    3.13  /*
    3.14  //	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-1 trying to use proxy...
    3.15 -	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    3.16 +	proxyModel = new QSortFilterProxyModel (this);
    3.17  
    3.18  	proxyModel->setSourceModel(model);
    3.19  
    3.20 -	proxyModel->setFilterRegExp(QRegExp("x", Qt::CaseInsensitive));
    3.21 -	proxyModel->setFilterKeyColumn(0);
    3.22 -	proxyModel->setDynamicSortFilter (true);
    3.23 -//	setModel(proxyModel);
    3.24 +	proxyModel->setDynamicSortFilter (false);
    3.25 +	setModel(proxyModel);
    3.26  */
    3.27  	setModel(model);
    3.28  
    3.29 @@ -52,6 +49,14 @@
    3.30  	//cout <<"Destructor TreeEditor for "<<model->getMapName().toStdString()<<endl;
    3.31  }
    3.32  
    3.33 +void TreeEditor::setSortFilter(QString s)
    3.34 +{
    3.35 +	cout << "TE::setting sortFilter to "<<s.toStdString()<<endl;
    3.36 +	proxyModel->setFilterRegExp(QRegExp(s, Qt::CaseInsensitive));
    3.37 +	proxyModel->setFilterKeyColumn(0);
    3.38 +	proxyModel->setDynamicSortFilter (true);
    3.39 +}
    3.40 +
    3.41  void TreeEditor::cursorUp()
    3.42  {
    3.43  	model->select (indexAbove (model->getSelectedIndex() ));
     4.1 --- a/treeeditor.h	Thu Oct 01 11:48:58 2009 +0000
     4.2 +++ b/treeeditor.h	Thu Oct 01 13:23:20 2009 +0000
     4.3 @@ -2,6 +2,7 @@
     4.4  #define TREEEDITOR_H
     4.5  
     4.6  #include <QTreeView>
     4.7 +#include <QSortFilterProxyModel>
     4.8  
     4.9  class VymModel;
    4.10  
    4.11 @@ -16,13 +17,16 @@
    4.12      TreeEditor(VymModel *m);
    4.13  	~TreeEditor();
    4.14  
    4.15 +public slots:
    4.16 +	void setSortFilter (QString f);
    4.17 +
    4.18  private slots:
    4.19  	void cursorUp();
    4.20  	void cursorDown();
    4.21  
    4.22  private:
    4.23  	VymModel *model;
    4.24 -	VymModel *proxyModel;
    4.25 +	QSortFilterProxyModel *proxyModel;
    4.26  };
    4.27  
    4.28  #endif
     5.1 --- a/vymmodel.cpp	Thu Oct 01 11:48:58 2009 +0000
     5.2 +++ b/vymmodel.cpp	Thu Oct 01 13:23:20 2009 +0000
     5.3 @@ -1507,6 +1507,17 @@
     5.4  	return c;
     5.5  }
     5.6  
     5.7 +void VymModel::setSortFilter (const QString &s)
     5.8 +{
     5.9 +	sortFilter=s;
    5.10 +	emit (sortFilterChanged (sortFilter));
    5.11 +}
    5.12 +
    5.13 +QString VymModel::getSortFilter ()
    5.14 +{
    5.15 +	return sortFilter;
    5.16 +}
    5.17 +
    5.18  void VymModel::setHeading(const QString &s)
    5.19  {
    5.20  	BranchItem *selbi=getSelectedBranch();
     6.1 --- a/vymmodel.h	Thu Oct 01 11:48:58 2009 +0000
     6.2 +++ b/vymmodel.h	Thu Oct 01 13:23:20 2009 +0000
     6.3 @@ -244,7 +244,14 @@
     6.4  	QString getDate();
     6.5  	int branchCount();
     6.6  
     6.7 -public:	
     6.8 +	void setSortFilter (const QString &);
     6.9 +	QString getSortFilter ();
    6.10 +protected:	
    6.11 +	QString sortFilter;
    6.12 +signals:
    6.13 +	void sortFilterChanged (QString );		//!< Notify editors of new filter
    6.14 +
    6.15 +public:
    6.16  	void setHeading(const QString &);		//!< Set heading of item	
    6.17  	QString getHeading ();					//!< Get heading of item
    6.18  
     7.1 --- a/vymview.cpp	Thu Oct 01 11:48:58 2009 +0000
     7.2 +++ b/vymview.cpp	Thu Oct 01 13:23:20 2009 +0000
     7.3 @@ -40,6 +40,11 @@
     7.4  		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
     7.5  		mapEditor,SLOT (updateData(const QModelIndex &) ) );
     7.6  
     7.7 +
     7.8 +	connect (
     7.9 +		model, SIGNAL (sortFilterChanged (const QString &)),
    7.10 +		treeEditor, SLOT (setSortFilter (const QString &) ) );
    7.11 +
    7.12  	// VymModel may want to update selection or other data, e.g. during animation
    7.13  	connect (
    7.14  		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),