Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / queryentry.cxx
bloba282f4dce50078aed51809148731e9c4539c93ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "queryentry.hxx"
22 #include <unotools/textsearch.hxx>
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.
30 #define SC_EMPTYFIELDS ((double)0x0042)
31 #define SC_NONEMPTYFIELDS ((double)0x0043)
33 bool ScQueryEntry::Item::operator== (const Item& r) const
35 return meType == r.meType && mfVal == r.mfVal && maString == r.maString;
38 ScQueryEntry::ScQueryEntry() :
39 bDoQuery(false),
40 nField(0),
41 eOp(SC_EQUAL),
42 eConnect(SC_AND),
43 pSearchParam(NULL),
44 pSearchText(NULL),
45 maQueryItems(1)
49 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 maQueryItems(r.maQueryItems)
60 ScQueryEntry::~ScQueryEntry()
62 delete pSearchParam;
63 delete pSearchText;
66 ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
68 bDoQuery = r.bDoQuery;
69 eOp = r.eOp;
70 eConnect = r.eConnect;
71 nField = r.nField;
72 maQueryItems = r.maQueryItems;
74 delete pSearchParam;
75 delete pSearchText;
76 pSearchParam = NULL;
77 pSearchText = NULL;
79 return *this;
82 ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems()
84 return maQueryItems;
87 const ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems() const
89 return maQueryItems;
92 void ScQueryEntry::SetQueryByEmpty()
94 eOp = SC_EQUAL;
95 maQueryItems.resize(1);
96 Item& rItem = maQueryItems[0];
97 rItem.meType = ByEmpty;
98 rItem.maString = svl::SharedString();
99 rItem.mfVal = SC_EMPTYFIELDS;
102 bool ScQueryEntry::IsQueryByEmpty() const
104 if (maQueryItems.size() != 1)
105 return false;
107 const Item& rItem = maQueryItems[0];
108 return eOp == SC_EQUAL &&
109 rItem.meType == ByEmpty &&
110 rItem.maString.isEmpty() &&
111 rItem.mfVal == SC_EMPTYFIELDS;
114 void ScQueryEntry::SetQueryByNonEmpty()
116 eOp = SC_EQUAL;
117 maQueryItems.resize(1);
118 Item& rItem = maQueryItems[0];
119 rItem.meType = ByEmpty;
120 rItem.maString = svl::SharedString();
121 rItem.mfVal = SC_NONEMPTYFIELDS;
124 bool ScQueryEntry::IsQueryByNonEmpty() const
126 if (maQueryItems.size() != 1)
127 return false;
129 const Item& rItem = maQueryItems[0];
130 return eOp == SC_EQUAL &&
131 rItem.meType == ByEmpty &&
132 rItem.maString.isEmpty() &&
133 rItem.mfVal == SC_NONEMPTYFIELDS;
136 const ScQueryEntry::Item& ScQueryEntry::GetQueryItem() const
138 if (maQueryItems.size() > 1)
139 // Reset to a single query mode.
140 maQueryItems.resize(1);
141 return maQueryItems[0];
144 ScQueryEntry::Item& ScQueryEntry::GetQueryItem()
146 if (maQueryItems.size() > 1)
147 // Reset to a single query mode.
148 maQueryItems.resize(1);
149 return maQueryItems[0];
152 void ScQueryEntry::Clear()
154 bDoQuery = false;
155 eOp = SC_EQUAL;
156 eConnect = SC_AND;
157 nField = 0;
158 maQueryItems.clear();
159 maQueryItems.push_back(Item());
161 delete pSearchParam;
162 delete pSearchText;
163 pSearchParam = NULL;
164 pSearchText = NULL;
167 bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
169 return bDoQuery == r.bDoQuery
170 && eOp == r.eOp
171 && eConnect == r.eConnect
172 && nField == r.nField
173 && maQueryItems == r.maQueryItems;
174 //! pSearchParam und pSearchText nicht vergleichen
177 utl::TextSearch* ScQueryEntry::GetSearchTextPtr( bool bCaseSens ) const
179 if ( !pSearchParam )
181 OUString aStr = maQueryItems[0].maString.getString();
182 pSearchParam = new utl::SearchParam(
183 aStr, utl::SearchParam::SRCH_REGEXP, bCaseSens, false, false);
184 pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
186 return pSearchText;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */