-
Notifications
You must be signed in to change notification settings - Fork 0
/
Query.cpp
51 lines (45 loc) · 1.48 KB
/
Query.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
#include "Query.h"
static void AppendQueryResult(QStringList& queryResult, Station* station);
Query::Query()
{
model_QueryResult = new QStringListModel();
}
QStringListModel* Query_ID::StartQuery(void)
{
// 对于 Query_Id,一个 ID 最多只可能搜索到一个结果
queryResult.clear();
model_QueryResult->setStringList(queryResult); // 清空结果
Station* station = FindStationById(query_id);
if (station == nullptr) {
qDebug() << "No station found.";
} else
AppendQueryResult(queryResult, station);
model_QueryResult->setStringList(queryResult);
return model_QueryResult;
}
QStringListModel* Query_Name::StartQuery(void)
{
// 对于 Query_Name,一个 Name 可能搜索到多个结果
queryResult.clear();
QList<Station*> stations = FindStationsByName(query_name);
if (stations.size() == 0) {
qDebug() << "No station found.";
}
else {
for (Station* station : stations) {
AppendQueryResult(queryResult, station);
}
}
model_QueryResult->setStringList(queryResult);
return model_QueryResult;
}
static void AppendQueryResult(QStringList& queryResult, Station* station)
{
QString lineNo = QString::number(station->lineNo);
if (lineNo != "61") { // 61 号线其实是 6 号线支线,需要特殊处理
queryResult << station->name + " - " + QString::number(station->lineNo) + " 号线";
}
else {
queryResult << station->name + " - 6 号线支线";
}
}