Clean up file.

This commit is contained in:
Jay Nabonne
2019-02-08 10:57:08 +00:00
parent 99e7da303e
commit b7ff45799c

View File

@@ -1,3 +1,13 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/treeitemfactory.h
// Purpose: Factory to create text edit controls for the tree items
// Author: Graham Dawes
// Modified by:
// Created: 02/2019
// Copyright: Graham Dawes
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TREEITEM_FACTORY_H_ #ifndef _WX_TREEITEM_FACTORY_H_
#define _WX_TREEITEM_FACTORY_H_ #define _WX_TREEITEM_FACTORY_H_
@@ -17,6 +27,7 @@
// //
// To work around these issues we create a wxTextCtl parented by the wxListCtrl // To work around these issues we create a wxTextCtl parented by the wxListCtrl
// then recalculate its position relative to the internal widget. // then recalculate its position relative to the internal widget.
class wxQtListTextCtrl : public wxTextCtrl class wxQtListTextCtrl : public wxTextCtrl
{ {
public: public:
@@ -27,7 +38,6 @@ public:
m_actualParent(actualParent), m_actualParent(actualParent),
m_moving(0) m_moving(0)
{ {
Bind(wxEVT_MOVE, &wxQtListTextCtrl::onMove, this); Bind(wxEVT_MOVE, &wxQtListTextCtrl::onMove, this);
} }
@@ -36,22 +46,23 @@ public:
// QWidget::move generates a QMoveEvent so we need to guard against // QWidget::move generates a QMoveEvent so we need to guard against
// reentrant calls. // reentrant calls.
wxRecursionGuard guard(m_moving); wxRecursionGuard guard(m_moving);
if (guard.IsInside())
if ( guard.IsInside() )
{ {
event.Skip(); event.Skip();
return; return;
} }
const QPoint eventPosition = wxQtConvertPoint(event.GetPosition()); const QPoint eventPos = wxQtConvertPoint(event.GetPosition());
const QPoint globalPosition = m_actualParent->mapToGlobal(eventPosition); const QPoint globalPos = m_actualParent->mapToGlobal(eventPos);
// For some reason this always gives us the offset from the header info // 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 // the internal control. So we need to treat this as an offset rather
// than a position. // than a position.
QWidget* widget = GetHandle(); QWidget* widget = GetHandle();
const QPoint offset = widget->mapFromGlobal(globalPosition); const QPoint offset = widget->mapFromGlobal(globalPos);
widget->move(eventPosition + offset); widget->move(eventPos + offset);
} }
private: private:
@@ -64,29 +75,34 @@ private:
// QT doesn't give us direct access to the editor within the QTreeWidget. // 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 // Instead, we'll supply a factory to create the widget for QT and keep track
// of it ourselves. // of it ourselves.
class wxQtTreeItemEditorFactory : public QItemEditorFactory class wxQtTreeItemEditorFactory : public QItemEditorFactory
{ {
public: public:
explicit wxQtTreeItemEditorFactory(wxWindow* parent) explicit wxQtTreeItemEditorFactory(wxWindow* parent)
: m_parent(parent), : m_parent(parent),
m_textCtrl(NULL) m_textCtrl(NULL)
{ {
} }
void AttachTo(QTreeWidget *tree) void AttachTo(QTreeWidget *tree)
{ {
QItemDelegate *qItemDelegate = static_cast<QItemDelegate*>(tree->itemDelegate()); QAbstractItemDelegate* delegate = tree->itemDelegate();
QItemDelegate *qItemDelegate = static_cast<QItemDelegate*>(delegate);
qItemDelegate->setItemEditorFactory(this); qItemDelegate->setItemEditorFactory(this);
} }
QWidget* createEditor(int WXUNUSED(userType), QWidget* parent) const wxOVERRIDE virtual QWidget* createEditor(
int WXUNUSED(userType),
QWidget* parent
) const wxOVERRIDE
{ {
m_textCtrl = new wxQtListTextCtrl(m_parent, parent); m_textCtrl = new wxQtListTextCtrl(m_parent, parent);
m_textCtrl->SetFocus(); m_textCtrl->SetFocus();
return m_textCtrl->GetHandle(); return m_textCtrl->GetHandle();
} }
wxTextCtrl* GetEditControl() wxTextCtrl* GetEditControl() const
{ {
return m_textCtrl; return m_textCtrl;
} }
@@ -105,4 +121,3 @@ private:
}; };
#endif //_WX_TREEITEM_FACTORY_H_ #endif //_WX_TREEITEM_FACTORY_H_