Add EditControl support for wxTreeCtrl under wxQT
This commit is contained in:
parent
cfe36f7ae7
commit
57348b4a59
@ -2,6 +2,8 @@
|
||||
#define _WX_TREEITEM_FACTORY_H_
|
||||
|
||||
#include <QtWidgets/QItemEditorFactory>
|
||||
#include <QtWidgets/QTreeWidget>
|
||||
#include <QtWidgets/QItemDelegate>
|
||||
|
||||
#include "wx/recguard.h"
|
||||
#include "wx/textctrl.h"
|
||||
@ -71,6 +73,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void AttachTo(QTreeWidget *tree)
|
||||
{
|
||||
QItemDelegate *qItemDelegate = static_cast<QItemDelegate*>(tree->itemDelegate());
|
||||
qItemDelegate->setItemEditorFactory(this);
|
||||
}
|
||||
|
||||
QWidget* createEditor(int WXUNUSED(userType), QWidget* parent) const wxOVERRIDE
|
||||
{
|
||||
m_textCtrl = new wxQtListTextCtrl(m_parent, parent);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#ifndef _WX_QT_TREECTRL_H_
|
||||
#define _WX_QT_TREECTRL_H_
|
||||
|
||||
class QTreeWidget;
|
||||
class wxQTreeWidget;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxTreeCtrl : public wxTreeCtrlBase
|
||||
{
|
||||
@ -140,7 +140,7 @@ private:
|
||||
void SendDeleteEvent(const wxTreeItemId &item);
|
||||
wxTreeItemId GetNext(const wxTreeItemId &item) const;
|
||||
|
||||
QTreeWidget *m_qtTreeWidget;
|
||||
wxQTreeWidget *m_qtTreeWidget;
|
||||
wxDECLARE_DYNAMIC_CLASS(wxTreeCtrl);
|
||||
};
|
||||
|
||||
|
@ -8,9 +8,11 @@
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
#include "wx/treectrl.h"
|
||||
#include "wx/qt/private/winevent.h"
|
||||
#include "wx/imaglist.h"
|
||||
|
||||
#include "wx/qt/private/winevent.h"
|
||||
#include "wx/qt/private/treeitemfactory.h"
|
||||
|
||||
#include <QtWidgets/QTreeWidget>
|
||||
|
||||
namespace
|
||||
@ -25,17 +27,53 @@ namespace
|
||||
return wxTreeItemId(item);
|
||||
}
|
||||
|
||||
size_t CountChildren(QTreeWidgetItem *item)
|
||||
{
|
||||
const int currentCount = item->childCount();
|
||||
size_t totalCount = currentCount;
|
||||
|
||||
for (int i = 0; i < currentCount; ++i)
|
||||
{
|
||||
totalCount += CountChildren(item->child(i));
|
||||
}
|
||||
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
QIcon::Mode TreeIconToQIconMode(wxTreeItemIcon icon)
|
||||
{
|
||||
switch (icon)
|
||||
{
|
||||
case wxTreeItemIcon_Normal:
|
||||
return QIcon::Normal;
|
||||
case wxTreeItemIcon_Selected:
|
||||
return QIcon::Selected;
|
||||
}
|
||||
|
||||
wxFAIL_MSG("Unspported tree icon state");
|
||||
return QIcon::Normal;
|
||||
}
|
||||
}
|
||||
|
||||
class wxQTreeWidget : public wxQtEventSignalHandler<QTreeWidget, wxTreeCtrl>
|
||||
{
|
||||
public:
|
||||
wxQTreeWidget(wxWindow *parent, wxTreeCtrl *handler) :
|
||||
wxQtEventSignalHandler(parent, handler)
|
||||
wxQtEventSignalHandler(parent, handler),
|
||||
m_editorFactory(handler)
|
||||
{
|
||||
connect(this, &QTreeWidget::currentItemChanged, this, &wxQTreeWidget::OnCurrentItemChanged);
|
||||
connect(this, &QTreeWidget::itemActivated, this, &wxQTreeWidget::OnItemActivated);
|
||||
connect(this, &QTreeWidget::itemClicked, this, &wxQTreeWidget::OnItemClicked);
|
||||
connect(this, &QTreeWidget::itemCollapsed, this, &wxQTreeWidget::OnItemCollapsed);
|
||||
connect(this, &QTreeWidget::itemExpanded, this, &wxQTreeWidget::OnItemExpanded);
|
||||
|
||||
m_editorFactory.AttachTo(this);
|
||||
}
|
||||
|
||||
wxTextCtrl *GetEditControl()
|
||||
{
|
||||
return m_editorFactory.GetEditControl();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -112,38 +150,10 @@ namespace
|
||||
EmitEvent(expandedEvent);
|
||||
|
||||
}
|
||||
|
||||
wxQtTreeItemEditorFactory m_editorFactory;
|
||||
};
|
||||
|
||||
|
||||
size_t CountChildren(QTreeWidgetItem *item)
|
||||
{
|
||||
const int currentCount = item->childCount();
|
||||
size_t totalCount = currentCount;
|
||||
|
||||
for(int i = 0; i < currentCount; ++i)
|
||||
{
|
||||
totalCount += CountChildren(item->child(i));
|
||||
}
|
||||
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
QIcon::Mode TreeIconToQIconMode(wxTreeItemIcon icon)
|
||||
{
|
||||
switch (icon)
|
||||
{
|
||||
case wxTreeItemIcon_Normal:
|
||||
return QIcon::Normal;
|
||||
case wxTreeItemIcon_Selected:
|
||||
return QIcon::Selected;
|
||||
}
|
||||
|
||||
wxFAIL_MSG("Unspported tree icon state");
|
||||
return QIcon::Normal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wxTreeCtrl::wxTreeCtrl() :
|
||||
m_qtTreeWidget(NULL)
|
||||
{
|
||||
@ -772,17 +782,22 @@ void wxTreeCtrl::ScrollTo(const wxTreeItemId& item)
|
||||
wxTextCtrl *wxTreeCtrl::EditLabel(const wxTreeItemId& item, wxClassInfo* textCtrlClass)
|
||||
{
|
||||
wxCHECK_MSG(item.IsOk(), NULL, "invalid tree item");
|
||||
return NULL;
|
||||
|
||||
QTreeWidgetItem *qTreeItem = wxQtConvertTreeItem(item);
|
||||
m_qtTreeWidget->openPersistentEditor(qTreeItem);
|
||||
return m_qtTreeWidget->GetEditControl();
|
||||
}
|
||||
|
||||
wxTextCtrl *wxTreeCtrl::GetEditControl() const
|
||||
{
|
||||
return NULL;
|
||||
return m_qtTreeWidget->GetEditControl();
|
||||
}
|
||||
|
||||
void wxTreeCtrl::EndEditLabel(const wxTreeItemId& item, bool discardChanges)
|
||||
{
|
||||
wxCHECK_RET(item.IsOk(), "invalid tree item");
|
||||
QTreeWidgetItem *qTreeItem = wxQtConvertTreeItem(item);
|
||||
m_qtTreeWidget->closePersistentEditor(qTreeItem);
|
||||
}
|
||||
|
||||
void wxTreeCtrl::SortChildren(const wxTreeItemId& item)
|
||||
|
Loading…
Reference in New Issue
Block a user