LibreOffice Module dbaccess (master) 1
queryorder.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 <strings.hrc>
21#include <strings.hxx>
22#include <core_resource.hxx>
23#include <queryorder.hxx>
24#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
25#include <com/sun/star/sdbc/ColumnSearch.hpp>
26#include <com/sun/star/sdbc/XConnection.hpp>
27#include <com/sun/star/container/XNameAccess.hpp>
29#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
31
32using namespace dbaui;
33using namespace connectivity;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::util;
37using namespace ::com::sun::star::sdb;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::sdbcx;
40using namespace ::com::sun::star::beans;
41
42
43DlgOrderCrit::DlgOrderCrit(weld::Window * pParent,
44 const Reference< XConnection>& _rxConnection,
46 const Reference< XNameAccess>& _rxCols)
47 : GenericDialogController(pParent, "dbaccess/ui/sortdialog.ui", "SortDialog")
48 , m_xQueryComposer(_rxComposer)
49 , m_xColumns(_rxCols)
50 , m_xConnection(_rxConnection)
51 , m_xLB_ORDERFIELD1(m_xBuilder->weld_combo_box("field1"))
52 , m_xLB_ORDERVALUE1(m_xBuilder->weld_combo_box("value1"))
53 , m_xLB_ORDERFIELD2(m_xBuilder->weld_combo_box("field2"))
54 , m_xLB_ORDERVALUE2(m_xBuilder->weld_combo_box("value2"))
55 , m_xLB_ORDERFIELD3(m_xBuilder->weld_combo_box("field3"))
56 , m_xLB_ORDERVALUE3(m_xBuilder->weld_combo_box("value3"))
57{
61
65
66 OUString aSTR_NOENTRY(DBA_RES(STR_VALUE_NONE));
67 for (auto j : m_aColumnList)
68 {
69 j->append_text(aSTR_NOENTRY);
70 }
71
72 for (int j=0; j < DOG_ROWS; ++j)
73 {
76 }
77 try
78 {
79 // ... also the remaining fields
80 Sequence< OUString> aNames = m_xColumns->getElementNames();
81 const OUString* pIter = aNames.getConstArray();
82 const OUString* pEnd = pIter + aNames.getLength();
84 for(;pIter != pEnd;++pIter)
85 {
86 xColumn.set(m_xColumns->getByName(*pIter),UNO_QUERY);
87 OSL_ENSURE(xColumn.is(),"Column is null!");
88 if ( xColumn.is() )
89 {
90 sal_Int32 nDataType = 0;
91 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
92 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
93 if(eColumnSearch != ColumnSearch::NONE)
94 {
95 for (auto j : m_aColumnList)
96 {
97 j->append_text(*pIter);
98 }
99 }
100 }
101 }
102
103 m_sOrgOrder = m_xQueryComposer->getOrder();
105 }
106 catch(const Exception&)
107 {
108 DBG_UNHANDLED_EXCEPTION("dbaccess");
109 }
110 EnableLines();
111
112 m_xLB_ORDERFIELD1->connect_changed(LINK(this,DlgOrderCrit,FieldListSelectHdl));
113 m_xLB_ORDERFIELD2->connect_changed(LINK(this,DlgOrderCrit,FieldListSelectHdl));
114}
115
117{
118}
119
120IMPL_LINK_NOARG( DlgOrderCrit, FieldListSelectHdl, weld::ComboBox&, void )
121{
122 EnableLines();
123}
124
126{
127 try
128 {
129 static constexpr OUStringLiteral sNameProperty = u"Name";
130 static constexpr OUStringLiteral sAscendingProperty = u"IsAscending";
131
132 Reference< XIndexAccess > xOrderColumns( m_xQueryComposer->getOrderColumns(), UNO_SET_THROW );
133 sal_Int32 nColumns = xOrderColumns->getCount();
134 if ( nColumns > DOG_ROWS )
135 nColumns = DOG_ROWS;
136
137 for ( sal_Int32 i = 0; i < nColumns; ++i )
138 {
139 Reference< XPropertySet > xColumn( xOrderColumns->getByIndex( i ), UNO_QUERY_THROW );
140
141 OUString sColumnName;
142 bool bIsAscending( true );
143
144 xColumn->getPropertyValue( sNameProperty ) >>= sColumnName;
145 xColumn->getPropertyValue( sAscendingProperty ) >>= bIsAscending;
146
147 m_aColumnList[i]->set_active_text(sColumnName);
148 m_aValueList[i]->set_active(bIsAscending ? 0 : 1);
149 }
150 }
151 catch( const Exception& )
152 {
153 DBG_UNHANDLED_EXCEPTION("dbaccess");
154 }
155}
156
158{
159
160 if ( m_xLB_ORDERFIELD1->get_active() == 0 )
161 {
162 m_xLB_ORDERFIELD2->set_sensitive(false);
163 m_xLB_ORDERVALUE2->set_sensitive(false);
164
165 m_xLB_ORDERFIELD2->set_active( 0 );
166 m_xLB_ORDERVALUE2->set_active( 0 );
167 }
168 else
169 {
170 m_xLB_ORDERFIELD2->set_sensitive(true);
171 m_xLB_ORDERVALUE2->set_sensitive(true);
172 }
173
174 if ( m_xLB_ORDERFIELD2->get_active() == 0 )
175 {
176 m_xLB_ORDERFIELD3->set_sensitive(false);
177 m_xLB_ORDERVALUE3->set_sensitive(false);
178
179 m_xLB_ORDERFIELD3->set_active( 0 );
180 m_xLB_ORDERVALUE3->set_active( 0 );
181 }
182 else
183 {
184 m_xLB_ORDERFIELD3->set_sensitive(true);
185 m_xLB_ORDERVALUE3->set_sensitive(true);
186 }
187}
188
190{
191 Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
192 OUString sQuote = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : OUString();
193
194 OUStringBuffer sOrder;
195 for( sal_uInt16 i=0 ; i<DOG_ROWS; i++ )
196 {
197 if (m_aColumnList[i]->get_active() != 0)
198 {
199 if(!sOrder.isEmpty())
200 sOrder.append(",");
201
202 OUString sName = m_aColumnList[i]->get_active_text();
203 sOrder.append(::dbtools::quoteName(sQuote,sName));
204 if (m_aValueList[i]->get_active())
205 sOrder.append(" DESC ");
206 else
207 sOrder.append(" ASC ");
208 }
209 }
210 return sOrder.makeStringAndClear();
211}
212
214{
215 m_xQueryComposer->setOrder(GetOrderList());
216}
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nDataType
OptionalString sName
std::unique_ptr< weld::ComboBox > m_xLB_ORDERFIELD3
Definition: queryorder.hxx:58
std::unique_ptr< weld::ComboBox > m_xLB_ORDERFIELD1
Definition: queryorder.hxx:54
weld::ComboBox * m_aColumnList[DOG_ROWS]
Definition: queryorder.hxx:51
std::unique_ptr< weld::ComboBox > m_xLB_ORDERVALUE2
Definition: queryorder.hxx:57
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: queryorder.hxx:49
css::uno::Reference< css::container::XNameAccess > m_xColumns
Definition: queryorder.hxx:48
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xQueryComposer
Definition: queryorder.hxx:47
std::unique_ptr< weld::ComboBox > m_xLB_ORDERVALUE3
Definition: queryorder.hxx:59
void impl_initializeOrderList_nothrow()
Definition: queryorder.cxx:125
OUString GetOrderList() const
Definition: queryorder.cxx:189
std::unique_ptr< weld::ComboBox > m_xLB_ORDERFIELD2
Definition: queryorder.hxx:56
std::unique_ptr< weld::ComboBox > m_xLB_ORDERVALUE1
Definition: queryorder.hxx:55
weld::ComboBox * m_aValueList[DOG_ROWS]
Definition: queryorder.hxx:52
virtual ~DlgOrderCrit() override
Definition: queryorder.cxx:116
virtual OUString get_active_text() const=0
virtual void set_active(int pos)=0
void set_active_text(const OUString &rStr)
#define DBA_RES(id)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
const char sQuote[]
Reference< XColumn > xColumn
@ Exception
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
sal_Int32 getSearchColumnFlag(const Reference< XConnection > &_rxConn, sal_Int32 _nDataType)
int i
Reference< XConnection > m_xConnection
Definition: objectnames.cxx:79
#define DOG_ROWS
Definition: queryorder.hxx:23
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")