calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / ui / querydesign / QTableWindow.cxx
blob6b129c32d5fd11a74cdd778fb665e1c2e84da029
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 "QTableWindow.hxx"
21 #include <QueryTableView.hxx>
22 #include <JoinController.hxx>
23 #include <JoinDesignView.hxx>
24 #include <osl/diagnose.h>
25 #include <helpids.h>
26 #include <browserids.hxx>
27 #include <TableWindowListBox.hxx>
28 #include <strings.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/sdbc/SQLException.hpp>
31 #include "TableFieldInfo.hxx"
32 #include <comphelper/stl_types.hxx>
33 #include <comphelper/types.hxx>
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::beans;
39 using namespace dbaui;
40 OQueryTableWindow::OQueryTableWindow( vcl::Window* pParent, const TTableWindowData::value_type& pTabWinData)
41 :OTableWindow( pParent, pTabWinData )
42 ,m_nAliasNum(0)
44 m_strInitialAlias = GetAliasName();
46 // if table name matches alias, do not pass to InitialAlias,
47 // as the appending of a possible token could not succeed...
48 if (m_strInitialAlias == pTabWinData->GetTableName())
49 m_strInitialAlias.clear();
51 SetHelpId(HID_CTL_QRYDGNTAB);
54 bool OQueryTableWindow::Init()
56 bool bSuccess = OTableWindow::Init();
57 if (!bSuccess)
58 return bSuccess;
60 OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
62 // first determine Alias
63 OUString sAliasName;
65 TTableWindowData::value_type pWinData = GetData();
67 if (!m_strInitialAlias.isEmpty() )
68 // Alias was explicitly given
69 sAliasName = m_strInitialAlias;
70 else if ( GetTable().is() )
71 GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
72 else
73 return false;
75 // Alias with successive number
76 if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
78 sAliasName += "_" + OUString::number(m_nAliasNum);
81 sAliasName = sAliasName.replaceAll("\"", "");
82 SetAliasName(sAliasName);
83 // SetAliasName passes it as WinName, hence it uses the base class
84 // reset the title
85 m_xTitle->SetText( pWinData->GetWinName() );
86 m_xTitle->Show();
88 getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
89 return bSuccess;
92 void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
94 OTableFieldInfo* pInfo = new OTableFieldInfo();
95 pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
96 if ( _xColumn.is() )
97 pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
98 return pInfo;
101 void OQueryTableWindow::deleteUserData(void*& _pUserData)
103 delete static_cast<OTableFieldInfo*>(_pUserData);
104 _pUserData = nullptr;
107 void OQueryTableWindow::OnEntryDoubleClicked(weld::TreeIter& rEntry)
109 if (getTableView()->getDesignView()->getController().isReadOnly())
110 return;
112 weld::TreeView& rTreeView = m_xListBox->get_widget();
113 OTableFieldInfo* pInf = weld::fromId<OTableFieldInfo*>(rTreeView.get_id(rEntry));
114 OSL_ENSURE(pInf != nullptr, "OQueryTableWindow::OnEntryDoubleClicked : field doesn't have FieldInfo !");
116 // build up DragInfo
117 OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(), rTreeView.get_text(rEntry));
118 aInfo->SetTabWindow(this);
119 aInfo->SetAlias(GetAliasName());
120 aInfo->SetFieldIndex(rTreeView.get_iter_index_in_parent(rEntry));
121 aInfo->SetDataType(pInf->GetDataType());
123 // and insert corresponding field
124 static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
127 bool OQueryTableWindow::ExistsField(const OUString& strFieldName, OTableFieldDescRef const & rInfo)
129 OSL_ENSURE(m_xListBox != nullptr, "OQueryTableWindow::ExistsField : doesn't have css::form::ListBox !");
130 OSL_ENSURE(rInfo.is(),"OQueryTableWindow::ExistsField: invalid argument for OTableFieldDescRef!");
131 Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
132 bool bExists = false;
133 if(xConnection.is())
135 weld::TreeView& rTreeView = m_xListBox->get_widget();
136 std::unique_ptr<weld::TreeIter> xEntry(rTreeView.make_iterator());
137 bool bEntry = rTreeView.get_iter_first(*xEntry);
140 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
141 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
143 while (bEntry)
145 if (bCase(strFieldName, rTreeView.get_text(*xEntry)))
147 OTableFieldInfo* pInf = weld::fromId<OTableFieldInfo*>(rTreeView.get_id(*xEntry));
148 assert(pInf && "OQueryTableWindow::ExistsField : field doesn't have FieldInfo !");
150 rInfo->SetTabWindow(this);
151 rInfo->SetField(strFieldName);
152 rInfo->SetTable(GetTableName());
153 rInfo->SetAlias(GetAliasName());
154 rInfo->SetFieldIndex(rTreeView.get_iter_index_in_parent(*xEntry));
155 rInfo->SetDataType(pInf->GetDataType());
156 bExists = true;
157 break;
159 bEntry = rTreeView.iter_next(*xEntry);
162 catch(SQLException&)
167 return bExists;
170 bool OQueryTableWindow::ExistsAVisitedConn() const
172 return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */