Upgraded object_control to use icons near the name
Renamed some classes Deleted unused classes
This commit is contained in:
parent
942a3340aa
commit
a91cb5b267
@ -677,11 +677,11 @@ void SliderCtrl::BUILD()
|
||||
|
||||
auto temp = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
auto default = static_cast<ConfigOptionInt*>(m_opt.default_value)->value;
|
||||
auto def_val = static_cast<ConfigOptionInt*>(m_opt.default_value)->value;
|
||||
auto min = m_opt.min == INT_MIN ? 0 : m_opt.min;
|
||||
auto max = m_opt.max == INT_MAX ? 100 : m_opt.max;
|
||||
|
||||
m_slider = new wxSlider(m_parent, wxID_ANY, default * m_scale,
|
||||
m_slider = new wxSlider(m_parent, wxID_ANY, def_val * m_scale,
|
||||
min * m_scale, max * m_scale,
|
||||
wxDefaultPosition, size);
|
||||
wxSize field_size(40, -1);
|
||||
|
@ -144,7 +144,7 @@ wxSizer *m_sizer_object_buttons = nullptr;
|
||||
wxSizer *m_sizer_part_buttons = nullptr;
|
||||
wxSizer *m_sizer_object_movers = nullptr;
|
||||
wxDataViewCtrl *m_objects_ctrl = nullptr;
|
||||
MyObjectTreeModel *m_objects_model = nullptr;
|
||||
PrusaObjectDataViewModel *m_objects_model = nullptr;
|
||||
wxCollapsiblePane *m_collpane_settings = nullptr;
|
||||
int m_event_object_selection_changed = 0;
|
||||
int m_event_object_settings_changed = 0;
|
||||
@ -815,7 +815,7 @@ unsigned get_colour_approx_luma(const wxColour &colour)
|
||||
wxDataViewCtrl* get_objects_ctrl() {
|
||||
return m_objects_ctrl;
|
||||
}
|
||||
MyObjectTreeModel* get_objects_model() {
|
||||
PrusaObjectDataViewModel* get_objects_model() {
|
||||
return m_objects_model;
|
||||
}
|
||||
|
||||
@ -925,36 +925,28 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
||||
{
|
||||
m_objects_ctrl = new wxDataViewCtrl(win, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
m_objects_ctrl->SetInitialSize(wxSize(-1, 150)); // TODO - Set correct height according to the opened/closed objects
|
||||
|
||||
auto objects_sz = new wxBoxSizer(wxVERTICAL);
|
||||
objects_sz->Add(m_objects_ctrl, 1, wxGROW | wxLEFT, 20);
|
||||
|
||||
m_objects_model = new MyObjectTreeModel;
|
||||
m_objects_model = new PrusaObjectDataViewModel;
|
||||
m_objects_ctrl->AssociateModel(m_objects_model);
|
||||
#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
||||
m_objects_ctrl->EnableDragSource(wxDF_UNICODETEXT);
|
||||
m_objects_ctrl->EnableDropTarget(wxDF_UNICODETEXT);
|
||||
#endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
||||
|
||||
// column 0 of the view control:
|
||||
|
||||
wxDataViewTextRenderer *tr = new wxDataViewTextRenderer("string", wxDATAVIEW_CELL_INERT);
|
||||
wxDataViewColumn *column00 = new wxDataViewColumn("Name", tr, 0, 110, wxALIGN_LEFT,
|
||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
m_objects_ctrl->AppendColumn(column00);
|
||||
// column 0(Icon+Text) of the view control:
|
||||
m_objects_ctrl->AppendIconTextColumn(_(L("Name")), 0, wxDATAVIEW_CELL_INERT, 150,
|
||||
wxALIGN_LEFT, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
|
||||
// column 1 of the view control:
|
||||
|
||||
tr = new wxDataViewTextRenderer("string", wxDATAVIEW_CELL_INERT);
|
||||
wxDataViewColumn *column01 = new wxDataViewColumn("Copy", tr, 1, 75, wxALIGN_CENTER_HORIZONTAL,
|
||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
m_objects_ctrl->AppendColumn(column01);
|
||||
m_objects_ctrl->AppendTextColumn(_(L("Copy")), 1, wxDATAVIEW_CELL_INERT, 65,
|
||||
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
|
||||
// column 2 of the view control:
|
||||
|
||||
tr = new wxDataViewTextRenderer("string", wxDATAVIEW_CELL_INERT);
|
||||
wxDataViewColumn *column02 = new wxDataViewColumn("Scale", tr, 2, 80, wxALIGN_CENTER_HORIZONTAL,
|
||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
m_objects_ctrl->AppendColumn(column02);
|
||||
m_objects_ctrl->AppendTextColumn(_(L("Scale")), 2, wxDATAVIEW_CELL_INERT, 70,
|
||||
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||
|
||||
m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& event)
|
||||
{
|
||||
@ -988,6 +980,7 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
||||
auto show_obj_sizer = m_objects_model->GetParent(item) == wxDataViewItem(0);
|
||||
m_sizer_object_buttons->Show(show_obj_sizer);
|
||||
m_sizer_part_buttons->Show(!show_obj_sizer);
|
||||
m_sizer_object_movers->Show(!show_obj_sizer);
|
||||
m_collpane_settings->SetLabelText((show_obj_sizer ? _(L("Object Settings")) : _(L("Part Settings"))) + ":");
|
||||
m_collpane_settings->Show(true);
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ class wxFileDialog;
|
||||
class wxStaticBitmap;
|
||||
class wxFont;
|
||||
class wxDataViewCtrl;
|
||||
class MyObjectTreeModel;
|
||||
class PrusaObjectDataViewModel;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@ -149,7 +149,7 @@ const wxFont& bold_font();
|
||||
void open_model(wxWindow *parent, wxArrayString& input_files);
|
||||
|
||||
wxDataViewCtrl* get_objects_ctrl ();
|
||||
MyObjectTreeModel* get_objects_model();
|
||||
PrusaObjectDataViewModel* get_objects_model();
|
||||
ModelObjectPtrs& get_objects();
|
||||
const int& get_event_object_settings_changed();
|
||||
wxFrame* get_main_frame();
|
||||
|
@ -2,11 +2,12 @@
|
||||
#include "GUI_ObjectParts.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
#include "LambdaObjectDialog.hpp"
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/frame.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "LambdaObjectDialog.hpp"
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
@ -130,8 +131,10 @@ void on_btn_load(wxWindow* parent, bool is_modifier /*= false*/, bool is_lambda/
|
||||
|
||||
parts_changed(obj_idx);
|
||||
|
||||
const std::string icon_name = is_modifier ? "plugin.png" : "package.png";
|
||||
auto icon = wxIcon(Slic3r::GUI::from_u8(Slic3r::var(icon_name)), wxBITMAP_TYPE_PNG);
|
||||
for (int i = 0; i < part_names.size(); ++i)
|
||||
objects_ctrl->Select(objects_model->AddChild(item, part_names.Item(i)));
|
||||
objects_ctrl->Select(objects_model->AddChild(item, part_names.Item(i), icon));
|
||||
}
|
||||
|
||||
void parts_changed(int obj_idx)
|
||||
|
@ -341,12 +341,12 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse)
|
||||
|
||||
// *****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyObjectTreeModel
|
||||
// PrusaObjectDataViewModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::Add(wxString &name)
|
||||
wxDataViewItem PrusaObjectDataViewModel::Add(wxString &name)
|
||||
{
|
||||
auto root = new MyObjectTreeModelNode(name);
|
||||
auto root = new PrusaObjectDataViewModelNode(name);
|
||||
m_objects.push_back(root);
|
||||
// notify control
|
||||
wxDataViewItem child((void*)root);
|
||||
@ -355,9 +355,9 @@ wxDataViewItem MyObjectTreeModel::Add(wxString &name)
|
||||
return child;
|
||||
}
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::Add(wxString &name, int instances_count, int scale)
|
||||
wxDataViewItem PrusaObjectDataViewModel::Add(wxString &name, int instances_count, int scale)
|
||||
{
|
||||
auto root = new MyObjectTreeModelNode(name, instances_count, scale);
|
||||
auto root = new PrusaObjectDataViewModelNode(name, instances_count, scale);
|
||||
m_objects.push_back(root);
|
||||
// notify control
|
||||
wxDataViewItem child((void*)root);
|
||||
@ -366,21 +366,24 @@ wxDataViewItem MyObjectTreeModel::Add(wxString &name, int instances_count, int s
|
||||
return child;
|
||||
}
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::AddChild(const wxDataViewItem &parent_item, wxString &name)
|
||||
wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_item,
|
||||
const wxString &name,
|
||||
const wxIcon& icon)
|
||||
{
|
||||
MyObjectTreeModelNode *root = (MyObjectTreeModelNode*)parent_item.GetID();
|
||||
PrusaObjectDataViewModelNode *root = (PrusaObjectDataViewModelNode*)parent_item.GetID();
|
||||
if (!root) return wxDataViewItem(0);
|
||||
|
||||
if (root->GetChildren().Count() == 0)
|
||||
{
|
||||
auto node = new MyObjectTreeModelNode(root, root->m_name);
|
||||
auto icon_solid_mesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG);
|
||||
auto node = new PrusaObjectDataViewModelNode(root, root->m_name, icon_solid_mesh);
|
||||
root->Append(node);
|
||||
// notify control
|
||||
wxDataViewItem child((void*)node);
|
||||
ItemAdded(parent_item, child);
|
||||
}
|
||||
|
||||
auto node = new MyObjectTreeModelNode(root, name);
|
||||
auto node = new PrusaObjectDataViewModelNode(root, name, icon);
|
||||
root->Append(node);
|
||||
// notify control
|
||||
wxDataViewItem child((void*)node);
|
||||
@ -388,10 +391,10 @@ wxDataViewItem MyObjectTreeModel::AddChild(const wxDataViewItem &parent_item, wx
|
||||
return child;
|
||||
}
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::Delete(const wxDataViewItem &item)
|
||||
wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item)
|
||||
{
|
||||
auto ret_item = wxDataViewItem(0);
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return ret_item;
|
||||
|
||||
@ -434,7 +437,7 @@ wxDataViewItem MyObjectTreeModel::Delete(const wxDataViewItem &item)
|
||||
return ret_item;
|
||||
}
|
||||
|
||||
void MyObjectTreeModel::DeleteAll()
|
||||
void PrusaObjectDataViewModel::DeleteAll()
|
||||
{
|
||||
while (!m_objects.empty())
|
||||
{
|
||||
@ -444,7 +447,7 @@ void MyObjectTreeModel::DeleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::GetItemById(int obj_idx)
|
||||
wxDataViewItem PrusaObjectDataViewModel::GetItemById(int obj_idx)
|
||||
{
|
||||
if (obj_idx >= m_objects.size())
|
||||
{
|
||||
@ -455,11 +458,11 @@ wxDataViewItem MyObjectTreeModel::GetItemById(int obj_idx)
|
||||
}
|
||||
|
||||
|
||||
int MyObjectTreeModel::GetIdByItem(wxDataViewItem& item)
|
||||
int PrusaObjectDataViewModel::GetIdByItem(wxDataViewItem& item)
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
auto it = find(m_objects.begin(), m_objects.end(), node);
|
||||
if (it == m_objects.end())
|
||||
return -1;
|
||||
@ -467,43 +470,44 @@ int MyObjectTreeModel::GetIdByItem(wxDataViewItem& item)
|
||||
return it - m_objects.begin();
|
||||
}
|
||||
|
||||
wxString MyObjectTreeModel::GetName(const wxDataViewItem &item) const
|
||||
wxString PrusaObjectDataViewModel::GetName(const wxDataViewItem &item) const
|
||||
{
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return wxEmptyString;
|
||||
|
||||
return node->m_name;
|
||||
}
|
||||
|
||||
wxString MyObjectTreeModel::GetCopy(const wxDataViewItem &item) const
|
||||
wxString PrusaObjectDataViewModel::GetCopy(const wxDataViewItem &item) const
|
||||
{
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return wxEmptyString;
|
||||
|
||||
return node->m_copy;
|
||||
}
|
||||
|
||||
wxString MyObjectTreeModel::GetScale(const wxDataViewItem &item) const
|
||||
wxString PrusaObjectDataViewModel::GetScale(const wxDataViewItem &item) const
|
||||
{
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return wxEmptyString;
|
||||
|
||||
return node->m_scale;
|
||||
}
|
||||
|
||||
void MyObjectTreeModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
|
||||
void PrusaObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
variant = node->m_name;
|
||||
break;
|
||||
case 0:{
|
||||
const wxDataViewIconText data(node->m_name, node->m_icon);
|
||||
variant << data;
|
||||
break;}
|
||||
case 1:
|
||||
variant = node->m_copy;
|
||||
break;
|
||||
@ -515,15 +519,15 @@ void MyObjectTreeModel::GetValue(wxVariant &variant, const wxDataViewItem &item,
|
||||
}
|
||||
}
|
||||
|
||||
bool MyObjectTreeModel::SetValue(const wxVariant &variant, const wxDataViewItem &item, unsigned int col)
|
||||
bool PrusaObjectDataViewModel::SetValue(const wxVariant &variant, const wxDataViewItem &item, unsigned int col)
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
return node->SetValue(variant, col);
|
||||
}
|
||||
|
||||
bool MyObjectTreeModel::SetValue(const wxVariant &variant, const int item_idx, unsigned int col)
|
||||
bool PrusaObjectDataViewModel::SetValue(const wxVariant &variant, const int item_idx, unsigned int col)
|
||||
{
|
||||
if (item_idx < 0 || item_idx >= m_objects.size())
|
||||
return false;
|
||||
@ -536,13 +540,13 @@ bool MyObjectTreeModel::SetValue(const wxVariant &variant, const int item_idx, u
|
||||
//
|
||||
// }
|
||||
|
||||
wxDataViewItem MyObjectTreeModel::GetParent(const wxDataViewItem &item) const
|
||||
wxDataViewItem PrusaObjectDataViewModel::GetParent(const wxDataViewItem &item) const
|
||||
{
|
||||
// the invisible root node has no parent
|
||||
if (!item.IsOk())
|
||||
return wxDataViewItem(0);
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
|
||||
// objects nodes has no parent too
|
||||
if (find(m_objects.begin(), m_objects.end(),node) != m_objects.end())
|
||||
@ -551,19 +555,19 @@ wxDataViewItem MyObjectTreeModel::GetParent(const wxDataViewItem &item) const
|
||||
return wxDataViewItem((void*)node->GetParent());
|
||||
}
|
||||
|
||||
bool MyObjectTreeModel::IsContainer(const wxDataViewItem &item) const
|
||||
bool PrusaObjectDataViewModel::IsContainer(const wxDataViewItem &item) const
|
||||
{
|
||||
// the invisible root node can have children
|
||||
if (!item.IsOk())
|
||||
return true;
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||
return node->IsContainer();
|
||||
}
|
||||
|
||||
unsigned int MyObjectTreeModel::GetChildren(const wxDataViewItem &parent, wxDataViewItemArray &array) const
|
||||
unsigned int PrusaObjectDataViewModel::GetChildren(const wxDataViewItem &parent, wxDataViewItemArray &array) const
|
||||
{
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)parent.GetID();
|
||||
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)parent.GetID();
|
||||
if (!node)
|
||||
{
|
||||
for (auto object : m_objects)
|
||||
@ -579,288 +583,7 @@ unsigned int MyObjectTreeModel::GetChildren(const wxDataViewItem &parent, wxData
|
||||
unsigned int count = node->GetChildren().GetCount();
|
||||
for (unsigned int pos = 0; pos < count; pos++)
|
||||
{
|
||||
MyObjectTreeModelNode *child = node->GetChildren().Item(pos);
|
||||
array.Add(wxDataViewItem((void*)child));
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyMusicTreeModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
MyMusicTreeModel::MyMusicTreeModel()
|
||||
{
|
||||
m_root = new MyMusicTreeModelNode(NULL, "");// , "My Music");
|
||||
|
||||
// setup pop music
|
||||
m_pop = new MyMusicTreeModelNode(m_root, "Pop music");
|
||||
m_pop->Append(
|
||||
new MyMusicTreeModelNode(m_pop, "You are not alone", "Michael Jackson", 1995));
|
||||
m_pop->Append(
|
||||
new MyMusicTreeModelNode(m_pop, "Take a bow", "Madonna", 1994));
|
||||
m_root->Append(m_pop);
|
||||
|
||||
// setup classical music
|
||||
m_classical = new MyMusicTreeModelNode(m_root, "Classical music");
|
||||
m_ninth = new MyMusicTreeModelNode(m_classical, "Ninth symphony",
|
||||
"Ludwig van Beethoven", 1824);
|
||||
m_classical->Append(m_ninth);
|
||||
m_classical->Append(new MyMusicTreeModelNode(m_classical, "German Requiem",
|
||||
"Johannes Brahms", 1868));
|
||||
m_root->Append(m_classical);
|
||||
|
||||
m_classicalMusicIsKnownToControl = false;
|
||||
}
|
||||
|
||||
wxString MyMusicTreeModel::GetTitle(const wxDataViewItem &item) const
|
||||
{
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return wxEmptyString;
|
||||
|
||||
return node->m_title;
|
||||
}
|
||||
|
||||
wxString MyMusicTreeModel::GetArtist(const wxDataViewItem &item) const
|
||||
{
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return wxEmptyString;
|
||||
|
||||
return node->m_artist;
|
||||
}
|
||||
|
||||
int MyMusicTreeModel::GetYear(const wxDataViewItem &item) const
|
||||
{
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return 2000;
|
||||
|
||||
return node->m_year;
|
||||
}
|
||||
|
||||
void MyMusicTreeModel::AddToClassical(const wxString &title, const wxString &artist,
|
||||
unsigned int year)
|
||||
{
|
||||
if (!m_classical)
|
||||
{
|
||||
wxASSERT(m_root);
|
||||
|
||||
// it was removed: restore it
|
||||
m_classical = new MyMusicTreeModelNode(m_root, "Classical music");
|
||||
m_root->Append(m_classical);
|
||||
|
||||
// notify control
|
||||
wxDataViewItem child((void*)m_classical);
|
||||
wxDataViewItem parent((void*)m_root);
|
||||
ItemAdded(parent, child);
|
||||
}
|
||||
|
||||
// add to the classical music node a new node:
|
||||
MyMusicTreeModelNode *child_node =
|
||||
new MyMusicTreeModelNode(m_classical, title, artist, year);
|
||||
m_classical->Append(child_node);
|
||||
|
||||
// FIXME: what's m_classicalMusicIsKnownToControl for?
|
||||
if (m_classicalMusicIsKnownToControl)
|
||||
{
|
||||
// notify control
|
||||
wxDataViewItem child((void*)child_node);
|
||||
wxDataViewItem parent((void*)m_classical);
|
||||
ItemAdded(parent, child);
|
||||
}
|
||||
}
|
||||
|
||||
void MyMusicTreeModel::Delete(const wxDataViewItem &item)
|
||||
{
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
if (!node) // happens if item.IsOk()==false
|
||||
return;
|
||||
|
||||
wxDataViewItem parent(node->GetParent());
|
||||
if (!parent.IsOk())
|
||||
{
|
||||
wxASSERT(node == m_root);
|
||||
|
||||
// don't make the control completely empty:
|
||||
//wxLogError("Cannot remove the root item!");
|
||||
return;
|
||||
}
|
||||
|
||||
// is the node one of those we keep stored in special pointers?
|
||||
if (node == m_pop)
|
||||
m_pop = NULL;
|
||||
else if (node == m_classical)
|
||||
m_classical = NULL;
|
||||
else if (node == m_ninth)
|
||||
m_ninth = NULL;
|
||||
|
||||
// first remove the node from the parent's array of children;
|
||||
// NOTE: MyMusicTreeModelNodePtrArray is only an array of _pointers_
|
||||
// thus removing the node from it doesn't result in freeing it
|
||||
node->GetParent()->GetChildren().Remove(node);
|
||||
|
||||
// free the node
|
||||
delete node;
|
||||
|
||||
// notify control
|
||||
ItemDeleted(parent, item);
|
||||
}
|
||||
|
||||
int MyMusicTreeModel::Compare(const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||
unsigned int column, bool ascending) const
|
||||
{
|
||||
wxASSERT(item1.IsOk() && item2.IsOk());
|
||||
// should never happen
|
||||
|
||||
if (IsContainer(item1) && IsContainer(item2))
|
||||
{
|
||||
wxVariant value1, value2;
|
||||
GetValue(value1, item1, 0);
|
||||
GetValue(value2, item2, 0);
|
||||
|
||||
wxString str1 = value1.GetString();
|
||||
wxString str2 = value2.GetString();
|
||||
int res = str1.Cmp(str2);
|
||||
if (res) return res;
|
||||
|
||||
// items must be different
|
||||
wxUIntPtr litem1 = (wxUIntPtr)item1.GetID();
|
||||
wxUIntPtr litem2 = (wxUIntPtr)item2.GetID();
|
||||
|
||||
return litem1 - litem2;
|
||||
}
|
||||
|
||||
return wxDataViewModel::Compare(item1, item2, column, ascending);
|
||||
}
|
||||
|
||||
void MyMusicTreeModel::GetValue(wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col) const
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
variant = node->m_title;
|
||||
break;
|
||||
case 1:
|
||||
variant = node->m_artist;
|
||||
break;
|
||||
case 2:
|
||||
variant = (long)node->m_year;
|
||||
break;
|
||||
case 3:
|
||||
variant = node->m_quality;
|
||||
break;
|
||||
case 4:
|
||||
variant = 80L; // all music is very 80% popular
|
||||
break;
|
||||
case 5:
|
||||
if (GetYear(item) < 1900)
|
||||
variant = "old";
|
||||
else
|
||||
variant = "new";
|
||||
break;
|
||||
|
||||
default:
|
||||
;// wxLogError("MyMusicTreeModel::GetValue: wrong column %d", col);
|
||||
}
|
||||
}
|
||||
|
||||
bool MyMusicTreeModel::SetValue(const wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col)
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
node->m_title = variant.GetString();
|
||||
return true;
|
||||
case 1:
|
||||
node->m_artist = variant.GetString();
|
||||
return true;
|
||||
case 2:
|
||||
node->m_year = variant.GetLong();
|
||||
return true;
|
||||
case 3:
|
||||
node->m_quality = variant.GetString();
|
||||
return true;
|
||||
|
||||
default:;
|
||||
// wxLogError("MyMusicTreeModel::SetValue: wrong column");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MyMusicTreeModel::IsEnabled(const wxDataViewItem &item,
|
||||
unsigned int col) const
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
|
||||
// disable Beethoven's ratings, his pieces can only be good
|
||||
return !(col == 3 && node->m_artist.EndsWith("Beethoven"));
|
||||
}
|
||||
|
||||
wxDataViewItem MyMusicTreeModel::GetParent(const wxDataViewItem &item) const
|
||||
{
|
||||
// the invisible root node has no parent
|
||||
if (!item.IsOk())
|
||||
return wxDataViewItem(0);
|
||||
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
|
||||
// "MyMusic" also has no parent
|
||||
if (node == m_root)
|
||||
return wxDataViewItem(0);
|
||||
|
||||
return wxDataViewItem((void*)node->GetParent());
|
||||
}
|
||||
|
||||
bool MyMusicTreeModel::IsContainer(const wxDataViewItem &item) const
|
||||
{
|
||||
// the invisble root node can have children
|
||||
// (in our model always "MyMusic")
|
||||
if (!item.IsOk())
|
||||
return true;
|
||||
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)item.GetID();
|
||||
return node->IsContainer();
|
||||
}
|
||||
|
||||
unsigned int MyMusicTreeModel::GetChildren(const wxDataViewItem &parent,
|
||||
wxDataViewItemArray &array) const
|
||||
{
|
||||
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*)parent.GetID();
|
||||
if (!node)
|
||||
{
|
||||
array.Add(wxDataViewItem((void*)m_root));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (node == m_classical)
|
||||
{
|
||||
MyMusicTreeModel *model = (MyMusicTreeModel*)(const MyMusicTreeModel*) this;
|
||||
model->m_classicalMusicIsKnownToControl = true;
|
||||
}
|
||||
|
||||
if (node->GetChildCount() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int count = node->GetChildren().GetCount();
|
||||
for (unsigned int pos = 0; pos < count; pos++)
|
||||
{
|
||||
MyMusicTreeModelNode *child = node->GetChildren().Item(pos);
|
||||
PrusaObjectDataViewModelNode *child = node->GetChildren().Item(pos);
|
||||
array.Add(wxDataViewItem((void*)child));
|
||||
}
|
||||
|
||||
|
@ -145,25 +145,25 @@ public:
|
||||
|
||||
// *****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyObjectTreeModelNode: a node inside MyObjectTreeModel
|
||||
// PrusaObjectDataViewModelNode: a node inside PrusaObjectDataViewModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MyObjectTreeModelNode;
|
||||
WX_DEFINE_ARRAY_PTR(MyObjectTreeModelNode*, MyObjectTreeModelNodePtrArray);
|
||||
class PrusaObjectDataViewModelNode;
|
||||
WX_DEFINE_ARRAY_PTR(PrusaObjectDataViewModelNode*, MyObjectTreeModelNodePtrArray);
|
||||
|
||||
class MyObjectTreeModelNode
|
||||
class PrusaObjectDataViewModelNode
|
||||
{
|
||||
MyObjectTreeModelNode* m_parent;
|
||||
PrusaObjectDataViewModelNode* m_parent;
|
||||
MyObjectTreeModelNodePtrArray m_children;
|
||||
public:
|
||||
MyObjectTreeModelNode(const wxString &name, int instances_count=1, int scale=100) {
|
||||
PrusaObjectDataViewModelNode(const wxString &name, int instances_count=1, int scale=100) {
|
||||
m_parent = NULL;
|
||||
m_name = name;
|
||||
m_copy = wxString::Format("%d", instances_count);
|
||||
m_scale = wxString::Format("%d%%", scale);
|
||||
}
|
||||
|
||||
MyObjectTreeModelNode( MyObjectTreeModelNode* parent,
|
||||
PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent,
|
||||
const wxString& sub_obj) {
|
||||
m_parent = parent;
|
||||
m_name = sub_obj;
|
||||
@ -171,18 +171,25 @@ public:
|
||||
m_scale = wxEmptyString;
|
||||
}
|
||||
|
||||
~MyObjectTreeModelNode()
|
||||
PrusaObjectDataViewModelNode(PrusaObjectDataViewModelNode* parent,
|
||||
const wxString& sub_obj, const wxIcon& icon):
|
||||
PrusaObjectDataViewModelNode(parent, sub_obj){
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
~PrusaObjectDataViewModelNode()
|
||||
{
|
||||
// free all our children nodes
|
||||
size_t count = m_children.GetCount();
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
MyObjectTreeModelNode *child = m_children[i];
|
||||
PrusaObjectDataViewModelNode *child = m_children[i];
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
|
||||
wxString m_name;
|
||||
wxIcon m_icon;
|
||||
wxString m_copy;
|
||||
wxString m_scale;
|
||||
bool m_container = false;
|
||||
@ -192,7 +199,7 @@ public:
|
||||
return m_container;
|
||||
}
|
||||
|
||||
MyObjectTreeModelNode* GetParent()
|
||||
PrusaObjectDataViewModelNode* GetParent()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
@ -200,15 +207,15 @@ public:
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
MyObjectTreeModelNode* GetNthChild(unsigned int n)
|
||||
PrusaObjectDataViewModelNode* GetNthChild(unsigned int n)
|
||||
{
|
||||
return m_children.Item(n);
|
||||
}
|
||||
void Insert(MyObjectTreeModelNode* child, unsigned int n)
|
||||
void Insert(PrusaObjectDataViewModelNode* child, unsigned int n)
|
||||
{
|
||||
m_children.Insert(child, n);
|
||||
}
|
||||
void Append(MyObjectTreeModelNode* child)
|
||||
void Append(PrusaObjectDataViewModelNode* child)
|
||||
{
|
||||
if (!m_container)
|
||||
m_container = true;
|
||||
@ -237,33 +244,39 @@ public:
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
m_name = variant.GetString();
|
||||
return true;
|
||||
case 0:{
|
||||
wxDataViewIconText data;
|
||||
data << variant;
|
||||
m_icon = data.GetIcon();
|
||||
m_name = data.GetText();
|
||||
return true;}
|
||||
case 1:
|
||||
m_copy = variant.GetString();
|
||||
return true;
|
||||
case 2:
|
||||
m_scale = variant.GetString();
|
||||
return true;
|
||||
|
||||
default:
|
||||
printf("MyObjectTreeModel::SetValue: wrong column");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void SetIcon(const wxIcon &icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyObjectTreeModel
|
||||
// PrusaObjectDataViewModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MyObjectTreeModel :public wxDataViewModel
|
||||
class PrusaObjectDataViewModel :public wxDataViewModel
|
||||
{
|
||||
std::vector<MyObjectTreeModelNode*> m_objects;
|
||||
std::vector<PrusaObjectDataViewModelNode*> m_objects;
|
||||
public:
|
||||
MyObjectTreeModel(){}
|
||||
~MyObjectTreeModel()
|
||||
PrusaObjectDataViewModel(){}
|
||||
~PrusaObjectDataViewModel()
|
||||
{
|
||||
for (auto object : m_objects)
|
||||
delete object;
|
||||
@ -271,7 +284,9 @@ public:
|
||||
|
||||
wxDataViewItem Add(wxString &name);
|
||||
wxDataViewItem Add(wxString &name, int instances_count, int scale);
|
||||
wxDataViewItem AddChild(const wxDataViewItem &parent_item, wxString &name);
|
||||
wxDataViewItem AddChild(const wxDataViewItem &parent_item,
|
||||
const wxString &name,
|
||||
const wxIcon& icon);
|
||||
wxDataViewItem Delete(const wxDataViewItem &item);
|
||||
void DeleteAll();
|
||||
wxDataViewItem GetItemById(int obj_idx);
|
||||
@ -310,197 +325,6 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyMusicTreeModelNode: a node inside MyMusicTreeModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MyMusicTreeModelNode;
|
||||
WX_DEFINE_ARRAY_PTR(MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray);
|
||||
|
||||
class MyMusicTreeModelNode
|
||||
{
|
||||
public:
|
||||
MyMusicTreeModelNode(MyMusicTreeModelNode* parent,
|
||||
const wxString &title, const wxString &artist,
|
||||
unsigned int year)
|
||||
{
|
||||
m_parent = parent;
|
||||
|
||||
m_title = title;
|
||||
m_artist = artist;
|
||||
m_year = year;
|
||||
m_quality = "good";
|
||||
|
||||
m_container = false;
|
||||
}
|
||||
|
||||
MyMusicTreeModelNode(MyMusicTreeModelNode* parent,
|
||||
const wxString &branch)
|
||||
{
|
||||
m_parent = parent;
|
||||
|
||||
m_title = branch;
|
||||
m_year = -1;
|
||||
|
||||
m_container = true;
|
||||
}
|
||||
|
||||
~MyMusicTreeModelNode()
|
||||
{
|
||||
// free all our children nodes
|
||||
size_t count = m_children.GetCount();
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
MyMusicTreeModelNode *child = m_children[i];
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsContainer() const
|
||||
{
|
||||
return m_container;
|
||||
}
|
||||
|
||||
MyMusicTreeModelNode* GetParent()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
MyMusicTreeModelNodePtrArray& GetChildren()
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
MyMusicTreeModelNode* GetNthChild(unsigned int n)
|
||||
{
|
||||
return m_children.Item(n);
|
||||
}
|
||||
void Insert(MyMusicTreeModelNode* child, unsigned int n)
|
||||
{
|
||||
m_children.Insert(child, n);
|
||||
}
|
||||
void Append(MyMusicTreeModelNode* child)
|
||||
{
|
||||
m_children.Add(child);
|
||||
}
|
||||
unsigned int GetChildCount() const
|
||||
{
|
||||
return m_children.GetCount();
|
||||
}
|
||||
|
||||
public: // public to avoid getters/setters
|
||||
wxString m_title;
|
||||
wxString m_artist;
|
||||
int m_year;
|
||||
wxString m_quality;
|
||||
|
||||
// TODO/FIXME:
|
||||
// the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
|
||||
// needs to know in advance if a node is or _will be_ a container.
|
||||
// Thus implementing:
|
||||
// bool IsContainer() const
|
||||
// { return m_children.GetCount()>0; }
|
||||
// doesn't work with wxGTK when MyMusicTreeModel::AddToClassical is called
|
||||
// AND the classical node was removed (a new node temporary without children
|
||||
// would be added to the control)
|
||||
bool m_container;
|
||||
|
||||
private:
|
||||
MyMusicTreeModelNode *m_parent;
|
||||
MyMusicTreeModelNodePtrArray m_children;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyMusicTreeModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Implement this data model
|
||||
Title Artist Year Judgement
|
||||
--------------------------------------------------------------------------
|
||||
1: My Music:
|
||||
2: Pop music
|
||||
3: You are not alone Michael Jackson 1995 good
|
||||
4: Take a bow Madonna 1994 good
|
||||
5: Classical music
|
||||
6: Ninth Symphony Ludwig v. Beethoven 1824 good
|
||||
7: German Requiem Johannes Brahms 1868 good
|
||||
*/
|
||||
|
||||
class MyMusicTreeModel : public wxDataViewModel
|
||||
{
|
||||
public:
|
||||
MyMusicTreeModel();
|
||||
~MyMusicTreeModel()
|
||||
{
|
||||
if (m_root)
|
||||
delete m_root;
|
||||
|
||||
}
|
||||
|
||||
// helper method for wxLog
|
||||
|
||||
wxString GetTitle(const wxDataViewItem &item) const;
|
||||
wxString GetArtist(const wxDataViewItem &item) const;
|
||||
int GetYear(const wxDataViewItem &item) const;
|
||||
|
||||
// helper methods to change the model
|
||||
|
||||
void AddToClassical(const wxString &title, const wxString &artist,
|
||||
unsigned int year);
|
||||
void Delete(const wxDataViewItem &item);
|
||||
|
||||
wxDataViewItem GetNinthItem() const
|
||||
{
|
||||
return wxDataViewItem(m_ninth);
|
||||
}
|
||||
|
||||
// override sorting to always sort branches ascendingly
|
||||
|
||||
int Compare(const wxDataViewItem &item1, const wxDataViewItem &item2,
|
||||
unsigned int column, bool ascending) const override/*wxOVERRIDE*/;
|
||||
|
||||
// implementation of base class virtuals to define model
|
||||
|
||||
virtual unsigned int GetColumnCount() const override/*wxOVERRIDE*/
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
virtual wxString GetColumnType(unsigned int col) const override/*wxOVERRIDE*/
|
||||
{
|
||||
if (col == 2)
|
||||
return wxT("long");
|
||||
|
||||
return wxT("string");
|
||||
}
|
||||
|
||||
virtual void GetValue(wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col) const override/*wxOVERRIDE*/;
|
||||
virtual bool SetValue(const wxVariant &variant,
|
||||
const wxDataViewItem &item, unsigned int col) override/*wxOVERRIDE*/;
|
||||
|
||||
virtual bool IsEnabled(const wxDataViewItem &item,
|
||||
unsigned int col) const override/*wxOVERRIDE*/;
|
||||
|
||||
virtual wxDataViewItem GetParent(const wxDataViewItem &item) const override/*wxOVERRIDE*/;
|
||||
virtual bool IsContainer(const wxDataViewItem &item) const override/*wxOVERRIDE*/;
|
||||
virtual unsigned int GetChildren(const wxDataViewItem &parent,
|
||||
wxDataViewItemArray &array) const override/*wxOVERRIDE*/;
|
||||
|
||||
private:
|
||||
MyMusicTreeModelNode* m_root;
|
||||
|
||||
// pointers to some "special" nodes of the tree:
|
||||
MyMusicTreeModelNode* m_pop;
|
||||
MyMusicTreeModelNode* m_classical;
|
||||
MyMusicTreeModelNode* m_ninth;
|
||||
|
||||
// ??
|
||||
bool m_classicalMusicIsKnownToControl;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyCustomRenderer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user