Code review changes

This commit is contained in:
Matthew Griffin
2019-06-04 10:29:17 +01:00
parent 12c8741704
commit 9bb9bf5718
4 changed files with 32 additions and 29 deletions

View File

@@ -7,8 +7,8 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TREEITEM_DELEGATE_H #ifndef _WX_QT_PRIVATE_TREEITEM_DELEGATE_H
#define _WX_TREEITEM_DELEGATE_H #define _WX_QT_PRIVATE_TREEITEM_DELEGATE_H
#include <QtWidgets/QStyledItemDelegate> #include <QtWidgets/QStyledItemDelegate>
@@ -28,7 +28,10 @@ public:
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &WXUNUSED(option), const QModelIndex &index) const wxOVERRIDE QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &WXUNUSED(option), const QModelIndex &index) const wxOVERRIDE
{ {
m_current_model_index = index; if ( m_textCtrl != NULL )
destroyEditor(m_textCtrl->GetHandle(), m_currentModelIndex);
m_currentModelIndex = index;
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();
@@ -36,9 +39,9 @@ public:
void destroyEditor(QWidget *WXUNUSED(editor), const QModelIndex &WXUNUSED(index)) const wxOVERRIDE void destroyEditor(QWidget *WXUNUSED(editor), const QModelIndex &WXUNUSED(index)) const wxOVERRIDE
{ {
if (!wxTheApp->IsScheduledForDestruction(m_textCtrl)) if ( m_textCtrl != NULL )
{ {
m_current_model_index = QModelIndex(); m_currentModelIndex = QModelIndex(); // invalidate the index
wxTheApp->ScheduleForDestruction(m_textCtrl); wxTheApp->ScheduleForDestruction(m_textCtrl);
m_textCtrl = NULL; m_textCtrl = NULL;
} }
@@ -56,7 +59,7 @@ public:
QModelIndex GetCurrentModelIndex() const QModelIndex GetCurrentModelIndex() const
{ {
return m_current_model_index; return m_currentModelIndex;
} }
void AcceptModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void AcceptModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
@@ -67,7 +70,7 @@ public:
private: private:
wxWindow* m_parent; wxWindow* m_parent;
mutable wxTextCtrl* m_textCtrl; mutable wxTextCtrl* m_textCtrl;
mutable QModelIndex m_current_model_index; mutable QModelIndex m_currentModelIndex;
}; };
#endif // _WX_TREEITEM_DELEGATE_H #endif // _WX_QT_PRIVATE_TREEITEM_DELEGATE_H

View File

@@ -7,8 +7,8 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TREEITEM_FACTORY_H_ #ifndef _WX_QT_PRIVATE_TREEITEM_FACTORY_H_
#define _WX_TREEITEM_FACTORY_H_ #define _WX_QT_PRIVATE_TREEITEM_FACTORY_H_
#include <QtWidgets/QItemEditorFactory> #include <QtWidgets/QItemEditorFactory>
#include <QtWidgets/QTreeWidget> #include <QtWidgets/QTreeWidget>
@@ -91,11 +91,11 @@ public:
qItemDelegate->setItemEditorFactory(this); qItemDelegate->setItemEditorFactory(this);
} }
virtual QWidget* createEditor( QWidget* createEditor(int WXUNUSED(userType), QWidget* parent) const wxOVERRIDE
int WXUNUSED(userType),
QWidget* parent
) const wxOVERRIDE
{ {
if (m_textCtrl != NULL)
ClearEditor();
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();
@@ -106,7 +106,7 @@ public:
return m_textCtrl; return m_textCtrl;
} }
void ClearEditor() void ClearEditor() const
{ {
delete m_textCtrl; delete m_textCtrl;
m_textCtrl = NULL; m_textCtrl = NULL;
@@ -119,4 +119,4 @@ private:
wxDECLARE_NO_COPY_CLASS(wxQtTreeItemEditorFactory); wxDECLARE_NO_COPY_CLASS(wxQtTreeItemEditorFactory);
}; };
#endif //_WX_TREEITEM_FACTORY_H_ #endif //_WX_QT_PRIVATE_TREEITEM_FACTORY_H_

View File

