]> git.saurik.com Git - wxWidgets.git/commitdiff
sorting support for generic version (patch 1765087 from Bo)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 3 Aug 2007 11:47:42 +0000 (11:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 3 Aug 2007 11:47:42 +0000 (11:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47863 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp
src/generic/datavgen.cpp

index c2b915eb1f452d83b497a430fbf7f04b6ab17fed..ec832adb839c6d69cdf2403e768b262b52bd4676 100644 (file)
@@ -97,7 +97,7 @@ public:
     virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
     virtual bool Cleared() = 0;
     
-    virtual void Resort() { }
+    virtual void Resort() = 0;
 
     void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
     wxDataViewModel *GetOwner()             { return m_owner; }
index 5142ea28b4735d6963d0cf59630e3c2f673fccc1..1a7069c38ecb0fb10bbf3f29083c5b694d7ab526 100644 (file)
@@ -161,11 +161,11 @@ public:
     {
         MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
         wxDataViewItem parent( node->GetParent() );
-        node->GetParent()->GetChildren().Remove( node );
-        delete node;
         
         // notify control
         ItemDeleted( parent, item );
+        node->GetParent()->GetChildren().Remove( node );
+        delete node;
     }
     
     // override sorting to always sort branches ascendingly
index 54fb552de2e6d2e59c2fbc6ef36ea72870de3e1b..d021c5ba92807f527bc1a9420d70fa0b7e5facbd 100644 (file)
@@ -246,8 +246,8 @@ void wxDataViewIndexListModel::RowAppended()
 void wxDataViewIndexListModel::RowDeleted( unsigned int row )
 {
     wxDataViewItem item( m_hash[row] );
-    m_hash.RemoveAt( row );
     wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
+    m_hash.RemoveAt( row );
 }
 
 void wxDataViewIndexListModel::RowChanged( unsigned int row )
index 13ebc80740b870c6bd47edfe00b536e68b535eac..a054a591503898e7a8e1b5255921650a8e74fb8f 100644 (file)
@@ -347,6 +347,30 @@ public:
             parent->ChangeSubTreeCount(num);
     }
 
+    void Resort()
+    {
+        wxDataViewTreeNodes nds = nodes;
+        wxDataViewTreeLeaves lvs = leaves;
+        nodes.Empty();
+        leaves.Empty();
+               
+        int len = nds.GetCount();
+        if(len > 0)
+        {
+            for(int i = 0; i < len; i ++)
+                nodes.Add(nds[i]);
+            for(int i = 0; i < len; i ++)
+                nodes[i]->Resort();
+        }
+
+        len = lvs.GetCount();
+        if(len > 0)
+        {
+            for(int i = 0; i < len; i++)
+                leaves.Add(lvs[i]);
+        }
+    }
+
 private:
     wxDataViewTreeNode * parent;
     wxDataViewTreeNodes  nodes;
@@ -398,6 +422,8 @@ public:
     bool ItemChanged( const wxDataViewItem &item );
     bool ValueChanged( const wxDataViewItem &item, unsigned int col );
     bool Cleared();
+    void Resort()
+        { g_model = GetOwner()->GetModel(); m_root->Resort(); UpdateDisplay(); }
 
     void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
     wxDataViewCtrl *GetOwner() { return m_owner; }
@@ -528,6 +554,8 @@ public:
         { return m_mainWindow->ValueChanged( item, col ); }
     virtual bool Cleared()
         { return m_mainWindow->Cleared(); }
+    virtual void Resort()
+        { return m_mainWindow->Resort(); }
 
     wxDataViewMainWindow    *m_mainWindow;
 };
@@ -1149,6 +1177,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay()
     // add the updated array of columns to the header control
     unsigned int cols = GetOwner()->GetColumnCount();
     unsigned int added = 0;
+    wxDataViewModel * model = GetOwner()->GetModel();
     for (unsigned int i = 0; i < cols; i++)
     {
         wxDataViewColumn *col = GetColumn( i );
@@ -1282,6 +1311,30 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA
         case HDN_ITEMCLICK:
             {
                 unsigned int idx = GetColumnIdxFromHeader(nmHDR);
+                wxDataViewModel * model = GetOwner()->GetModel();
+
+                if(nmHDR->iButton == 0)
+                {
+                    wxDataViewColumn *col = GetColumn(idx);
+                    if(col->IsSortable())
+                    {
+                        if(model && model->GetSortingColumn() == idx)
+                        {
+                            bool order = col->IsSortOrderAscending();
+                            col->SetSortOrder(!order);
+                            model->SetSortOrderAscending(!order);
+                        }
+                        else if(model)
+                        {
+                            model->SetSortingColumn(idx);
+                            model->SetSortOrderAscending(true);
+                        }
+                    }
+                    UpdateDisplay();
+                    if(model)
+                        model->Resort();
+                }
+
                 wxEventType evt = nmHDR->iButton == 0 ?
                         wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
                         wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
@@ -1923,8 +1976,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
     g_model = GetOwner()->GetModel();
 
     wxDataViewTreeNode * node;
-    wxDataViewItem parent_item = g_model->GetParent( item );
-    node = FindNode(parent_item);
+    node = FindNode(parent);
 
     if( node == NULL || node->GetChildren().Index( item.GetID() ) == wxNOT_FOUND )
     {