Merge branch 'qt_tree_control' of https://github.com/GeoTeric/wxWidgets into qt-fixes
See https://github.com/wxWidgets/wxWidgets/pull/1225
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QTreeWidget>
|
||||
#include <QtWidgets/QItemDelegate>
|
||||
#include <QtWidgets/QItemEditorFactory>
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/bitmap.h"
|
||||
@@ -23,110 +22,14 @@
|
||||
|
||||
#include "wx/listctrl.h"
|
||||
#include "wx/imaglist.h"
|
||||
#include "wx/recguard.h"
|
||||
|
||||
#include "wx/qt/private/winevent.h"
|
||||
#include "wx/qt/private/treeitemfactory.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
|
||||
class wxQtListTreeWidget : public wxQtEventSignalHandler< QTreeWidget, wxListCtrl >
|
||||
{
|
||||
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 wxQtItemEditorFactory : public QItemEditorFactory
|
||||
{
|
||||
public:
|
||||
explicit wxQtItemEditorFactory(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(wxQtItemEditorFactory);
|
||||
};
|
||||
|
||||
class wxQtTreeWidget : public wxQtEventSignalHandler< QTreeWidget, wxListCtrl >
|
||||
{
|
||||
public:
|
||||
wxQtTreeWidget( wxWindow *parent, wxListCtrl *handler );
|
||||
wxQtListTreeWidget( wxWindow *parent, wxListCtrl *handler );
|
||||
|
||||
void EmitListEvent(wxEventType typ, QTreeWidgetItem *qitem, int column) const;
|
||||
|
||||
@@ -153,21 +56,21 @@ private:
|
||||
qItemDelegate->setItemEditorFactory(&m_editorFactory);
|
||||
}
|
||||
|
||||
wxQtItemEditorFactory m_editorFactory;
|
||||
wxQtTreeItemEditorFactory m_editorFactory;
|
||||
};
|
||||
|
||||
wxQtTreeWidget::wxQtTreeWidget( wxWindow *parent, wxListCtrl *handler )
|
||||
wxQtListTreeWidget::wxQtListTreeWidget( wxWindow *parent, wxListCtrl *handler )
|
||||
: wxQtEventSignalHandler< QTreeWidget, wxListCtrl >( parent, handler ),
|
||||
m_editorFactory(handler)
|
||||
{
|
||||
connect(this, &QTreeWidget::itemClicked, this, &wxQtTreeWidget::itemClicked);
|
||||
connect(this, &QTreeWidget::itemPressed, this, &wxQtTreeWidget::itemPressed);
|
||||
connect(this, &QTreeWidget::itemActivated, this, &wxQtTreeWidget::itemActivated);
|
||||
connect(this, &QTreeWidget::itemClicked, this, &wxQtListTreeWidget::itemClicked);
|
||||
connect(this, &QTreeWidget::itemPressed, this, &wxQtListTreeWidget::itemPressed);
|
||||
connect(this, &QTreeWidget::itemActivated, this, &wxQtListTreeWidget::itemActivated);
|
||||
|
||||
ChangeEditorFactory();
|
||||
}
|
||||
|
||||
void wxQtTreeWidget::EmitListEvent(wxEventType typ, QTreeWidgetItem *qitem, int column) const
|
||||
void wxQtListTreeWidget::EmitListEvent(wxEventType typ, QTreeWidgetItem *qitem, int column) const
|
||||
{
|
||||
wxListCtrl *handler = GetHandler();
|
||||
if ( handler )
|
||||
@@ -187,17 +90,17 @@ void wxQtTreeWidget::EmitListEvent(wxEventType typ, QTreeWidgetItem *qitem, int
|
||||
}
|
||||
}
|
||||
|
||||
void wxQtTreeWidget::itemClicked(QTreeWidgetItem *qitem, int column)
|
||||
void wxQtListTreeWidget::itemClicked(QTreeWidgetItem *qitem, int column)
|
||||
{
|
||||
EmitListEvent(wxEVT_LIST_ITEM_SELECTED, qitem, column);
|
||||
}
|
||||
|
||||
void wxQtTreeWidget::itemPressed(QTreeWidgetItem *qitem, int column)
|
||||
void wxQtListTreeWidget::itemPressed(QTreeWidgetItem *qitem, int column)
|
||||
{
|
||||
EmitListEvent(wxEVT_LIST_ITEM_SELECTED, qitem, column);
|
||||
}
|
||||
|
||||
void wxQtTreeWidget::itemActivated(QTreeWidgetItem *qitem, int column)
|
||||
void wxQtListTreeWidget::itemActivated(QTreeWidgetItem *qitem, int column)
|
||||
{
|
||||
EmitListEvent(wxEVT_LIST_ITEM_ACTIVATED, qitem, column);
|
||||
}
|
||||
@@ -258,7 +161,7 @@ bool wxListCtrl::Create(wxWindow *parent,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
m_qtTreeWidget = new wxQtTreeWidget( parent, this );
|
||||
m_qtTreeWidget = new wxQtListTreeWidget( parent, this );
|
||||
|
||||
if (style & wxLC_NO_HEADER)
|
||||
m_qtTreeWidget->setHeaderHidden(true);
|
||||
|
||||
Reference in New Issue
Block a user