@@ -75,7 +75,6 @@ public:
virtual wxTreeItemId GetFocusedItem() const wxOVERRIDE; virtual wxTreeItemId GetFocusedItem() const wxOVERRIDE;
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const wxOVERRIDE; virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const wxOVERRIDE;
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const wxOVERRIDE; virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const wxOVERRIDE;
virtual wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const wxOVERRIDE; virtual wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const wxOVERRIDE;
virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const wxOVERRIDE; virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const wxOVERRIDE;

View File

@@ -16,6 +16,7 @@
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/settings.h" #include "wx/settings.h"
#include "wx/sharedptr.h" #include "wx/sharedptr.h"
#include "wx/withimages.h"
#include "wx/qt/private/winevent.h" #include "wx/qt/private/winevent.h"
#include "wx/qt/private/treeitemdelegate.h" #include "wx/qt/private/treeitemdelegate.h"
@@ -32,12 +33,13 @@ struct TreeItemDataQt
{ {
} }
TreeItemDataQt(wxTreeItemData* data) : data(data) explicit TreeItemDataQt(wxTreeItemData* data) : data(data)
{ {
if ( !registered ) static bool s_registered = false;
if ( !s_registered )
{ {
qRegisterMetaTypeStreamOperators<TreeItemDataQt>("TreeItemDataQt"); qRegisterMetaTypeStreamOperators<TreeItemDataQt>("TreeItemDataQt");
registered = true; s_registered = true;
} }
} }
@@ -46,13 +48,10 @@ struct TreeItemDataQt
return data.get(); return data.get();
} }
private: private:
wxSharedPtr<wxTreeItemData> data; wxSharedPtr<wxTreeItemData> data;
static bool registered;
}; };
bool TreeItemDataQt::registered = false;
QDataStream &operator<<(QDataStream &out, const TreeItemDataQt &WXUNUSED(obj)) QDataStream &operator<<(QDataStream &out, const TreeItemDataQt &WXUNUSED(obj))
{ {
return out; return out;
@@ -84,6 +83,7 @@ size_t CountChildren(QTreeWidgetItem *item)
return totalCount; return totalCount;
} }
class ImageState class ImageState
{ {
public: public:
@@ -91,7 +91,7 @@ public:
{ {
for ( int i = wxTreeItemIcon_Normal; i < wxTreeItemIcon_Max; ++i ) for ( int i = wxTreeItemIcon_Normal; i < wxTreeItemIcon_Max; ++i )
{ {
m_imageStates[i] = -1; m_imageStates[i] = wxWithImages::NO_IMAGE;
} }
} }
@@ -101,7 +101,7 @@ public:
return m_imageStates[index]; return m_imageStates[index];
} }
const int &operator[](size_t index) const int operator[](size_t index) const
{ {
wxASSERT(index < wxTreeItemIcon_Max); wxASSERT(index < wxTreeItemIcon_Max);
return m_imageStates[index]; return m_imageStates[index];
@@ -523,7 +523,7 @@ wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id,
const wxSize& size, const wxSize& size,
long style, long style,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
Create(parent, id, pos, size, style, validator, name); Create(parent, id, pos, size, style, validator, name);
} }
@@ -587,7 +587,7 @@ void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
wxString wxTreeCtrl::GetItemText(const wxTreeItemId& item) const wxString wxTreeCtrl::GetItemText(const wxTreeItemId& item) const
{ {
if ( !item.IsOk() ) if ( !item.IsOk() )
return ""; return wxString();
const QTreeWidgetItem* qTreeItem = wxQtConvertTreeItem(item); const QTreeWidgetItem* qTreeItem = wxQtConvertTreeItem(item);
return wxQtConvertString(qTreeItem->text(0)); return wxQtConvertString(qTreeItem->text(0));
@@ -816,10 +816,11 @@ size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds& selections) const
QList<QTreeWidgetItem*> qtSelections = m_qtTreeWidget->selectedItems(); QList<QTreeWidgetItem*> qtSelections = m_qtTreeWidget->selectedItems();
const size_t numberOfSelections = qtSelections.size(); const size_t numberOfSelections = qtSelections.size();
selections.reserve(numberOfSelections);
for ( size_t i = 0; i < numberOfSelections; ++i ) for ( size_t i = 0; i < numberOfSelections; ++i )
{ {
QTreeWidgetItem *item = qtSelections[i]; QTreeWidgetItem *item = qtSelections[i];
selections.Add(wxQtConvertTreeItem(item)); selections.push_back(wxQtConvertTreeItem(item));
} }
return numberOfSelections; return numberOfSelections;