1 #include "findresultwidget.h"
6 #include "findresultitem.h"
7 #include "findresultmodel.h"
10 extern QString iconPath;
12 FindResultWidget::FindResultWidget(VymModel *m, QWidget *)
16 // Create results model
17 resultsModel=new FindResultModel;
20 view = new QTreeView (this);
21 view->setModel (resultsModel);
23 QVBoxLayout* mainLayout = new QVBoxLayout;
25 // FIXME-4 feature: show number of hits at bottom of FindResultWidget
27 /* FIXME-3 testing QMenuBar *mb=new QMenuBar;
28 QAction *a=new QAction ("Foo action",NULL);
30 mb->insertSeparator();
31 mainLayout->addWidget(mb);
33 mainLayout->addWidget(view);
35 setLayout (mainLayout);
40 connect (view->selectionModel(),SIGNAL (selectionChanged (QItemSelection,QItemSelection)),
41 this, SLOT (updateSelection (QItemSelection,QItemSelection)));
43 connect (resultsModel, SIGNAL(layoutChanged() ), view, SLOT (expandAll() ));
46 void FindResultWidget::addItem (TreeItem *ti)
50 QModelIndex index = view->selectionModel()->currentIndex();
51 //QAbstractItemModel *resultsModel = view->model();
53 if (!resultsModel->insertRow(index.row()+1, index.parent()))
56 for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
57 QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
58 resultsModel->setData(child, QVariant(ti->getHeading()), Qt::EditRole);
59 resultsModel->getItem(child)->setOriginal (ti);
64 void FindResultWidget::addItem (const QString &s)
68 QModelIndex index = view->selectionModel()->currentIndex();
70 if (!resultsModel->insertRow(index.row()+1, index.parent()))
73 for (int column = 0; column < resultsModel->columnCount(index.parent()); ++column) {
74 QModelIndex child = resultsModel->index(index.row()+1, column, index.parent());
75 resultsModel->setData(child, QVariant(s), Qt::EditRole);
80 void FindResultWidget::setModel (VymModel *m)
82 if (model !=NULL && m!=model)
83 qWarning ("FindResultWidget::setModel m!=model");
87 FindResultModel* FindResultWidget::getResultModel()
92 void FindResultWidget::popup()
95 parentWidget()->show();
98 void FindResultWidget::cancelPressed()
100 emit (hideFindResultWidget() );
103 void FindResultWidget::updateSelection(QItemSelection newsel,QItemSelection)
106 foreach (ix,newsel.indexes() )
108 FindResultItem *fri= static_cast<FindResultItem*>(ix.internalPointer());
109 if (fri->getOrgModel() && fri->getOriginalID()>0)
111 TreeItem *ti=fri->getOrgModel()->findID(fri->getOriginalID() );
114 fri->getOrgModel()->select (ti);
115 int i=fri->getOriginalIndex();
116 if (i>=0) emit (noteSelected (resultsModel->getSearchString(),i));