Skip to content

Commit

Permalink
Use shared_ptr for (virtual) list control data
Browse files Browse the repository at this point in the history
Blake-Madden committed Mar 23, 2024
1 parent d5ccb2e commit f425708
Showing 5 changed files with 28 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/ui/controls/listctrlex.h
Original file line number Diff line number Diff line change
@@ -724,12 +724,12 @@ class ListCtrlEx final : public wxListView

/// @brief Sets the underlying data provider for a virtual list control.
/// @param dataProvider The data provider for the list control.
void SetVirtualDataProvider(ListCtrlExDataProviderBase* dataProvider) noexcept
void SetVirtualDataProvider(std::shared_ptr<ListCtrlExDataProviderBase> dataProvider) noexcept
{ m_virtualData = dataProvider; }

/// @returns The underlying data provider for a virtual list control.
[[nodiscard]]
const ListCtrlExDataProviderBase* GetVirtualDataProvider() const noexcept
const std::shared_ptr<ListCtrlExDataProviderBase>& GetVirtualDataProvider()
{ return m_virtualData; }

/// @brief Sets whether clicking the list can be sorted.
@@ -1085,7 +1085,7 @@ class ListCtrlEx final : public wxListView

Wisteria::Canvas::Watermark m_waterMark;

ListCtrlExDataProviderBase* m_virtualData{ nullptr };
std::shared_ptr<ListCtrlExDataProviderBase> m_virtualData{ nullptr };
wxMenu* m_menu{ nullptr };
wxPrintData* m_printData{ nullptr };

15 changes: 7 additions & 8 deletions src/ui/dialogs/filelistdlg.h
Original file line number Diff line number Diff line change
@@ -38,10 +38,10 @@ class FileListDlg final : public Wisteria::UI::DialogWithHelp
explicit FileListDlg(wxWindow* parent, wxWindowID id = wxID_ANY,
const wxString& caption = _(L"File List"),
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE|wxCLIP_CHILDREN|wxRESIZE_BORDER)
long style = wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN | wxRESIZE_BORDER)
{
SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS|wxWS_EX_CONTEXTHELP);
Wisteria::UI::DialogWithHelp::Create( parent, id, caption, pos, size, style );
SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS | wxWS_EX_CONTEXTHELP);
Wisteria::UI::DialogWithHelp::Create(parent, id, caption, pos, size, style);

CreateControls();
Centre();
@@ -50,17 +50,15 @@ class FileListDlg final : public Wisteria::UI::DialogWithHelp
FileListDlg(const FileListDlg& that) = delete;
/// @private
FileListDlg& operator=(const FileListDlg& that) = delete;
/// @private
~FileListDlg()
{ wxDELETE(m_fileData); }

/// @returns Access to the file list control, which should be filled before calling ShowModal().
[[nodiscard]]
ListCtrlEx* GetListCtrl() noexcept
{ return m_listCtrl; }
/// @returns Access to the file list control's backend data provider,
/// which should be filled before calling ShowModal().
[[nodiscard]]
ListCtrlExNumericDataProvider* GetListCtrlData() noexcept
const std::shared_ptr<ListCtrlExNumericDataProvider>& GetListCtrlData()
{ return m_fileData; }
/// @returns Access to a descriptive infobar shown when the dialog is presented.
[[nodiscard]]
@@ -73,7 +71,8 @@ class FileListDlg final : public Wisteria::UI::DialogWithHelp
static constexpr int ID_FOLDER_OPEN = wxID_HIGHEST;

ListCtrlEx* m_listCtrl{ nullptr };
ListCtrlExNumericDataProvider* m_fileData{ new ListCtrlExNumericDataProvider };
std::shared_ptr<ListCtrlExNumericDataProvider> m_fileData
{ std::make_shared<ListCtrlExNumericDataProvider>() };
Wisteria::UI::Thumbnail* m_thumbnail{ nullptr };
wxStaticText* m_label{ nullptr };
wxInfoBar* m_infoBar{ nullptr };
12 changes: 5 additions & 7 deletions src/ui/dialogs/listctrlsortdlg.h
Original file line number Diff line number Diff line change
@@ -33,16 +33,13 @@ class ListCtrlSortDlg final : public Wisteria::UI::DialogWithHelp
ListCtrlSortDlg(wxWindow* parent, const wxArrayString& columnChoices,
wxWindowID id = wxID_ANY, const wxString& caption = _(L"Sort Columns"),
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) :
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) :
m_columnChoices(columnChoices)
{ Create(parent, id, caption, pos, size, style); }
/// @private
ListCtrlSortDlg(const ListCtrlSortDlg& that) = delete;
/// @private
ListCtrlSortDlg& operator=(const ListCtrlSortDlg& that) = delete;
/// @private
~ListCtrlSortDlg()
{ wxDELETE(m_data); }

