LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - queryorder.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 113 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 12 16.7 %
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 "dbu_tbl.hrc"
      21             : #include "queryorder.hxx"
      22             : #include "dbustrings.hrc"
      23             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      24             : #include <com/sun/star/sdbc/ColumnSearch.hpp>
      25             : #include <com/sun/star/container/XNameAccess.hpp>
      26             : #include <tools/debug.hxx>
      27             : #include "moduledbu.hxx"
      28             : #include <connectivity/sqliterator.hxx>
      29             : #include <connectivity/dbtools.hxx>
      30             : #include <comphelper/extract.hxx>
      31             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      32             : #include <tools/diagnose_ex.h>
      33             : #include <vcl/settings.hxx>
      34             : #include <algorithm>
      35             : 
      36             : using namespace dbaui;
      37             : using namespace connectivity;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::container;
      40             : using namespace ::com::sun::star::util;
      41             : using namespace ::com::sun::star::sdb;
      42             : using namespace ::com::sun::star::sdbc;
      43             : using namespace ::com::sun::star::sdbcx;
      44             : using namespace ::com::sun::star::beans;
      45             : 
      46             : 
      47           0 : DlgOrderCrit::DlgOrderCrit(vcl::Window * pParent,
      48             :     const Reference< XConnection>& _rxConnection,
      49             :     const Reference< XSingleSelectQueryComposer >& _rxComposer,
      50             :     const Reference< XNameAccess>& _rxCols)
      51             :     : ModalDialog(pParent, "SortDialog", "dbaccess/ui/sortdialog.ui")
      52             :     , aSTR_NOENTRY(ModuleRes(STR_VALUE_NONE))
      53             :     , m_xQueryComposer(_rxComposer)
      54             :     , m_xColumns(_rxCols)
      55           0 :     , m_xConnection(_rxConnection)
      56             : {
      57             : 
      58           0 :     get(m_pLB_ORDERFIELD1, "field1");
      59           0 :     get(m_pLB_ORDERVALUE1, "value1");
      60           0 :     get(m_pLB_ORDERFIELD2, "field2");
      61           0 :     get(m_pLB_ORDERVALUE2, "value2");
      62           0 :     get(m_pLB_ORDERFIELD3, "field3");
      63           0 :     get(m_pLB_ORDERVALUE3, "value3");
      64             : 
      65           0 :     AllSettings aSettings( GetSettings() );
      66           0 :     StyleSettings aStyle( aSettings.GetStyleSettings() );
      67           0 :     aStyle.SetAutoMnemonic( false );
      68           0 :     aSettings.SetStyleSettings( aStyle );
      69           0 :     SetSettings( aSettings );
      70             : 
      71           0 :     m_aColumnList[0] = m_pLB_ORDERFIELD1;
      72           0 :     m_aColumnList[1] = m_pLB_ORDERFIELD2;
      73           0 :     m_aColumnList[2] = m_pLB_ORDERFIELD3;
      74             : 
      75           0 :     m_aValueList[0] = m_pLB_ORDERVALUE1;
      76           0 :     m_aValueList[1] = m_pLB_ORDERVALUE2;
      77           0 :     m_aValueList[2] = m_pLB_ORDERVALUE3;
      78             : 
      79           0 :     for (int j=0; j < DOG_ROWS; ++j)
      80             :     {
      81           0 :         m_aColumnList[j]->InsertEntry( aSTR_NOENTRY );
      82             :     }
      83             : 
      84           0 :     for (int j=0; j < DOG_ROWS; ++j)
      85             :     {
      86           0 :         m_aColumnList[j]->SelectEntryPos(0);
      87           0 :         m_aValueList[j]->SelectEntryPos(0);
      88             :     }
      89             :     try
      90             :     {
      91             :         // ... also the remaining fields
      92           0 :         Sequence< OUString> aNames = m_xColumns->getElementNames();
      93           0 :         const OUString* pIter = aNames.getConstArray();
      94           0 :         const OUString* pEnd   = pIter + aNames.getLength();
      95           0 :         Reference<XPropertySet> xColumn;
      96           0 :         for(;pIter != pEnd;++pIter)
      97             :         {
      98           0 :             xColumn.set(m_xColumns->getByName(*pIter),UNO_QUERY);
      99             :             OSL_ENSURE(xColumn.is(),"Column is null!");
     100           0 :             if ( xColumn.is() )
     101             :             {
     102           0 :                 sal_Int32 nDataType = 0;
     103           0 :                 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
     104           0 :                 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
     105           0 :                 if(eColumnSearch != ColumnSearch::NONE)
     106             :                 {
     107           0 :                     for (int j=0; j < DOG_ROWS; ++j)
     108             :                     {
     109           0 :                         m_aColumnList[j]->InsertEntry(*pIter);
     110             :                     }
     111             :                 }
     112             :             }
     113             :         }
     114             : 
     115           0 :         m_sOrgOrder = m_xQueryComposer->getOrder();
     116           0 :         impl_initializeOrderList_nothrow();
     117             :     }
     118           0 :     catch(const Exception&)
     119             :     {
     120             :         DBG_UNHANDLED_EXCEPTION();
     121             :     }
     122           0 :     EnableLines();
     123             : 
     124           0 :     m_pLB_ORDERFIELD1->SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
     125           0 :     m_pLB_ORDERFIELD2->SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
     126           0 : }
     127             : 
     128           0 : DlgOrderCrit::~DlgOrderCrit()
     129             : {
     130           0 :     disposeOnce();
     131           0 : }
     132             : 
     133           0 : void DlgOrderCrit::dispose()
     134             : {
     135           0 :     m_pLB_ORDERFIELD1.clear();
     136           0 :     m_pLB_ORDERVALUE1.clear();
     137           0 :     m_pLB_ORDERFIELD2.clear();
     138           0 :     m_pLB_ORDERVALUE2.clear();
     139           0 :     m_pLB_ORDERFIELD3.clear();
     140           0 :     m_pLB_ORDERVALUE3.clear();
     141           0 :     for (auto a : m_aColumnList) a.clear();
     142           0 :     for (auto a : m_aValueList) a.clear();
     143           0 :     ModalDialog::dispose();
     144           0 : }
     145             : 
     146           0 : IMPL_LINK( DlgOrderCrit, FieldListSelectHdl, ListBox *, /*pListBox*/ )
     147             : {
     148           0 :     EnableLines();
     149           0 :     return 0;
     150             : }
     151             : 
     152           0 : void DlgOrderCrit::impl_initializeOrderList_nothrow()
     153             : {
     154             :     try
     155             :     {
     156           0 :         const OUString sNameProperty = "Name";
     157           0 :         const OUString sAscendingProperty = "IsAscending";
     158             : 
     159           0 :         Reference< XIndexAccess > xOrderColumns( m_xQueryComposer->getOrderColumns(), UNO_QUERY_THROW );
     160           0 :         sal_Int32 nColumns = xOrderColumns->getCount();
     161           0 :         if ( nColumns > DOG_ROWS )
     162           0 :             nColumns = DOG_ROWS;
     163             : 
     164           0 :         for ( sal_Int32 i = 0; i < nColumns; ++i )
     165             :         {
     166           0 :             Reference< XPropertySet > xColumn( xOrderColumns->getByIndex( i ), UNO_QUERY_THROW );
     167             : 
     168           0 :             OUString sColumnName;
     169           0 :             bool        bIsAscending( true );
     170             : 
     171           0 :             xColumn->getPropertyValue( sNameProperty ) >>= sColumnName;
     172           0 :             xColumn->getPropertyValue( sAscendingProperty ) >>= bIsAscending;
     173             : 
     174           0 :             m_aColumnList[i]->SelectEntry( sColumnName );
     175           0 :             m_aValueList[i]->SelectEntryPos( bIsAscending ? 0 : 1 );
     176           0 :         }
     177             :     }
     178           0 :     catch( const Exception& )
     179             :     {
     180             :         DBG_UNHANDLED_EXCEPTION();
     181             :     }
     182           0 : }
     183             : 
     184           0 : void DlgOrderCrit::EnableLines()
     185             : {
     186             : 
     187           0 :     if ( m_pLB_ORDERFIELD1->GetSelectEntryPos() == 0 )
     188             :     {
     189           0 :         m_pLB_ORDERFIELD2->Disable();
     190           0 :         m_pLB_ORDERVALUE2->Disable();
     191             : 
     192           0 :         m_pLB_ORDERFIELD2->SelectEntryPos( 0 );
     193           0 :         m_pLB_ORDERVALUE2->SelectEntryPos( 0 );
     194             :     }
     195             :     else
     196             :     {
     197           0 :         m_pLB_ORDERFIELD2->Enable();
     198           0 :         m_pLB_ORDERVALUE2->Enable();
     199             :     }
     200             : 
     201           0 :     if ( m_pLB_ORDERFIELD2->GetSelectEntryPos() == 0 )
     202             :     {
     203           0 :         m_pLB_ORDERFIELD3->Disable();
     204           0 :         m_pLB_ORDERVALUE3->Disable();
     205             : 
     206           0 :         m_pLB_ORDERFIELD3->SelectEntryPos( 0 );
     207           0 :         m_pLB_ORDERVALUE3->SelectEntryPos( 0 );
     208             :     }
     209             :     else
     210             :     {
     211           0 :         m_pLB_ORDERFIELD3->Enable();
     212           0 :         m_pLB_ORDERVALUE3->Enable();
     213             :     }
     214           0 : }
     215             : 
     216           0 : OUString DlgOrderCrit::GetOrderList( ) const
     217             : {
     218           0 :     Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
     219           0 :     OUString sQuote  = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : OUString();
     220             :     static const char sDESC[] = " DESC ";
     221             :     static const char sASC[] = " ASC ";
     222             : 
     223           0 :     Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
     224             : 
     225           0 :     OUString sOrder;
     226           0 :     for( sal_uInt16 i=0 ; i<DOG_ROWS; i++ )
     227             :     {
     228           0 :         if(m_aColumnList[i]->GetSelectEntryPos() != 0)
     229             :         {
     230           0 :             if(!sOrder.isEmpty())
     231           0 :                 sOrder += ",";
     232             : 
     233           0 :             OUString sName = m_aColumnList[i]->GetSelectEntry();
     234           0 :             sOrder += ::dbtools::quoteName(sQuote,sName);
     235           0 :             if(m_aValueList[i]->GetSelectEntryPos())
     236           0 :                 sOrder += sDESC;
     237             :             else
     238           0 :                 sOrder += sASC;
     239             :         }
     240             :     }
     241           0 :     return sOrder;
     242             : }
     243             : 
     244           0 : void DlgOrderCrit::BuildOrderPart()
     245             : {
     246           0 :     m_xQueryComposer->setOrder(GetOrderList());
     247          36 : }
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11