LCOV - code coverage report
Current view: top level - sc/source/core/tool - queryentry.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 68 83 81.9 %
Date: 2012-08-25 Functions: 13 16 81.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 64 29.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "queryentry.hxx"
      30                 :            : 
      31                 :            : #include <unotools/textsearch.hxx>
      32                 :            : 
      33                 :            : /*
      34                 :            :  * dialog returns the special field values "empty"/"not empty"
      35                 :            :  * as constants SC_EMPTYFIELDS and SC_NONEMPTYFIELDS respectively in nVal in
      36                 :            :  * conjuctions with the flag bQueryByString = FALSE.
      37                 :            :  */
      38                 :            : 
      39                 :            : #define SC_EMPTYFIELDS      ((double)0x0042)
      40                 :            : #define SC_NONEMPTYFIELDS   ((double)0x0043)
      41                 :            : 
      42                 :          0 : bool ScQueryEntry::Item::operator== (const Item& r) const
      43                 :            : {
      44 [ #  # ][ #  # ]:          0 :     return meType == r.meType && mfVal == r.mfVal && maString.equals(r.maString);
                 [ #  # ]
      45                 :            : }
      46                 :            : 
      47                 :       7470 : ScQueryEntry::ScQueryEntry() :
      48                 :            :     bDoQuery(false),
      49                 :            :     nField(0),
      50                 :            :     eOp(SC_EQUAL),
      51                 :            :     eConnect(SC_AND),
      52                 :            :     pSearchParam(NULL),
      53                 :            :     pSearchText(NULL),
      54                 :       7470 :     maQueryItems(1)
      55                 :            : {
      56                 :       7470 : }
      57                 :            : 
      58                 :      19912 : ScQueryEntry::ScQueryEntry(const ScQueryEntry& r) :
      59                 :            :     bDoQuery(r.bDoQuery),
      60                 :            :     nField(r.nField),
      61                 :            :     eOp(r.eOp),
      62                 :            :     eConnect(r.eConnect),
      63                 :            :     pSearchParam(NULL),
      64                 :            :     pSearchText(NULL),
      65                 :      19912 :     maQueryItems(r.maQueryItems)
      66                 :            : {
      67                 :      19912 : }
      68                 :            : 
      69                 :      27022 : ScQueryEntry::~ScQueryEntry()
      70                 :            : {
      71 [ -  + ][ #  # ]:      27022 :     delete pSearchParam;
      72 [ -  + ][ #  # ]:      27022 :     delete pSearchText;
      73                 :      27022 : }
      74                 :            : 
      75                 :         24 : ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
      76                 :            : {
      77                 :         24 :     bDoQuery        = r.bDoQuery;
      78                 :         24 :     eOp             = r.eOp;
      79                 :         24 :     eConnect        = r.eConnect;
      80                 :         24 :     nField          = r.nField;
      81                 :         24 :     maQueryItems  = r.maQueryItems;
      82                 :            : 
      83         [ -  + ]:         24 :     delete pSearchParam;
      84         [ -  + ]:         24 :     delete pSearchText;
      85                 :         24 :     pSearchParam    = NULL;
      86                 :         24 :     pSearchText     = NULL;
      87                 :            : 
      88                 :         24 :     return *this;
      89                 :            : }
      90                 :            : 
      91                 :         67 : ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems()
      92                 :            : {
      93                 :         67 :     return maQueryItems;
      94                 :            : }
      95                 :            : 
      96                 :       1856 : const ScQueryEntry::QueryItemsType& ScQueryEntry::GetQueryItems() const
      97                 :            : {
      98                 :       1856 :     return maQueryItems;
      99                 :            : }
     100                 :            : 
     101                 :          6 : void ScQueryEntry::SetQueryByEmpty()
     102                 :            : {
     103                 :          6 :     eOp = SC_EQUAL;
     104                 :          6 :     maQueryItems.resize(1);
     105                 :          6 :     Item& rItem = maQueryItems[0];
     106                 :          6 :     rItem.meType = ByEmpty;
     107                 :          6 :     rItem.maString = rtl::OUString();
     108                 :          6 :     rItem.mfVal = SC_EMPTYFIELDS;
     109                 :          6 : }
     110                 :            : 
     111                 :         45 : bool ScQueryEntry::IsQueryByEmpty() const
     112                 :            : {
     113         [ -  + ]:         45 :     if (maQueryItems.size() != 1)
     114                 :          0 :         return false;
     115                 :            : 
     116                 :         45 :     const Item& rItem = maQueryItems[0];
     117                 :            :     return eOp == SC_EQUAL &&
     118                 :            :         rItem.meType == ByEmpty &&
     119                 :         41 :         rItem.maString.isEmpty() &&
     120   [ +  +  +  - ]:         86 :         rItem.mfVal == SC_EMPTYFIELDS;
         [ +  + ][ +  - ]
     121                 :            : }
     122                 :            : 
     123                 :          5 : void ScQueryEntry::SetQueryByNonEmpty()
     124                 :            : {
     125                 :          5 :     eOp = SC_EQUAL;
     126                 :          5 :     maQueryItems.resize(1);
     127                 :          5 :     Item& rItem = maQueryItems[0];
     128                 :          5 :     rItem.meType = ByEmpty;
     129                 :          5 :     rItem.maString = rtl::OUString();
     130                 :          5 :     rItem.mfVal = SC_NONEMPTYFIELDS;
     131                 :          5 : }
     132                 :            : 
     133                 :          4 : bool ScQueryEntry::IsQueryByNonEmpty() const
     134                 :            : {
     135         [ -  + ]:          4 :     if (maQueryItems.size() != 1)
     136                 :          0 :         return false;
     137                 :            : 
     138                 :          4 :     const Item& rItem = maQueryItems[0];
     139                 :            :     return eOp == SC_EQUAL &&
     140                 :            :         rItem.meType == ByEmpty &&
     141                 :          0 :         rItem.maString.isEmpty() &&
     142   [ -  +  #  # ]:          4 :         rItem.mfVal == SC_NONEMPTYFIELDS;
         [ #  # ][ +  - ]
     143                 :            : }
     144                 :            : 
     145                 :       5880 : const ScQueryEntry::Item& ScQueryEntry::GetQueryItem() const
     146                 :            : {
     147         [ -  + ]:       5880 :     if (maQueryItems.size() > 1)
     148                 :            :         // Reset to a single query mode.
     149                 :          0 :         maQueryItems.resize(1);
     150                 :       5880 :     return maQueryItems[0];
     151                 :            : }
     152                 :            : 
     153                 :       1188 : ScQueryEntry::Item& ScQueryEntry::GetQueryItem()
     154                 :            : {
     155         [ -  + ]:       1188 :     if (maQueryItems.size() > 1)
     156                 :            :         // Reset to a single query mode.
     157                 :          0 :         maQueryItems.resize(1);
     158                 :       1188 :     return maQueryItems[0];
     159                 :            : }
     160                 :            : 
     161                 :       7437 : void ScQueryEntry::Clear()
     162                 :            : {
     163                 :       7437 :     bDoQuery        = false;
     164                 :       7437 :     eOp             = SC_EQUAL;
     165                 :       7437 :     eConnect        = SC_AND;
     166                 :       7437 :     nField          = 0;
     167                 :       7437 :     maQueryItems.clear();
     168         [ +  - ]:       7437 :     maQueryItems.push_back(Item());
     169                 :            : 
     170         [ -  + ]:       7437 :     delete pSearchParam;
     171         [ -  + ]:       7437 :     delete pSearchText;
     172                 :       7437 :     pSearchParam    = NULL;
     173                 :       7437 :     pSearchText     = NULL;
     174                 :       7437 : }
     175                 :            : 
     176                 :          0 : bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
     177                 :            : {
     178                 :            :     return bDoQuery         == r.bDoQuery
     179                 :            :         && eOp              == r.eOp
     180                 :            :         && eConnect         == r.eConnect
     181                 :            :         && nField           == r.nField
     182 [ #  # ][ #  # ]:          0 :         && maQueryItems   == r.maQueryItems;
         [ #  # ][ #  # ]
                 [ #  # ]
     183                 :            :     //! pSearchParam und pSearchText nicht vergleichen
     184                 :            : }
     185                 :            : 
     186                 :          0 : utl::TextSearch* ScQueryEntry::GetSearchTextPtr( bool bCaseSens ) const
     187                 :            : {
     188         [ #  # ]:          0 :     if ( !pSearchParam )
     189                 :            :     {
     190                 :          0 :         const rtl::OUString& rStr = maQueryItems[0].maString;
     191                 :            :         pSearchParam = new utl::SearchParam(
     192         [ #  # ]:          0 :             rStr, utl::SearchParam::SRCH_REGEXP, bCaseSens, false, false);
     193         [ #  # ]:          0 :         pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
     194                 :            :     }
     195                 :          0 :     return pSearchText;
     196                 :            : }
     197                 :            : 
     198                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10