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.equals(r.maString);
36 : }
37 :
38 1258 : ScQueryEntry::ScQueryEntry() :
39 : bDoQuery(false),
40 : nField(0),
41 : eOp(SC_EQUAL),
42 : eConnect(SC_AND),
43 : pSearchParam(NULL),
44 : pSearchText(NULL),
45 1258 : maQueryItems(1)
46 : {
47 1258 : }
48 :
49 1904 : 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 1904 : maQueryItems(r.maQueryItems)
57 : {
58 1904 : }
59 :
60 6228 : ScQueryEntry::~ScQueryEntry()
61 : {
62 3114 : delete pSearchParam;
63 3114 : delete pSearchText;
64 3114 : }
65 :
66 4 : ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
67 : {
68 4 : bDoQuery = r.bDoQuery;
69 4 : eOp = r.eOp;
70 4 : eConnect = r.eConnect;
71 4 : nField = r.nField;
72 4 : maQueryItems = r.maQueryItems;
73 :
74 4 : delete pSearchParam;
75 4 : delete pSearchText;
76 4 : pSearchParam = NULL;
77 4 : pSearchText = NULL;
78 :
79 4 : return *this;
80 : }
81 :
82 8 : ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems()
83 : {
84 8 : return maQueryItems;
85 : }
86 :
87 454 : const ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems() const
88 : {
89 454 : return maQueryItems;
90 : }
91 :
92 1 : void ScQueryEntry::SetQueryByEmpty()
93 : {
94 1 : eOp = SC_EQUAL;
95 1 : maQueryItems.resize(1);
96 1 : Item& rItem = maQueryItems[0];
97 1 : rItem.meType = ByEmpty;
98 1 : rItem.maString = rtl::OUString();
99 1 : rItem.mfVal = SC_EMPTYFIELDS;
100 1 : }
101 :
102 8 : bool ScQueryEntry::IsQueryByEmpty() const
103 : {
104 8 : if (maQueryItems.size() != 1)
105 0 : return false;
106 :
107 8 : const Item& rItem = maQueryItems[0];
108 : return eOp == SC_EQUAL &&
109 : rItem.meType == ByEmpty &&
110 8 : rItem.maString.isEmpty() &&
111 16 : rItem.mfVal == SC_EMPTYFIELDS;
112 : }
113 :
114 1 : void ScQueryEntry::SetQueryByNonEmpty()
115 : {
116 1 : eOp = SC_EQUAL;
117 1 : maQueryItems.resize(1);
118 1 : Item& rItem = maQueryItems[0];
119 1 : rItem.meType = ByEmpty;
120 1 : rItem.maString = rtl::OUString();
121 1 : rItem.mfVal = SC_NONEMPTYFIELDS;
122 1 : }
123 :
124 0 : bool ScQueryEntry::IsQueryByNonEmpty() const
125 : {
126 0 : if (maQueryItems.size() != 1)
127 0 : return false;
128 :
129 0 : const Item& rItem = maQueryItems[0];
130 : return eOp == SC_EQUAL &&
131 : rItem.meType == ByEmpty &&
132 0 : rItem.maString.isEmpty() &&
133 0 : rItem.mfVal == SC_NONEMPTYFIELDS;
134 : }
135 :
136 417 : const ScQueryEntry::Item& ScQueryEntry::GetQueryItem() const
137 : {
138 417 : if (maQueryItems.size() > 1)
139 : // Reset to a single query mode.
140 0 : maQueryItems.resize(1);
141 417 : return maQueryItems[0];
142 : }
143 :
144 243 : ScQueryEntry::Item& ScQueryEntry::GetQueryItem()
145 : {
146 243 : if (maQueryItems.size() > 1)
147 : // Reset to a single query mode.
148 0 : maQueryItems.resize(1);
149 243 : return maQueryItems[0];
150 : }
151 :
152 1249 : void ScQueryEntry::Clear()
153 : {
154 1249 : bDoQuery = false;
155 1249 : eOp = SC_EQUAL;
156 1249 : eConnect = SC_AND;
157 1249 : nField = 0;
158 1249 : maQueryItems.clear();
159 1249 : maQueryItems.push_back(Item());
160 :
161 1249 : delete pSearchParam;
162 1249 : delete pSearchText;
163 1249 : pSearchParam = NULL;
164 1249 : pSearchText = NULL;
165 1249 : }
166 :
167 0 : bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
168 : {
169 : return bDoQuery == r.bDoQuery
170 : && eOp == r.eOp
171 : && eConnect == r.eConnect
172 : && nField == r.nField
173 0 : && maQueryItems == r.maQueryItems;
174 : //! pSearchParam und pSearchText nicht vergleichen
175 : }
176 :
177 8 : utl::TextSearch* ScQueryEntry::GetSearchTextPtr( bool bCaseSens ) const
178 : {
179 8 : if ( !pSearchParam )
180 : {
181 1 : const rtl::OUString& rStr = maQueryItems[0].maString;
182 : pSearchParam = new utl::SearchParam(
183 1 : rStr, utl::SearchParam::SRCH_REGEXP, bCaseSens, false, false);
184 1 : pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
185 : }
186 8 : return pSearchText;
187 : }
188 :
189 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|