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)));
44 void FindResultWidget::addItem (TreeItem *ti)
48 QModelIndex index = view->selectionModel()->currentIndex();
49 //QAbstractItemModel *resultsModel = view->model();
51 if (!resultsModel->insertRow(index.row()+1, index.parent()))
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);
62 void FindResultWidget::addItem (const QString &s)
66 QModelIndex index = view->selectionModel()->currentIndex();
68 if (!resultsModel->insertRow(index.row()+1, index.parent()))
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);
78 void FindResultWidget::setModel (VymModel *m)
80 if (model !=NULL && m!=model)
81 qWarning ("FindResultWidget::setModel m!=model");
85 FindResultModel* FindResultWidget::getResultModel()
90 void FindResultWidget::addResult (const QString &category, TreeItem *ti)
92 if (!category.isEmpty())
95 addItem (model->getSelectedItem());
98 void FindResultWidget::popup()
101 parentWidget()->show();
104 void FindResultWidget::cancelPressed()
106 emit (hideFindResultWidget() );
109 void FindResultWidget::updateSelection(QItemSelection newsel,QItemSelection)
112 foreach (ix,newsel.indexes() )
114 FindResultItem *fri= static_cast<FindResultItem*>(ix.internalPointer());
115 if (fri->getOrgModel() && fri->getOrgID()>0)
117 TreeItem *ti=fri->getOrgModel()->findID(fri->getOrgID() );
119 fri->getOrgModel()->select (ti);