diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-02-28 21:22:45 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-03-01 22:23:26 +0100 |
commit | e6c422696fa1ee3f94642d94f7aca6743ad1e1e0 (patch) | |
tree | de3168f885ba0ff1825562b24ee8ed3864b5cc7c /sw/source/uibase | |
parent | 289cff91eb67c27874ba11115b9188a05ea8768d (diff) |
weld SwChangeDBDlg
Change-Id: Ie0fc6a6346f9c777b7172a0b641a2783cf633c1d
Reviewed-on: https://gerrit.libreoffice.org/68544
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r-- | sw/source/uibase/dbui/dbtree.cxx | 286 | ||||
-rw-r--r-- | sw/source/uibase/inc/changedb.hxx | 32 | ||||
-rw-r--r-- | sw/source/uibase/inc/dbtree.hxx | 35 |
3 files changed, 336 insertions, 17 deletions
diff --git a/sw/source/uibase/dbui/dbtree.cxx b/sw/source/uibase/dbui/dbtree.cxx index 8daa167434f5..34840d85261b 100644 --- a/sw/source/uibase/dbui/dbtree.cxx +++ b/sw/source/uibase/dbui/dbtree.cxx @@ -486,4 +486,290 @@ void SwDBTreeList::SetWrtShell(SwWrtShell& rSh) InitTreeList(); } +DBTreeList::DBTreeList(std::unique_ptr<weld::TreeView> xTreeView) + : bInitialized(false) + , bShowColumns(false) + , pImpl(new SwDBTreeList_Impl) + , m_xTreeView(std::move(xTreeView)) +{ + m_xTreeView->connect_expanding(LINK(this, DBTreeList, RequestingChildrenHdl)); +#if 0 + if (m_xTreeView->get_visible()) + InitTreeList(); +#endif +} + +DBTreeList::~DBTreeList() +{ +} + +void DBTreeList::InitTreeList() +{ + if (!pImpl->HasContext() && pImpl->GetWrtShell()) + return; + +//TODO SetDragDropMode(DragDropMode::APP_COPY); + +//TODO GetModel()->SetCompareHdl(LINK(this, DBTreeList, DBCompare)); + + Sequence< OUString > aDBNames = pImpl->GetContext()->getElementNames(); + auto const sort = comphelper::string::NaturalStringSorter( + comphelper::getProcessComponentContext(), + Application::GetSettings().GetUILanguageTag().getLocale()); + std::sort( + aDBNames.begin(), aDBNames.end(), + [&sort](OUString const & x, OUString const & y) + { return sort.compare(x, y) < 0; }); + const OUString* pDBNames = aDBNames.getConstArray(); + sal_Int32 nCount = aDBNames.getLength(); + + OUString aImg(RID_BMP_DB); + for (sal_Int32 i = 0; i < nCount; ++i) + { + OUString sDBName(pDBNames[i]); + Reference<XConnection> xConnection = pImpl->GetConnection(sDBName); + if (xConnection.is()) + { + m_xTreeView->insert(nullptr, -1, &sDBName, nullptr, nullptr, nullptr, &aImg, true, nullptr); + } + } + Select(OUString(), OUString(), OUString()); + + bInitialized = true; +} + +void DBTreeList::AddDataSource(const OUString& rSource) +{ + OUString aImg(RID_BMP_DB); + std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator()); + m_xTreeView->insert(nullptr, -1, &rSource, nullptr, nullptr, nullptr, &aImg, true, xIter.get()); + m_xTreeView->select(*xIter); +} + +IMPL_LINK(DBTreeList, RequestingChildrenHdl, weld::TreeIter&, rParent, bool) +{ + if (!m_xTreeView->iter_has_child(rParent)) + { + if (m_xTreeView->get_iter_depth(rParent)) // column names + { + try + { + std::unique_ptr<weld::TreeIter> xGrandParent(m_xTreeView->make_iterator(&rParent)); + m_xTreeView->iter_parent(*xGrandParent); + OUString sSourceName = m_xTreeView->get_text(*xGrandParent); + OUString sTableName = m_xTreeView->get_text(rParent); + + if(!pImpl->GetContext()->hasByName(sSourceName)) + return true; + Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName); + bool bTable = m_xTreeView->get_id(rParent).isEmpty(); + Reference<XColumnsSupplier> xColsSupplier; + if(bTable) + { + Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY); + if(xTSupplier.is()) + { + Reference<XNameAccess> xTables = xTSupplier->getTables(); + OSL_ENSURE(xTables->hasByName(sTableName), "table not available anymore?"); + try + { + Any aTable = xTables->getByName(sTableName); + Reference<XPropertySet> xPropSet; + aTable >>= xPropSet; + xColsSupplier.set(xPropSet, UNO_QUERY); + } + catch (const Exception&) + { + } + } + } + else + { + Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY); + if(xQSupplier.is()) + { + Reference<XNameAccess> xQueries = xQSupplier->getQueries(); + OSL_ENSURE(xQueries->hasByName(sTableName), "table not available anymore?"); + try + { + Any aQuery = xQueries->getByName(sTableName); + Reference<XPropertySet> xPropSet; + aQuery >>= xPropSet; + xColsSupplier.set(xPropSet, UNO_QUERY); + } + catch (const Exception&) + { + } + } + } + + if(xColsSupplier.is()) + { + Reference <XNameAccess> xCols = xColsSupplier->getColumns(); + Sequence< OUString> aColNames = xCols->getElementNames(); + const OUString* pColNames = aColNames.getConstArray(); + long nCount = aColNames.getLength(); + for (long i = 0; i < nCount; i++) + { + OUString sName = pColNames[i]; + m_xTreeView->append(&rParent, sName); + } + } + } + catch (const Exception&) + { + } + } + else // table names + { + try + { + OUString sSourceName = m_xTreeView->get_text(rParent); + if (!pImpl->GetContext()->hasByName(sSourceName)) + return true; + Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName); + if (xConnection.is()) + { + Reference<XTablesSupplier> xTSupplier(xConnection, UNO_QUERY); + if(xTSupplier.is()) + { + Reference<XNameAccess> xTables = xTSupplier->getTables(); + Sequence< OUString> aTableNames = xTables->getElementNames(); + OUString sTableName; + long nCount = aTableNames.getLength(); + const OUString* pTableNames = aTableNames.getConstArray(); + OUString aImg(RID_BMP_DBTABLE); + for (long i = 0; i < nCount; i++) + { + sTableName = pTableNames[i]; + m_xTreeView->insert(&rParent, -1, &sTableName, nullptr, + nullptr, nullptr, &aImg, bShowColumns, nullptr); + } + } + + Reference<XQueriesSupplier> xQSupplier(xConnection, UNO_QUERY); + if(xQSupplier.is()) + { + Reference<XNameAccess> xQueries = xQSupplier->getQueries(); + Sequence< OUString> aQueryNames = xQueries->getElementNames(); + OUString sQueryName; + long nCount = aQueryNames.getLength(); + const OUString* pQueryNames = aQueryNames.getConstArray(); + OUString aImg(RID_BMP_DBQUERY); + for (long i = 0; i < nCount; i++) + { + sQueryName = pQueryNames[i]; + //to discriminate between queries and tables the user data of query entries is set + OUString sId(OUString::number(1)); + m_xTreeView->insert(&rParent, -1, &sQueryName, &sId, + nullptr, nullptr, &aImg, bShowColumns, nullptr); + } + } + } + } + catch (const Exception&) + { + } + } + } + return true; +} + +#if 0 +IMPL_LINK( DBTreeList, DBCompare, const SvSortData&, rData, sal_Int32 ) +{ + SvTreeListEntry* pRight = const_cast<SvTreeListEntry*>(rData.pRight); + + if (GetParent(pRight) && GetParent(GetParent(pRight))) + return 1; // don't sort column names + + return DefaultCompare(rData); // otherwise call base class +} +#endif + +OUString DBTreeList::GetDBName(OUString& rTableName, OUString& rColumnName, sal_Bool* pbIsTable) +{ + OUString sDBName; + std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator()); + if (m_xTreeView->get_selected(xIter.get()) && m_xTreeView->get_iter_depth(*xIter)) + { + if (m_xTreeView->get_iter_depth(*xIter) > 2) + { + rColumnName = m_xTreeView->get_text(*xIter); + m_xTreeView->iter_parent(*xIter); // column name was selected + } + if (pbIsTable) + { + *pbIsTable = m_xTreeView->get_id(*xIter).isEmpty(); + } + rTableName = m_xTreeView->get_text(*xIter); + m_xTreeView->iter_parent(*xIter); + sDBName = m_xTreeView->get_text(*xIter); + } + return sDBName; +} + +// Format: database.table +void DBTreeList::Select(const OUString& rDBName, const OUString& rTableName, const OUString& rColumnName) +{ + std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator()); + if (!m_xTreeView->get_iter_first(*xParent)) + return; + + do + { + if (rDBName == m_xTreeView->get_text(*xParent)) + { + if (!m_xTreeView->iter_has_child(*xParent)) + m_xTreeView->expand_row(*xParent); + std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xParent.get())); + if (!m_xTreeView->iter_children(*xChild)) + continue; + do + { + if (rTableName == m_xTreeView->get_text(*xChild)) + { + m_xTreeView->copy_iterator(*xChild, *xParent); + + bool bNoChild = false; + if (bShowColumns && !rColumnName.isEmpty()) + { + if (!m_xTreeView->iter_has_child(*xParent)) + m_xTreeView->expand_row(*xParent); + + bNoChild = true; + if (m_xTreeView->iter_children(*xChild)) + { + do + { + if (rColumnName == m_xTreeView->get_text(*xChild)) + { + bNoChild = false; + break; + } + } + while (m_xTreeView->iter_next_sibling(*xChild)); + } + } + + if (bNoChild) + m_xTreeView->copy_iterator(*xParent, *xChild); + + m_xTreeView->scroll_to_row(*xChild); + m_xTreeView->select(*xChild); + return; + } + } + while (m_xTreeView->iter_next_sibling(*xChild)); + } + } while (m_xTreeView->iter_next_sibling(*xParent)); +} + +void DBTreeList::SetWrtShell(SwWrtShell& rSh) +{ + pImpl->SetWrtShell(rSh); + if (m_xTreeView->get_visible() && !bInitialized) + InitTreeList(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/inc/changedb.hxx b/sw/source/uibase/inc/changedb.hxx index b2563f0e85c8..9beae0bb1a76 100644 --- a/sw/source/uibase/inc/changedb.hxx +++ b/sw/source/uibase/inc/changedb.hxx @@ -19,11 +19,8 @@ #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_CHANGEDB_HXX #define INCLUDED_SW_SOURCE_UIBASE_INC_CHANGEDB_HXX -#include <vcl/bitmap.hxx> -#include <vcl/button.hxx> -#include <vcl/fixed.hxx> -#include <vcl/treelistbox.hxx> #include <svx/stddlg.hxx> +#include <vcl/weld.hxx> #include "dbtree.hxx" class SwFieldMgr; @@ -32,30 +29,31 @@ class SwWrtShell; struct SwDBData; // exchange database at fields -class SwChangeDBDlg: public SvxStandardDialog +class SwChangeDBDlg : public SfxDialogController { - VclPtr<SvTreeListBox> m_pUsedDBTLB; - VclPtr<SwDBTreeList> m_pAvailDBTLB; - VclPtr<PushButton> m_pAddDBPB; - VclPtr<FixedText> m_pDocDBNameFT; - VclPtr<PushButton> m_pDefineBT; - SwWrtShell *pSh; - DECL_LINK(TreeSelectHdl, SvTreeListBox*, void); - DECL_LINK(ButtonHdl, Button*, void); - DECL_LINK(AddDBHdl, Button*, void); + std::unique_ptr<weld::TreeView> m_xUsedDBTLB; + std::unique_ptr<DBTreeList> m_xAvailDBTLB; + std::unique_ptr<weld::Button> m_xAddDBPB; + std::unique_ptr<weld::Label> m_xDocDBNameFT; + std::unique_ptr<weld::Button> m_xDefineBT; + + void TreeSelect(); + + DECL_LINK(TreeSelectHdl, weld::TreeView&, void); + DECL_LINK(ButtonHdl, weld::Button&, void); + DECL_LINK(AddDBHdl, weld::Button&, void); - virtual void Apply() override; void UpdateFields(); void FillDBPopup(); - SvTreeListEntry* Insert(const OUString& rDBName); + std::unique_ptr<weld::TreeIter> Insert(const OUString& rDBName); void ShowDBName(const SwDBData& rDBData); public: SwChangeDBDlg(SwView const & rVw); + virtual short run() override; virtual ~SwChangeDBDlg() override; - virtual void dispose() override; }; #endif diff --git a/sw/source/uibase/inc/dbtree.hxx b/sw/source/uibase/inc/dbtree.hxx index 333f850d2137..c9634b6ed7a7 100644 --- a/sw/source/uibase/inc/dbtree.hxx +++ b/sw/source/uibase/inc/dbtree.hxx @@ -21,6 +21,7 @@ #include <memory> #include <vcl/treelistbox.hxx> +#include <vcl/weld.hxx> #include <swdllapi.h> #include <swtypes.hxx> @@ -62,6 +63,40 @@ public: void AddDataSource(const OUString& rSource); }; +class SW_DLLPUBLIC DBTreeList +{ + bool bInitialized; + bool bShowColumns; + + rtl::Reference<SwDBTreeList_Impl> pImpl; + std::unique_ptr<weld::TreeView> m_xTreeView; +#if 0 + + DECL_DLLPRIVATE_LINK( DBCompare, const SvSortData&, sal_Int32 ); +#endif + DECL_DLLPRIVATE_LINK(RequestingChildrenHdl, weld::TreeIter&, bool); + SAL_DLLPRIVATE void InitTreeList(); + +public: + DBTreeList(std::unique_ptr<weld::TreeView> xTreeView); + ~DBTreeList(); + + OUString GetDBName(OUString& rTableName, OUString& rColumnName, sal_Bool* pbIsTable = nullptr); + + void Select( const OUString& rDBName, const OUString& rTableName, + const OUString& rColumnName ); + + void SetWrtShell(SwWrtShell& rSh); + + void AddDataSource(const OUString& rSource); + + void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xTreeView->connect_changed(rLink); } + std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const { return m_xTreeView->make_iterator(pOrig); } + bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); } + int get_iter_depth(const weld::TreeIter& rIter) const { return m_xTreeView->get_iter_depth(rIter); } + void set_size_request(int nWidth, int nHeight) { m_xTreeView->set_size_request(nWidth, nHeight); } +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |