findresultwidget.cpp
author insilmaril
Thu, 18 Mar 2010 11:55:59 +0000
changeset 840 c13937960f1d
parent 829 832e96c9abb6
child 842 bec082472471
permissions -rw-r--r--
Added missing return values
     1 #include "findresultwidget.h"
     2 
     3 #include <QVBoxLayout>
     4 #include <QTreeView>
     5 
     6 #include "findresultitem.h"
     7 #include "findresultmodel.h"
     8 #include "vymmodel.h"
     9 
    10 extern QString iconPath;
    11 
    12 FindResultWidget::FindResultWidget(VymModel *m, QWidget *)
    13 {
    14 	model=m;
    15 
    16 	// Create results model
    17 	resultsModel=new FindResultModel;
    18 
    19 	// Create TreeView
    20 	view = new QTreeView (this);
    21 	view->setModel (resultsModel);
    22 
    23     QVBoxLayout* mainLayout = new QVBoxLayout;
    24     
    25 	// FIXME-4 feature: show number of hits at bottom of FindResultWidget
    26 
    27 	/* FIXME-3 testing QMenuBar *mb=new QMenuBar;
    28 	QAction *a=new  QAction ("Foo action",NULL);
    29 	mb->addAction (a);
    30 	mb->insertSeparator();
    31 	mainLayout->addWidget(mb);
    32 	*/
    33 	mainLayout->addWidget(view);
    34 
    35 	setLayout (mainLayout);
    36 
    37 	model=m;
    38 
    39 	// Selection
    40 	connect (view->selectionModel(),SIGNAL (selectionChanged (QItemSelection,QItemSelection)),
    41 		this, SLOT (updateSelection (QItemSelection,QItemSelection)));
    42 }
    43 
    44 void FindResultWidget::addItem (TreeItem *ti)
    45 {
    46 	if (ti)
    47 	{
    48 		QModelIndex index = view->selectionModel()->currentIndex();
    49 		//QAbstractItemModel *resultsModel = view->model();
    50 		
    51 		if (!resultsModel->insertRow(index.row()+1, index.parent()))
    52 			return;
    53 
    54 		for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
    55 			QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
    56 			resultsModel->setData(child, QVariant(ti->getHeading()), Qt::EditRole);
    57 			resultsModel->getItem(child)->setOriginal (ti);
    58 		}
    59 	}
    60 }
    61 
    62 void FindResultWidget::addItem (const QString &s)
    63 {
    64 	if (!s.isEmpty())
    65 	{
    66 		QModelIndex index = view->selectionModel()->currentIndex();
    67 		
    68 		if (!resultsModel->insertRow(index.row()+1, index.parent()))
    69 			return;
    70 
    71 		for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
    72 			QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
    73 			resultsModel->setData(child, QVariant(s), Qt::EditRole);
    74 		}
    75 	}
    76 }
    77 
    78 void FindResultWidget::setModel (VymModel *m)
    79 {
    80 	if (model !=NULL && m!=model)
    81 		qWarning ("FindResultWidget::setModel  m!=model");
    82 	model=m;	
    83 }
    84 
    85 FindResultModel* FindResultWidget::getResultModel()
    86 {
    87 	return resultsModel;
    88 }
    89 
    90 void FindResultWidget::addResult (const QString &category, TreeItem *ti)
    91 {
    92 	if (!category.isEmpty())
    93 		addItem (category);
    94 	else	
    95 		addItem (model->getSelectedItem());
    96 }
    97 
    98 void FindResultWidget::popup()
    99 {
   100 	show();
   101 	parentWidget()->show();
   102 }
   103 
   104 void FindResultWidget::cancelPressed()
   105 {
   106 	emit (hideFindResultWidget() );
   107 }
   108 
   109 void FindResultWidget::updateSelection(QItemSelection newsel,QItemSelection)
   110 {
   111 	QModelIndex ix;
   112 	foreach (ix,newsel.indexes() )
   113 	{
   114 		FindResultItem *fri= static_cast<FindResultItem*>(ix.internalPointer());
   115 		if (fri->getOrgModel() && fri->getOrgID()>0)
   116 		{
   117 			TreeItem *ti=fri->getOrgModel()->findID(fri->getOrgID() );
   118 			if (ti)
   119 				fri->getOrgModel()->select (ti);
   120 		}
   121 	}
   122 }
   123 
   124