LibreOffice Module sc (master)  1
queryentry.cxx
Go to the documentation of this file.
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  * conjunctions with the flag bQueryByString = FALSE.
28  */
29 
30 #define SC_EMPTYFIELDS (double(0x0042))
31 #define SC_NONEMPTYFIELDS (double(0x0043))
32 #define SC_TEXTCOLOR (double(0x0044))
33 #define SC_BACKGROUNDCOLOR (double(0x0045))
34 
36 {
37  return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty;
38 }
39 
41  bDoQuery(false),
42  nField(0),
43  eOp(SC_EQUAL),
45  maQueryItems(1)
46 {
47 }
48 
50  bDoQuery(r.bDoQuery),
51  nField(r.nField),
52  eOp(r.eOp),
53  eConnect(r.eConnect),
54  maQueryItems(r.maQueryItems)
55 {
56 }
57 
59 {
60 }
61 
63 {
64  bDoQuery = r.bDoQuery;
65  eOp = r.eOp;
66  eConnect = r.eConnect;
67  nField = r.nField;
69 
70  pSearchParam.reset();
71  pSearchText.reset();
72 
73  return *this;
74 }
75 
77 {
78  eOp = SC_EQUAL;
79  maQueryItems.resize(1);
80  Item& rItem = maQueryItems[0];
81  rItem.meType = ByEmpty;
82  rItem.maString = svl::SharedString();
83  rItem.mfVal = SC_EMPTYFIELDS;
84 }
85 
87 {
88  if (maQueryItems.size() != 1)
89  return false;
90 
91  const Item& rItem = maQueryItems[0];
92  return eOp == SC_EQUAL &&
93  rItem.meType == ByEmpty &&
94  rItem.maString.isEmpty() &&
95  rItem.mfVal == SC_EMPTYFIELDS;
96 }
97 
99 {
100  eOp = SC_EQUAL;
101  maQueryItems.resize(1);
102  Item& rItem = maQueryItems[0];
103  rItem.meType = ByEmpty;
104  rItem.maString = svl::SharedString();
105  rItem.mfVal = SC_NONEMPTYFIELDS;
106 }
107 
109 {
110  if (maQueryItems.size() != 1)
111  return false;
112 
113  const Item& rItem = maQueryItems[0];
114  return eOp == SC_EQUAL &&
115  rItem.meType == ByEmpty &&
116  rItem.maString.isEmpty() &&
117  rItem.mfVal == SC_NONEMPTYFIELDS;
118 }
119 
121 {
122  eOp = SC_EQUAL;
123  maQueryItems.resize(1);
124  Item& rItem = maQueryItems[0];
125  rItem.meType = ByTextColor;
126  rItem.maString = svl::SharedString();
127  rItem.mfVal = SC_TEXTCOLOR;
128  rItem.maColor = color;
129 }
130 
132 {
133  if (maQueryItems.size() != 1)
134  return false;
135 
136  const Item& rItem = maQueryItems[0];
137  return eOp == SC_EQUAL &&
138  rItem.meType == ByTextColor;
139 }
140 
142 {
143  eOp = SC_EQUAL;
144  maQueryItems.resize(1);
145  Item& rItem = maQueryItems[0];
146  rItem.meType = ByBackgroundColor;
147  rItem.maString = svl::SharedString();
148  rItem.mfVal = SC_BACKGROUNDCOLOR;
149  rItem.maColor = color;
150 }
151 
153 {
154  if (maQueryItems.size() != 1)
155  return false;
156 
157  const Item& rItem = maQueryItems[0];
158  return eOp == SC_EQUAL &&
159  rItem.meType == ByBackgroundColor;
160 }
161 
163 {
164  if (maQueryItems.size() != 1)
165  // Reset to a single query mode.
166  maQueryItems.resize(1);
167  return maQueryItems[0];
168 }
169 
171 {
172  bDoQuery = false;
173  eOp = SC_EQUAL;
174  eConnect = SC_AND;
175  nField = 0;
176  maQueryItems.clear();
177  maQueryItems.emplace_back();
178 
179  pSearchParam.reset();
180  pSearchText.reset();
181 }
182 
184 {
185  return bDoQuery == r.bDoQuery
186  && eOp == r.eOp
187  && eConnect == r.eConnect
188  && nField == r.nField
189  && maQueryItems == r.maQueryItems;
190  // do not compare pSearchParam and pSearchText!
191 }
192 
194  bool bWildMatchSel ) const
195 {
196  if ( !pSearchParam )
197  {
198  OUString aStr = maQueryItems[0].maString.getString();
199  pSearchParam.reset(new utl::SearchParam(
200  aStr, eSearchType, bCaseSens, '~', bWildMatchSel));
202  }
203  return pSearchText.get();
204 }
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const ScQueryEntry &r) const
Definition: queryentry.cxx:183
bool IsQueryByBackgroundColor() const
Definition: queryentry.cxx:152
void SetQueryByEmpty()
Definition: queryentry.cxx:76
SCCOLROW nField
Definition: queryentry.hxx:60
bool IsQueryByEmpty() const
Definition: queryentry.cxx:86
std::unique_ptr< utl::SearchParam > pSearchParam
if Wildcard or RegExp, not saved
Definition: queryentry.hxx:63
void SetQueryByTextColor(Color color)
Definition: queryentry.cxx:120
void SetQueryByBackgroundColor(Color color)
Definition: queryentry.cxx:141
#define SC_BACKGROUNDCOLOR
Definition: queryentry.cxx:33
utl::TextSearch * GetSearchTextPtr(utl::SearchParam::SearchType eSearchType, bool bCaseSens, bool bWildMatchSel) const
creates pSearchParam and pSearchText if necessary
Definition: queryentry.cxx:193
bool isEmpty() const
bool IsQueryByNonEmpty() const
Definition: queryentry.cxx:108
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1016
svl::SharedString maString
Definition: queryentry.hxx:49
#define SC_NONEMPTYFIELDS
Definition: queryentry.cxx:31
Item & GetQueryItemImpl() const
Definition: queryentry.cxx:162
bool IsQueryByTextColor() const
Definition: queryentry.cxx:131
ScQueryEntry & operator=(const ScQueryEntry &r)
Definition: queryentry.cxx:62
#define SC_TEXTCOLOR
Definition: queryentry.cxx:32
ScQueryConnect eConnect
Definition: queryentry.hxx:62
QueryItemsType maQueryItems
Stores all query items.
Definition: queryentry.hxx:98
bool operator==(const Item &r) const
Definition: queryentry.cxx:35
#define SC_EMPTYFIELDS
Definition: queryentry.cxx:30
ScQueryOp eOp
Definition: queryentry.hxx:61
aStr
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:33
void SetQueryByNonEmpty()
Definition: queryentry.cxx:98
std::unique_ptr< utl::TextSearch > pSearchText
if Wildcard or RegExp, not saved
Definition: queryentry.hxx:64