findresultwidget.cpp
changeset 829 832e96c9abb6
parent 825 1ad892c1a709
child 842 bec082472471
     1.1 --- a/findresultwidget.cpp	Mon Mar 08 12:22:15 2010 +0000
     1.2 +++ b/findresultwidget.cpp	Mon Mar 08 12:24:26 2010 +0000
     1.3 @@ -1,54 +1,104 @@
     1.4  #include "findresultwidget.h"
     1.5  
     1.6 -#include <QLineEdit>
     1.7  #include <QVBoxLayout>
     1.8 -#include <QPushButton>
     1.9  #include <QTreeView>
    1.10  
    1.11 -#include <QMenuBar>
    1.12 -#include <QDebug>
    1.13 -
    1.14 +#include "findresultitem.h"
    1.15  #include "findresultmodel.h"
    1.16 +#include "vymmodel.h"
    1.17  
    1.18  extern QString iconPath;
    1.19  
    1.20 -FindResultWidget::FindResultWidget(QWidget *)
    1.21 +FindResultWidget::FindResultWidget(VymModel *m, QWidget *)
    1.22  {
    1.23 -	// Create model
    1.24 -	model=new FindResultModel;
    1.25 +	model=m;
    1.26 +
    1.27 +	// Create results model
    1.28 +	resultsModel=new FindResultModel;
    1.29  
    1.30  	// Create TreeView
    1.31 -	view = new QTreeView;
    1.32 -	view->setModel (model);
    1.33 +	view = new QTreeView (this);
    1.34 +	view->setModel (resultsModel);
    1.35  
    1.36      QVBoxLayout* mainLayout = new QVBoxLayout;
    1.37 -    QHBoxLayout *row2Layout = new QHBoxLayout;
    1.38      
    1.39 -	// Create Buttons
    1.40 -	cancelbutton = new QPushButton;
    1.41 -	//cancelbutton->setText(tr("Cancel"));
    1.42 -	cancelbutton->setIcon (QIcon (iconPath+"fileclose.png"));
    1.43 -	cancelbutton->setShortcut (Qt::Key_Escape);
    1.44 -	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
    1.45 +	// FIXME-4 feature: show number of hits at bottom of FindResultWidget
    1.46  
    1.47 -	row2Layout->addWidget (cancelbutton);
    1.48 -	//row2Layout->addWidget(findcombo);
    1.49 -	//row2Layout->addWidget(nextbutton);
    1.50 -
    1.51 -	QMenuBar *mb=new QMenuBar;
    1.52 +	/* FIXME-3 testing QMenuBar *mb=new QMenuBar;
    1.53  	QAction *a=new  QAction ("Foo action",NULL);
    1.54  	mb->addAction (a);
    1.55  	mb->insertSeparator();
    1.56  	mainLayout->addWidget(mb);
    1.57 +	*/
    1.58  	mainLayout->addWidget(view);
    1.59 -	mainLayout->addLayout (row2Layout);
    1.60  
    1.61  	setLayout (mainLayout);
    1.62 +
    1.63 +	model=m;
    1.64 +
    1.65 +	// Selection
    1.66 +	connect (view->selectionModel(),SIGNAL (selectionChanged (QItemSelection,QItemSelection)),
    1.67 +		this, SLOT (updateSelection (QItemSelection,QItemSelection)));
    1.68 +}
    1.69 +
    1.70 +void FindResultWidget::addItem (TreeItem *ti)
    1.71 +{
    1.72 +	if (ti)
    1.73 +	{
    1.74 +		QModelIndex index = view->selectionModel()->currentIndex();
    1.75 +		//QAbstractItemModel *resultsModel = view->model();
    1.76 +		
    1.77 +		if (!resultsModel->insertRow(index.row()+1, index.parent()))
    1.78 +			return;
    1.79 +
    1.80 +		for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
    1.81 +			QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
    1.82 +			resultsModel->setData(child, QVariant(ti->getHeading()), Qt::EditRole);
    1.83 +			resultsModel->getItem(child)->setOriginal (ti);
    1.84 +		}
    1.85 +	}
    1.86 +}
    1.87 +
    1.88 +void FindResultWidget::addItem (const QString &s)
    1.89 +{
    1.90 +	if (!s.isEmpty())
    1.91 +	{
    1.92 +		QModelIndex index = view->selectionModel()->currentIndex();
    1.93 +		
    1.94 +		if (!resultsModel->insertRow(index.row()+1, index.parent()))
    1.95 +			return;
    1.96 +
    1.97 +		for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
    1.98 +			QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
    1.99 +			resultsModel->setData(child, QVariant(s), Qt::EditRole);
   1.100 +		}
   1.101 +	}
   1.102 +}
   1.103 +
   1.104 +void FindResultWidget::setModel (VymModel *m)
   1.105 +{
   1.106 +	if (model !=NULL && m!=model)
   1.107 +		qWarning ("FindResultWidget::setModel  m!=model");
   1.108 +	model=m;	
   1.109 +}
   1.110 +
   1.111 +FindResultModel* FindResultWidget::getResultModel()
   1.112 +{
   1.113 +	return resultsModel;
   1.114 +}
   1.115 +
   1.116 +void FindResultWidget::addResult (const QString &category, TreeItem *ti)
   1.117 +{
   1.118 +	if (!category.isEmpty())
   1.119 +		addItem (category);
   1.120 +	else	
   1.121 +		addItem (model->getSelectedItem());
   1.122  }
   1.123  
   1.124  void FindResultWidget::popup()
   1.125  {
   1.126  	show();
   1.127 +	parentWidget()->show();
   1.128  }
   1.129  
   1.130  void FindResultWidget::cancelPressed()
   1.131 @@ -56,10 +106,19 @@
   1.132  	emit (hideFindResultWidget() );
   1.133  }
   1.134  
   1.135 -#include <QHideEvent>
   1.136 -void FindResultWidget::hideEvent(QHideEvent *event) //FIXME-2 testing only
   1.137 +void FindResultWidget::updateSelection(QItemSelection newsel,QItemSelection)
   1.138  {
   1.139 -	qDebug()<<"FRW::hideEvent()";
   1.140 -	event->ignore();
   1.141 +	QModelIndex ix;
   1.142 +	foreach (ix,newsel.indexes() )
   1.143 +	{
   1.144 +		FindResultItem *fri= static_cast<FindResultItem*>(ix.internalPointer());
   1.145 +		if (fri->getOrgModel() && fri->getOrgID()>0)
   1.146 +		{
   1.147 +			TreeItem *ti=fri->getOrgModel()->findID(fri->getOrgID() );
   1.148 +			if (ti)
   1.149 +				fri->getOrgModel()->select (ti);
   1.150 +		}
   1.151 +	}
   1.152  }
   1.153  
   1.154 +