refactoring of the TABS
[toast/confclerk.git] / src / gui / searchtabcontainer.cpp
1
2 #include <appsettings.h>
3
4 #include "searchtabcontainer.h"
5 #include "searchhead.h"
6
7
8 SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
9 {
10     header = new SearchHead(this);
11     header->setObjectName(QString::fromUtf8("header"));
12     QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
13     sizePolicy.setHorizontalStretch(0);
14     sizePolicy.setVerticalStretch(0);
15     //sizePolicy.setHeightForWidth(TabContainer::sizePolicy().hasHeightForWidth());
16     sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth());
17     header->setSizePolicy(sizePolicy);
18     header->setMinimumSize(QSize(10, 10));
19
20     verticalLayout->insertWidget(0,header);
21
22     header->show();
23
24     searchAgainButton = new QToolButton(this);
25     searchAgainButton->setObjectName(QString::fromUtf8("button"));
26     QIcon icon;
27     icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off);
28     searchAgainButton->setIcon(icon);
29     QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
30     sizePolicy1.setHorizontalStretch(0);
31     sizePolicy1.setVerticalStretch(0);
32     sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth());
33     searchAgainButton->setSizePolicy(sizePolicy1);
34
35     verticalLayout_2->insertWidget(0,searchAgainButton);
36
37     searchAgainButton->show();
38
39     connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
40     connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
41 }
42
43 SearchTabContainer::~SearchTabContainer()
44 {
45 }
46
47 void SearchTabContainer::searchButtonClicked()
48 {
49     qDebug() << "SearchTab::searchButtonClicked()";
50
51     QHash<QString,QString> columns;
52
53     SearchHead *searchHeader = static_cast<SearchHead*>(header);
54     if( searchHeader->searchTitle->isChecked() )
55         columns.insertMulti("EVENT", "title");
56     if( searchHeader->searchAbstract->isChecked() )
57         columns.insertMulti("EVENT", "abstract");
58     if( searchHeader->searchTag->isChecked() )
59         columns.insertMulti("EVENT", "tag");
60     if( searchHeader->searchSpeaker->isChecked() )
61         columns["PERSON"] = "name";
62     if( searchHeader->searchRoom->isChecked() )
63         columns["ROOM"] = "name";
64
65     QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
66     qDebug() << "\nKeyword to search: " << keyword;
67     SqlEngine::searchEvent( AppSettings::confId(), columns, keyword );
68
69     QDate startDate = Conference::getById(AppSettings::confId()).start();
70     QDate endDate = Conference::getById(AppSettings::confId()).end();
71     dayNavigator->setDates(startDate, endDate);
72     updateTreeView( Conference::getById(AppSettings::confId()).start() );
73 }
74
75 void SearchTabContainer::searchAgainClicked()
76 {
77     qDebug() << "SearchTab::searchAgainClicked()";
78     header->show();
79     searchAgainButton->hide();
80     dayNavigator->hide();
81     treeView->hide();
82 }
83
84 void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
85 {
86     int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
87     if( eventsCount ||
88             //TODO: this is not good test
89             dayNavigator->getCurrentDate() != Conference::getById( aConferenceId ).start()
90             ){
91         searchAgainButton->show();
92         dayNavigator->show();
93         treeView->show();
94         header->hide();
95     }
96     else{
97         treeView->hide();
98         searchAgainButton->hide();
99         dayNavigator->hide();
100         header->show();
101     }
102 }