-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.cpp
220 lines (195 loc) · 6.07 KB
/
search.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "search.h"
#include "qmessagebox.h"
#include "ui_search.h"
#include "homepage.h"
#include "news.h"
#include "newsbasedon.h"
Search::Search(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Search)
{
ui->setupUi(this);
_searchBasedOn = SearchBasedOn::notAdded;
// Load the icon from your resources
QIcon searchIcon("Resourses/search.png");
// Set the icon to the button
ui->searchButton->setIcon(searchIcon);
// hide Search(title, keywords) items
ui->lineEdit_Search->hide();
ui->comboBox->hide();
ui->label_2->hide();
ui->searchButton->hide();
// hide Search(date) items
ui->comboBox_dates->hide();
ui->comboBox_news->hide();
ui->searchButton_2->hide();
// hide show news button
ui->pushButton_4->hide();
}
Search::~Search()
{
delete ui;
}
void Search::on_pushButton_clicked()
{
ui->comboBox_dates->clear();
ui->comboBox_news->clear();
ui->comboBox->clear();
ui->lineEdit_Search->clear();
ui->label_2->show();
ui->pushButton->setStyleSheet(_clickedStyleSheet);
ui->pushButton_2->setStyleSheet(_defaultStyleSheet);
ui->pushButton_3->setStyleSheet(_defaultStyleSheet);
_searchBasedOn = SearchBasedOn::date;
// hide Search(title, keywords) items
ui->lineEdit_Search->hide();
ui->comboBox->hide();
ui->searchButton->hide();
// show search by date items
ui->comboBox_dates->show();
ui->comboBox_news->show();
ui->searchButton_2->show();
// show Show News Button;
ui->pushButton_4->show();
// Logic of Search By Date
ui->comboBox_dates->clear();
if(_newsByDate.empty()){
for(auto newsModel : Adminx::news)
{
_newsByDate[newsModel.getDate()].push_back(newsModel);
}
}
for(auto &[key, list] : _newsByDate)
{
ui->comboBox_dates->addItem(key.c_str());
}
if(ui->comboBox_dates->itemText(ui->comboBox_dates->currentIndex()).isEmpty()){
ui->comboBox_dates->removeItem(ui->comboBox_dates->currentIndex());
}
}
void Search::on_pushButton_2_clicked()
{
ui->label_2->show();
ui->comboBox_dates->clear();
ui->comboBox_news->clear();
ui->comboBox->clear();
ui->lineEdit_Search->clear();
ui->searchButton->show();
ui->pushButton->setStyleSheet(_defaultStyleSheet);
ui->pushButton_2->setStyleSheet(_clickedStyleSheet);
ui->pushButton_3->setStyleSheet(_defaultStyleSheet);
_searchBasedOn = SearchBasedOn::Keyword;
// hide Search(date) items
ui->comboBox_dates->hide();
ui->comboBox_news->hide();
ui->searchButton_2->hide();
// show search by keywords items
ui->lineEdit_Search->show();
ui->comboBox->show();
ui->label->show();
ui->searchButton->show();
// show Show News Button
ui->pushButton_4->show();
}
void Search::on_pushButton_3_clicked()
{
// clear comboBoxes
ui->comboBox_dates->clear();
ui->comboBox_news->clear();
ui->comboBox->clear();
ui->lineEdit_Search->clear();
ui->label_2->show();
ui->searchButton->show();
ui->pushButton->setStyleSheet(_defaultStyleSheet);
ui->pushButton_2->setStyleSheet(_defaultStyleSheet);
ui->pushButton_3->setStyleSheet(_clickedStyleSheet);
_searchBasedOn = SearchBasedOn::titles;
// hide Search(date) items
ui->comboBox_dates->hide();
ui->comboBox_news->hide();
ui->searchButton_2->hide();
// show search by title items
ui->lineEdit_Search->show();
ui->comboBox->show();
ui->label->show();
ui->searchButton->show();
// show Show News Button
ui->pushButton_4->show();
}
void Search::on_searchButton_clicked()
{
ui->comboBox->clear();
int id = Login::UserID;
if(_searchBasedOn == SearchBasedOn::notAdded)
{
QMessageBox::warning(this, "error", "No Selected Type of Search!");
return;
}
String searchInput = ui->lineEdit_Search->text().toStdString();
if(_searchBasedOn == SearchBasedOn::Keyword)
{
for(int it = 0; it < searchInput.size(); it++)
{
searchInput[it] = tolower(searchInput[it]);
}
}
_searchAns = Adminx::users[id].Search(_searchBasedOn, searchInput);
for (auto news : _searchAns) {
ui->comboBox->addItem(QString(news.getTitle().c_str()));
}
}
void Search::on_pushButton_back_clicked()
{
hide();
HomePage *homePage = new HomePage(this);
homePage->show();
}
void Search::on_searchButton_2_clicked()
{
ui->comboBox_news->clear();
_searchAns = _newsByDate[ui->comboBox_dates->currentText().toStdString()];
for (auto news : _searchAns) {
ui->comboBox_news->addItem(QString(news.getTitle().c_str()));
}
}
void Search::on_pushButton_4_clicked()
{
if(_searchBasedOn == SearchBasedOn::notAdded)
{
QMessageBox::warning(this, "error", "No Search Type Selected!");
return;
}
if((ui->comboBox->count() == 0 && (_searchBasedOn == SearchBasedOn::Keyword || _searchBasedOn == SearchBasedOn::titles)) || (ui->comboBox_news->count() == 0 && _searchBasedOn == SearchBasedOn::date))
{
QMessageBox::warning(this, "error", "No Found Data!");
return;
}
Adminx::backbuttons[3] = true;
Adminx::backbuttons[2] = false;
Adminx::backbuttons[1] = false;
Adminx::backbuttons[0] = false;
hide();
if(_searchBasedOn == SearchBasedOn::date)
{
for(int i = 0; i < Adminx::news.size(); i++)
{
if(ui->comboBox_news->currentText().toStdString() == Adminx::news[i].getTitle())
{
Newsbasedon::currentNew = i;
}
}
}
else
{
for(int i = 0; i < Adminx::news.size(); i++)
{
if(ui->comboBox->currentText().toStdString() == Adminx::news[i].getTitle())
{
Newsbasedon::currentNew = i;
}
}
}
News *news = new News(this);
news->show();
news->displayNew();
}