From cfe36f7ae75caba07de5978a4e08334fadb62c78 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Wed, 6 Feb 2019 08:57:29 +0000 Subject: [PATCH] Move wxQtTreeItemEditorFactory to its own header --- Makefile.in | 8 +- build/bakefiles/files.bkl | 6 ++ build/cmake/files.cmake | 6 ++ build/files | 10 ++- include/wx/qt/private/treeitemfactory.h | 100 ++++++++++++++++++++++++ src/qt/listctrl.cpp | 99 +---------------------- 6 files changed, 129 insertions(+), 100 deletions(-) create mode 100644 include/wx/qt/private/treeitemfactory.h diff --git a/Makefile.in b/Makefile.in index 4d55a924fa..2afb48ef2a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3576,7 +3576,13 @@ COND_TOOLKIT_QT_GUI_HDR = \ wx/qt/dataview.h \ wx/qt/dvrenderers.h \ $(QT_PLATFORM_HDR) \ - wx/qt/treectrl.h + wx/qt/treectrl.h \ + wx/qt/private/winevent.h \ + wx/qt/private/converter.h \ + wx/qt/private/treeitemfactory.h \ + wx/qt/private/pointer.h \ + wx/qt/private/timer.h \ + wx/qt/private/utils.h @COND_TOOLKIT_QT@GUI_HDR = $(COND_TOOLKIT_QT_GUI_HDR) @COND_TOOLKIT_COCOA@MEDIA_PLATFORM_HDR = @COND_TOOLKIT_GTK@MEDIA_PLATFORM_HDR = diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index d42f8d1621..f84b961111 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -362,6 +362,12 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/qt/dvrenderers.h $(QT_PLATFORM_HDR) wx/qt/treectrl.h + wx/qt/private/winevent.h + wx/qt/private/converter.h + wx/qt/private/treeitemfactory.h + wx/qt/private/pointer.h + wx/qt/private/timer.h + wx/qt/private/utils.h diff --git a/build/cmake/files.cmake b/build/cmake/files.cmake index 5d7319af7e..799d7e5b6c 100644 --- a/build/cmake/files.cmake +++ b/build/cmake/files.cmake @@ -277,6 +277,12 @@ set(QT_HDR wx/generic/activityindicator.h ${QT_PLATFORM_HDR} wx/qt/treectrl.h + wx/qt/private/converter.h + wx/qt/private/winevent.h + wx/qt/private/timer.h + wx/qt/private/pointer.h + wx/qt/private/treeitemfactory.h + wx/qt/private/utils.h ) set(QT_SRC diff --git a/build/files b/build/files index fbadb0eb71..9c6e4966d0 100644 --- a/build/files +++ b/build/files @@ -298,7 +298,15 @@ QT_HDR = wx/qt/tooltip.h wx/qt/toplevel.h wx/qt/treectrl.h - wx/qt/window.h + wx/qt/window.h + wx/qt/private/converter.h + wx/qt/private/winevent.h + wx/qt/private/winevent.h + wx/qt/private/converter.h + wx/qt/private/pointer.h + wx/qt/private/timer.h + wx/qt/private/treeitemfactory.h + wx/qt/private/utils.h QT_SRC= $(QT_PLATFORM_SRC) diff --git a/include/wx/qt/private/treeitemfactory.h b/include/wx/qt/private/treeitemfactory.h new file mode 100644 index 0000000000..c2c91c34fa --- /dev/null +++ b/include/wx/qt/private/treeitemfactory.h @@ -0,0 +1,100 @@ +#ifndef _WX_TREEITEM_FACTORY_H_ +#define _WX_TREEITEM_FACTORY_H_ + +#include + +#include "wx/recguard.h" +#include "wx/textctrl.h" + +// wxQT Doesn't have a mechanism for "adopting" external widgets so we have to +// create an instance of wxTextCtrl rather than adopting the control QT would +// create. +// +// Unfortunately the factory is given an internal widget as the parent for +// editor. +// +// To work around these issues we create a wxTextCtl parented by the wxListCtrl +// then recalculate its position relative to the internal widget. +class wxQtListTextCtrl : public wxTextCtrl +{ +public: + wxQtListTextCtrl(wxWindow* parent, QWidget* actualParent) + : wxTextCtrl(parent, wxID_ANY, wxEmptyString, + wxDefaultPosition, wxDefaultSize, + wxNO_BORDER), + m_actualParent(actualParent), + m_moving(0) + { + + Bind(wxEVT_MOVE, &wxQtListTextCtrl::onMove, this); + } + + void onMove(wxMoveEvent &event) + { + // QWidget::move generates a QMoveEvent so we need to guard against + // reentrant calls. + wxRecursionGuard guard(m_moving); + if (guard.IsInside()) + { + event.Skip(); + return; + } + + const QPoint eventPosition = wxQtConvertPoint(event.GetPosition()); + const QPoint globalPosition = m_actualParent->mapToGlobal(eventPosition); + + // For some reason this always gives us the offset from the header info + // the internal control. So we need to treat this as an offset rather + // than a position. + QWidget* widget = GetHandle(); + const QPoint offset = widget->mapFromGlobal(globalPosition); + + widget->move(eventPosition + offset); + } + +private: + QWidget* m_actualParent; + wxRecursionGuardFlag m_moving; + + wxDECLARE_NO_COPY_CLASS(wxQtListTextCtrl); +}; + +// QT doesn't give us direct access to the editor within the QTreeWidget. +// Instead, we'll supply a factory to create the widget for QT and keep track +// of it ourselves. +class wxQtTreeItemEditorFactory : public QItemEditorFactory +{ +public: + explicit wxQtTreeItemEditorFactory(wxWindow* parent) + : m_parent(parent), + m_textCtrl(NULL) + { + } + + QWidget* createEditor(int WXUNUSED(userType), QWidget* parent) const wxOVERRIDE + { + m_textCtrl = new wxQtListTextCtrl(m_parent, parent); + m_textCtrl->SetFocus(); + return m_textCtrl->GetHandle(); + } + + wxTextCtrl* GetEditControl() + { + return m_textCtrl; + } + + void ClearEditor() + { + delete m_textCtrl; + m_textCtrl = NULL; + } + +private: + wxWindow* m_parent; + mutable wxTextCtrl* m_textCtrl; + + wxDECLARE_NO_COPY_CLASS(wxQtTreeItemEditorFactory); +}; + +#endif //_WX_TREEITEM_FACTORY_H_ + diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index 5209a5db7e..e6bbb4d8a2 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #ifndef WX_PRECOMP #include "wx/bitmap.h" @@ -23,105 +22,9 @@ #include "wx/listctrl.h" #include "wx/imaglist.h" -#include "wx/recguard.h" #include "wx/qt/private/winevent.h" - -namespace -{ - -// wxQT Doesn't have a mechanism for "adopting" external widgets so we have to -// create an instance of wxTextCtrl rather than adopting the control QT would -// create. -// -// Unfortunately the factory is given an internal widget as the parent for -// editor. -// -// To work around these issues we create a wxTextCtl parented by the wxListCtrl -// then recalculate its position relative to the internal widget. -class wxQtListTextCtrl : public wxTextCtrl -{ -public: - wxQtListTextCtrl(wxWindow* parent, QWidget* actualParent) - : wxTextCtrl(parent, wxID_ANY, wxEmptyString, - wxDefaultPosition, wxDefaultSize, - wxNO_BORDER), - m_actualParent(actualParent), - m_moving(0) - { - - Bind(wxEVT_MOVE, &wxQtListTextCtrl::onMove, this); - } - - void onMove(wxMoveEvent &event) - { - // QWidget::move generates a QMoveEvent so we need to guard against - // reentrant calls. - wxRecursionGuard guard(m_moving); - if ( guard.IsInside() ) - { - event.Skip(); - return; - } - - const QPoint eventPosition = wxQtConvertPoint(event.GetPosition()); - const QPoint globalPosition = m_actualParent->mapToGlobal(eventPosition); - - // For some reason this always gives us the offset from the header info - // the internal control. So we need to treat this as an offset rather - // than a position. - QWidget* widget = GetHandle(); - const QPoint offset = widget->mapFromGlobal(globalPosition); - - widget->move(eventPosition + offset); - } - -private: - QWidget* m_actualParent; - wxRecursionGuardFlag m_moving; - - wxDECLARE_NO_COPY_CLASS(wxQtListTextCtrl); -}; - -} // anonymous namespace - - -// QT doesn't give us direct access to the editor within the QTreeWidget. -// Instead, we'll supply a factory to create the widget for QT and keep track -// of it ourselves. -class wxQtTreeItemEditorFactory : public QItemEditorFactory -{ -public: - explicit wxQtTreeItemEditorFactory(wxWindow* parent) - : m_parent(parent), - m_textCtrl(NULL) - { - } - - QWidget* createEditor(int WXUNUSED(userType), QWidget* parent) const wxOVERRIDE - { - m_textCtrl = new wxQtListTextCtrl(m_parent, parent); - m_textCtrl->SetFocus(); - return m_textCtrl->GetHandle(); - } - - wxTextCtrl* GetEditControl() - { - return m_textCtrl; - } - - void ClearEditor() - { - delete m_textCtrl; - m_textCtrl = NULL; - } - -private: - wxWindow* m_parent; - mutable wxTextCtrl* m_textCtrl; - - wxDECLARE_NO_COPY_CLASS(wxQtTreeItemEditorFactory); -}; +#include "wx/qt/private/treeitemfactory.h" class wxQtListTreeWidget : public wxQtEventSignalHandler< QTreeWidget, wxListCtrl > {