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