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 
34 {
35  return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty;
36 }
37 
39  bDoQuery(false),
40  nField(0),
41  eOp(SC_EQUAL),
43  maQueryItems(1)
44 {
45 }
46 
48  bDoQuery(r.bDoQuery),
49  nField(r.nField),
50  eOp(r.eOp),
51  eConnect(r.eConnect),
52  maQueryItems(r.maQueryItems)
53 {
54 }
55 
57 {
58 }
59 
61 {
62  bDoQuery = r.bDoQuery;
63  eOp = r.eOp;
64  eConnect = r.eConnect;
65  nField = r.nField;
67 
68  pSearchParam.reset();
69  pSearchText.reset();
70 
71  return *this;
72 }
73 
75 {
76  eOp = SC_EQUAL;
77  maQueryItems.resize(1);
78  Item& rItem = maQueryItems[0];
79  rItem.meType = ByEmpty;
80  rItem.maString = svl::SharedString();
81  rItem.mfVal = SC_EMPTYFIELDS;
82 }
83 
85 {
86  if (maQueryItems.size() != 1)
87  return false;
88 
89  const Item& rItem = maQueryItems[0];
90  return eOp == SC_EQUAL &&
91  rItem.meType == ByEmpty &&
92  rItem.maString.isEmpty() &&
93  rItem.mfVal == SC_EMPTYFIELDS;
94 }
95 
97 {
98  eOp = SC_EQUAL;
99  maQueryItems.resize(1);
100  Item& rItem = maQueryItems[0];
101  rItem.meType = ByEmpty;
102  rItem.maString = svl::SharedString();
103  rItem.mfVal = SC_NONEMPTYFIELDS;
104 }
105 
107 {
108  if (maQueryItems.size() != 1)
109  return false;
110 
111  const Item& rItem = maQueryItems[0];
112  return eOp == SC_EQUAL &&
113  rItem.meType == ByEmpty &&
114  rItem.maString.isEmpty() &&
115  rItem.mfVal == SC_NONEMPTYFIELDS;
116 }
117 
119 {
120  if (maQueryItems.size() > 1)
121  // Reset to a single query mode.
122  maQueryItems.resize(1);
123  return maQueryItems[0];
124 }
125 
127 {
128  if (maQueryItems.size() > 1)
129  // Reset to a single query mode.
130  maQueryItems.resize(1);
131  return maQueryItems[0];
132 }
133 
135 {
136  bDoQuery = false;
137  eOp = SC_EQUAL;
138  eConnect = SC_AND;
139  nField = 0;
140  maQueryItems.clear();
141  maQueryItems.emplace_back();
142 
143  pSearchParam.reset();
144  pSearchText.reset();
145 }
146 
148 {
149  return bDoQuery == r.bDoQuery
150  && eOp == r.eOp
151  && eConnect == r.eConnect
152  && nField == r.nField
153  && maQueryItems == r.maQueryItems;
154  // do not compare pSearchParam and pSearchText!
155 }
156 
158  bool bWildMatchSel ) const
159 {
160  if ( !pSearchParam )
161  {
162  OUString aStr = maQueryItems[0].maString.getString();
163  pSearchParam.reset(new utl::SearchParam(
164  aStr, eSearchType, bCaseSens, '~', bWildMatchSel));
166  }
167  return pSearchText.get();
168 }
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const ScQueryEntry &r) const
Definition: queryentry.cxx:147
void SetQueryByEmpty()
Definition: queryentry.cxx:74
SCCOLROW nField
Definition: queryentry.hxx:51
bool IsQueryByEmpty() const
Definition: queryentry.cxx:84
const Item & GetQueryItem() const
Definition: queryentry.cxx:118
std::unique_ptr< utl::SearchParam > pSearchParam
if Wildcard or RegExp, not saved
Definition: queryentry.hxx:54
utl::TextSearch * GetSearchTextPtr(utl::SearchParam::SearchType eSearchType, bool bCaseSens, bool bWildMatchSel) const
creates pSearchParam and pSearchText if necessary
Definition: queryentry.cxx:157
bool isEmpty() const
bool IsQueryByNonEmpty() const
Definition: queryentry.cxx:106
svl::SharedString maString
Definition: queryentry.hxx:41
#define SC_NONEMPTYFIELDS
Definition: queryentry.cxx:31
ScQueryEntry & operator=(const ScQueryEntry &r)
Definition: queryentry.cxx:60
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1018
ScQueryConnect eConnect
Definition: queryentry.hxx:53
QueryItemsType maQueryItems
Stores all query items.
Definition: queryentry.hxx:83
bool operator==(const Item &r) const
Definition: queryentry.cxx:33
#define SC_EMPTYFIELDS
Definition: queryentry.cxx:30
ScQueryOp eOp
Definition: queryentry.hxx:52
aStr
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:33
void SetQueryByNonEmpty()
Definition: queryentry.cxx:96
std::unique_ptr< utl::TextSearch > pSearchText
if Wildcard or RegExp, not saved
Definition: queryentry.hxx:55