Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "queryentry.hxx"
21 :
22 : #include <unotools/textsearch.hxx>
23 :
24 : /*
25 : * dialog returns the special field values "empty"/"not empty"
26 : * as constants SC_EMPTYFIELDS and SC_NONEMPTYFIELDS respectively in nVal in
27 : * conjuctions with the flag bQueryByString = FALSE.
28 : */
29 :
30 : #define SC_EMPTYFIELDS ((double)0x0042)
31 : #define SC_NONEMPTYFIELDS ((double)0x0043)
32 :
33 0 : bool ScQueryEntry::Item::operator== (const Item& r) const
34 : {
35 0 : return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty;
36 : }
37 :
38 5453 : ScQueryEntry::ScQueryEntry() :
39 : bDoQuery(false),
40 : nField(0),
41 : eOp(SC_EQUAL),
42 : eConnect(SC_AND),
43 : pSearchParam(NULL),
44 : pSearchText(NULL),
45 5453 : maQueryItems(1)
46 : {
47 5453 : }
48 :
49 13575 : ScQueryEntry::ScQueryEntry(const ScQueryEntry& r) :
50 : bDoQuery(r.bDoQuery),
51 : nField(r.nField),
52 : eOp(r.eOp),
53 : eConnect(r.eConnect),
54 : pSearchParam(NULL),
55 : pSearchText(NULL),
56 13575 : maQueryItems(r.maQueryItems)
57 : {
58 13575 : }
59 :
60 37336 : ScQueryEntry::~ScQueryEntry()
61 : {
62 18668 : delete pSearchParam;
63 18668 : delete pSearchText;
64 18668 : }
65 :
66 6 : ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
67 : {
68 6 : bDoQuery = r.bDoQuery;
69 6 : eOp = r.eOp;
70 6 : eConnect = r.eConnect;
71 6 : nField = r.nField;
72 6 : maQueryItems = r.maQueryItems;
73 :
74 6 : delete pSearchParam;
75 6 : delete pSearchText;
76 6 : pSearchParam = NULL;
77 6 : pSearchText = NULL;
78 :
79 6 : return *this;
80 : }
81 :
82 3 : void ScQueryEntry::SetQueryByEmpty()
83 : {
84 3 : eOp = SC_EQUAL;
85 3 : maQueryItems.resize(1);
86 3 : Item& rItem = maQueryItems[0];
87 3 : rItem.meType = ByEmpty;
88 3 : rItem.maString = svl::SharedString();
89 3 : rItem.mfVal = SC_EMPTYFIELDS;
90 3 : }
91 :
92 24 : bool ScQueryEntry::IsQueryByEmpty() const
93 : {
94 24 : if (maQueryItems.size() != 1)
95 0 : return false;
96 :
97 24 : const Item& rItem = maQueryItems[0];
98 48 : return eOp == SC_EQUAL &&
99 47 : rItem.meType == ByEmpty &&
100 70 : rItem.maString.isEmpty() &&
101 47 : rItem.mfVal == SC_EMPTYFIELDS;
102 : }
103 :
104 2 : void ScQueryEntry::SetQueryByNonEmpty()
105 : {
106 2 : eOp = SC_EQUAL;
107 2 : maQueryItems.resize(1);
108 2 : Item& rItem = maQueryItems[0];
109 2 : rItem.meType = ByEmpty;
110 2 : rItem.maString = svl::SharedString();
111 2 : rItem.mfVal = SC_NONEMPTYFIELDS;
112 2 : }
113 :
114 1 : bool ScQueryEntry::IsQueryByNonEmpty() const
115 : {
116 1 : if (maQueryItems.size() != 1)
117 0 : return false;
118 :
119 1 : const Item& rItem = maQueryItems[0];
120 2 : return eOp == SC_EQUAL &&
121 1 : rItem.meType == ByEmpty &&
122 1 : rItem.maString.isEmpty() &&
123 1 : rItem.mfVal == SC_NONEMPTYFIELDS;
124 : }
125 :
126 1507 : const ScQueryEntry::Item& ScQueryEntry::GetQueryItem() const
127 : {
128 1507 : if (maQueryItems.size() > 1)
129 : // Reset to a single query mode.
130 0 : maQueryItems.resize(1);
131 1507 : return maQueryItems[0];
132 : }
133 :
134 523 : ScQueryEntry::Item& ScQueryEntry::GetQueryItem()
135 : {
136 523 : if (maQueryItems.size() > 1)
137 : // Reset to a single query mode.
138 0 : maQueryItems.resize(1);
139 523 : return maQueryItems[0];
140 : }
141 :
142 5449 : void ScQueryEntry::Clear()
143 : {
144 5449 : bDoQuery = false;
145 5449 : eOp = SC_EQUAL;
146 5449 : eConnect = SC_AND;
147 5449 : nField = 0;
148 5449 : maQueryItems.clear();
149 5449 : maQueryItems.push_back(Item());
150 :
151 5449 : delete pSearchParam;
152 5449 : delete pSearchText;
153 5449 : pSearchParam = NULL;
154 5449 : pSearchText = NULL;
155 5449 : }
156 :
157 0 : bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
158 : {
159 0 : return bDoQuery == r.bDoQuery
160 0 : && eOp == r.eOp
161 0 : && eConnect == r.eConnect
162 0 : && nField == r.nField
163 0 : && maQueryItems == r.maQueryItems;
164 : // do not compare pSearchParam and pSearchText!
165 : }
166 :
167 24 : utl::TextSearch* ScQueryEntry::GetSearchTextPtr( bool bCaseSens ) const
168 : {
169 24 : if ( !pSearchParam )
170 : {
171 5 : OUString aStr = maQueryItems[0].maString.getString();
172 : pSearchParam = new utl::SearchParam(
173 5 : aStr, utl::SearchParam::SRCH_REGEXP, bCaseSens, false, false);
174 5 : pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
175 : }
176 24 : return pSearchText;
177 156 : }
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|