-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsearchform.h
90 lines (65 loc) · 1.97 KB
/
searchform.h
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
#ifndef SEARCHFORM_H
#define SEARCHFORM_H
#include <QWidget>
#include <nix.hpp>
#include "utils/utils.hpp"
template<typename T>
struct NameSearch : nix::util::Filter<T> {
const std::string name;
bool case_sensitive, exact;
NameSearch(const std::string &str, bool case_sensitive=false, bool exact=false)
: name(str), case_sensitive(case_sensitive), exact(exact)
{}
virtual bool operator()(const T &e) {
return nixview::util::stringCompare(e.name(), name, case_sensitive, exact);
}
};
template<typename T>
struct TypeSearch : nix::util::Filter<T> {
const std::string name;
bool case_sensitive, exact;
TypeSearch(const std::string &str, bool case_sensitive=false, bool exact=false)
: name(str), case_sensitive(case_sensitive), exact(exact)
{}
virtual bool operator()(const T &e) {
return nixview::util::stringCompare(e.type(), name, case_sensitive, exact);
}
};
template<typename T>
struct DefinitionSearch : nix::util::Filter<T> {
const std::string name;
bool case_sensitive, exact;
DefinitionSearch(const std::string &str, bool case_sensitive=false, bool exact=false)
: name(str), case_sensitive(case_sensitive), exact(exact)
{}
virtual bool operator()(const T &e) {
if (!e.definition()) {
return false;
}
return nixview::util::stringCompare(*e.definition(), name, case_sensitive, exact);
}
};
namespace Ui {
class SearchForm;
}
class SearchForm : public QWidget
{
Q_OBJECT
public:
explicit SearchForm(QWidget *parent = 0);
~SearchForm();
void clear();
void setNixFile(const nix::File &f);
void receiveFocus();
signals:
void newResults(std::vector<QVariant>);
public slots:
void go();
void fieldSelected(int index);
private:
Ui::SearchForm *ui;
std::vector<QVariant> results;
nix::File nix_file;
};
#endif // SEARCHFORM_H
// TODO invalidate nix file, if file was closed