/// @brief Sets the column sorting information.
/// @param sortColumns The columns to sort by.
@@ -56,9 +53,9 @@ class ListCtrlSortDlg final : public Wisteria::UI::DialogWithHelp
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
const wxString& caption = _(L"Sort Columns"),
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
Wisteria::UI::DialogWithHelp::Create(parent, id, caption, pos, size, style);

CreateControls();
@@ -76,7 +73,8 @@ class ListCtrlSortDlg final : public Wisteria::UI::DialogWithHelp

wxArrayString m_columnChoices;
ListCtrlEx* m_columnList{ nullptr };
ListCtrlExNumericDataProvider* m_data{ new ListCtrlExNumericDataProvider() };
std::shared_ptr<ListCtrlExNumericDataProvider> m_data
{ std::make_shared<ListCtrlExNumericDataProvider>() };
};

/** @}*/
20 changes: 10 additions & 10 deletions src/ui/dialogs/listdlg.h
Original file line number Diff line number Diff line change
@@ -111,16 +111,14 @@ class ListDlg final : public wxDialog
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize(600, 250),
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
/// @private
ListDlg(const ListDlg&) = delete;
/// @private
ListDlg& operator=(const ListDlg&) = delete;
/// @private
~ListDlg()
{ wxDELETE(m_data); }
/// @returns The list's data provider.
/// @private
ListDlg(const ListDlg&) = delete;
/// @private
ListDlg& operator=(const ListDlg&) = delete;

/// @returns The list's data provider.
[[nodiscard]]
ListCtrlExDataProvider* GetData() noexcept
std::shared_ptr<ListCtrlExDataProvider>& GetData()
{ return m_data; }
/// @returns The list.
[[nodiscard]]
@@ -166,7 +164,9 @@ class ListDlg final : public wxDialog
wxCommandEvent event;
OnReadLog(event);
}

private:

void BindEvents();
/// Creates the controls and sizers
void CreateControls();
@@ -201,7 +201,7 @@ class ListDlg final : public wxDialog
bool m_dontShowAgain{ false };
ListCtrlEx* m_list{ nullptr };
wxCheckListBox* m_checkList{ nullptr };
ListCtrlExDataProvider* m_data{ new ListCtrlExDataProvider() };
std::shared_ptr<ListCtrlExDataProvider> m_data{ std::make_shared<ListCtrlExDataProvider>() };
LogFile* m_logFile{ nullptr };
wxCheckBox* m_checkBox{ nullptr };
wxRibbonBar* m_ribbon{ nullptr };
6 changes: 3 additions & 3 deletions tests/gui-tests/listctrlextests.cpp
Original file line number Diff line number Diff line change
@@ -584,7 +584,7 @@ TEST_CASE("ListCtrlExDataProvider", "[listctrlexdataprovider]")

TEST_CASE("ListCtrlEx to LaTeX", "[listctrlex]")
{
auto m_dataProvider = new ListCtrlExNumericDataProvider;
auto m_dataProvider = std::make_shared<ListCtrlExNumericDataProvider>();
auto m_list = new ListCtrlEx(wxTheApp->GetTopWindow(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_VIRTUAL | wxLC_REPORT | wxBORDER_SUNKEN);
m_list->Hide();

@@ -797,7 +797,7 @@ text \\

TEST_CASE("ListCtrlEx", "[listctrlex]")
{
auto m_dataProvider = new ListCtrlExNumericDataProvider;
auto m_dataProvider = std::make_shared<LListCtrlExNumericDataProvider>();
auto m_list = new ListCtrlEx(wxTheApp->GetTopWindow(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_VIRTUAL | wxLC_REPORT | wxBORDER_SUNKEN);
m_list->Hide();

@@ -1506,4 +1506,4 @@ TEST_CASE("ListCtrlEx", "[listctrlex]")
}

wxDELETE(m_dataProvider);
}
}

0 comments on commit f425708

Please sign in to comment.