LCOV - code coverage report
Current view: top level - sc/source/core/tool - queryentry.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 79 91 86.8 %
Date: 2014-04-11 Functions: 14 16 87.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10