//=====================================================================
int SQLiteTreeHandler::AddBranch( const AttributeMapType& attr )
{
- //std::cout << "AddBranch" << std::endl;
tree::Node* parent = DBGetParent(attr);
- //std::cout << " parent = "<<parent->GetLabel()<<" level "<<parent->GetLevel()<<std::endl;
DBGraftToParent(parent,attr);
-
+ if(parent->GetLevel()<GetTree().GetNumberOfLevels()-1&&parent->GetLevel()>0)
+ {
+ int nC=GetNumberOfChildren(parent);
+ nC=nC+1;
+ std::stringstream out;
+ out <<nC;
+ SetAttribute(parent,"D1111_0011",out.str());
+ }
return (parent->GetLevel()+1);
}
DBRecursiveRemoveNode(node);
// std::cout << "DELETE"<<std::endl;
- if (node->GetParent())
+ bool remove=false;
+ tree::Node* parent=node->GetParent();
+ if (parent)
{
- node->GetParent()->RemoveChildrenFromList(node);
+ parent->RemoveChildrenFromList(node);
+ int nC=GetNumberOfChildren(parent);
+ nC=nC-1;
+ if(nC>0)
+ {
+ std::stringstream out;
+ out <<nC;
+ SetAttribute(parent,"D1111_0011",out.str());
+ }
+ else
+ {
+ remove=true;
+ }
+
}
delete node;
+ if(remove&&parent->GetLevel()>0)
+ {
+ Remove(parent);
+ }
// std::cout << "DELETE OK"<<std::endl;
return true;
}
int nbloaded = 0;
// If children loaded we do not have to do it but we need to recurse
// in order to load the children's children if necessary, and so on...
- if (node->GetChildrenLoaded()||mIsAdding)
+ if (node->GetChildrenLoaded())
{
// Iterate the children
{
// Create Node
tree::Node* child = new tree::Node(parent,attr);
+ GetNumberOfChildren(parent);
child->SetChildrenLoaded(true);
// std::cout<<"Number of children "<<parent->GetNumberOfChildren()<<std::endl;
+
// Set PARENT_ID if necessary
if ( parent->GetLevel()>0 )
child->SetAttribute("PARENT_ID",parent->GetAttribute("ID"));
// Query DB
int nb=0;
int level = n->GetLevel();
- if(GetTree().GetNumberOfLevels()!=(level+1))
+
+ if(level<GetTree().GetNumberOfLevels()&& level>0)
{
- std::string query = "SELECT * FROM ";
- query += GetTree().GetLevelDescriptor(level+1).GetName();
+ std::string query = "SELECT D1111_0011 FROM ";
+ query += GetTree().GetLevelDescriptor(level).GetName();
if (level>0)
{
- query += " WHERE PARENT_ID='" + n->UnsafeGetAttribute("ID")
+ query += " WHERE ID='" + n->UnsafeGetAttribute("ID")
+ "'";
}
-
CppSQLite3Query q;
QUERYDB(query,q);
while (!q.eof())
{
- nb++;
+ for (int fld = 0; fld < q.numFields(); fld++)
+ {
+ nb=q.getIntField(fld);
+ }
q.nextRow();
}
}
+ if(nb==0){nb=1;}
return nb;
}
mProgressSignal(mProgress);
if (mProgress.GetStop()) break;
}
- SetNumberOfChildren();
}
//=====================================================================
{
mProgress.Reset();
AddDirectoryRecursor( directory, recurse );
- SetNumberOfChildren();
GimmickDebugMessage(3,mProgress<<std::endl);
}
- //=====================================================================
-
- void TreeHandlerImageAdder::SetNumberOfChildren()
- {
- std::vector<tree::Node*> children = mTreeHandler->GetTree().GetChildrenList();
- std::vector<tree::Node*>::iterator it;
- for(it=children.begin();it!=children.end();++it)
- {
- SetNumberOfChildrenRecursor(*it);
- }
- }
- //=====================================================================
-
- void TreeHandlerImageAdder::SetNumberOfChildrenRecursor(tree::Node* node)
- {
- std::stringstream out;
- out << node->GetChildrenList().size();
- mTreeHandler->SetAttribute(node,"D1111_0011",out.str());
- if(node->GetLevel()<mTreeHandler->GetTree().GetNumberOfLevels()-2)
- {
- std::vector<tree::Node*> children = node->GetChildrenList();
- std::vector<tree::Node*>::iterator it;
- for(it=children.begin();it!=children.end();++it)
- {
- SetNumberOfChildrenRecursor(*it);
- }
- }
- }
-
//=====================================================================
void TreeHandlerImageAdder::AddFile( const std::string& filename )
{
void AddDirectoryRecursor( const std::string& directory,
bool recurse );
- ///Sets the number of children for the tree
- void SetNumberOfChildren();
-
- ///Sets the number of children recursively for the given node
- void SetNumberOfChildrenRecursor(tree::Node* node);
-
-
TreeHandler* mTreeHandler;
ImageReader mReader;
virtual void UpdateLevel( int )
{ GimmickError("INTERNAL ERROR : TreeView::UpdateLevel not overloaded");}
- ///Removes selected nodes on given level
- virtual void RemoveSelected( int )
+ ///Removes selected nodes
+ virtual void RemoveSelected( )
{ GimmickError("INTERNAL ERROR : TreeView::RemoveSelected not overloaded");}
///Validates the selected images
{
//TODO Select current tree handler
wxBusyCursor busy;
- GetTreeViewMap()["Local database"]->RemoveSelected(1);
+ GetTreeViewMap()["Local database"]->RemoveSelected();
ClearSelection();
}
//=================================================
sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
mColumnSelected=1;
mLastSelected=0;
+ mLastLevel=0;
mDirection=true;
mSelectionMade=false;
mProcess=true;
//=====================================================================
- ///Removes selected nodes on given level
- void WxTreeView::RemoveSelected( int level )
+ ///Removes selected nodes on last selected level
+ void WxTreeView::RemoveSelected()
{
- std::vector<tree::Node*> sel=GetSelected(level+1);
+ mLastLevel+=1;
+ std::vector<tree::Node*> sel=GetSelected(mLastLevel+1);
bool erase=false;
- if (wxMessageBox(_T("Delete file(s) ?"),
+ std::stringstream out;
+ std::string levelName=GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName();
+ out<<"Delete ";
+ out<<sel.size();
+ if(sel.size()>1&&levelName.at(levelName.size()-1)!='s')
+ {
+ out<<" "<<levelName;
+ out<<"s?";
+ }
+ else
+ {
+ out<<" "<<GetTreeHandler()->GetTree().GetLevelDescriptor(mLastLevel).GetName()<<"?";
+ }
+ if (wxMessageBox(_T(out.str()),
_T("Remove Files"),
wxYES_NO,this ) == wxYES)
{
}
if(erase)
{
+ bool needRefresh=false;
std::vector<tree::Node*>::iterator i;
for (i=sel.begin(); i!=sel.end(); ++i)
{
- GimmickDebugMessage(2,
+ GimmickMessage(1,
"deleting '"
<<(*i)->GetLabel()
- <<"'"<<level
+ <<"'"<<mLastLevel
<<std::endl);
+ if((*i)->GetParent()->GetNumberOfChildren()<2)
+ {
+ needRefresh=true;
+ }
GetTreeHandler()->Remove(*i);
}
- UpdateLevel(level);
+ if(needRefresh && mLastLevel>1)
+ {
+ UpdateLevel(mLastLevel-2);
+ }
+ else if(mLastLevel>1)
+ {
+ UpdateLevel(mLastLevel-1);
+ }
+ else
+ {
+ UpdateLevel(mLastLevel);
+ }
}
}
{
if ( GetCtrl(level) == obj ) break;
}
+ mLastLevel=level;
GimmickDebugMessage(1,
" Level "<<level+1
<<std::endl);
// Update the children level (if selection not at last level)
if (level<mLevelList.size()-1)
{
+
UpdateLevel( level + 2 );
// Reset the viewer setting the default image
GetGimmickView()->ClearSelection();
item = GetCtrl(level)->GetNextItem(item,
wxLIST_NEXT_BELOW);
}
- if ( item == -1 )
+ if ( item == -1 || item==0 )
{
break;
}
- if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 /*&& item!=0*/)
+ if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 )
{
adr = GetCtrl(level)->GetItemData(item);
nod = ((ItemData*)adr)->node;
virtual void UpdateLevel( int );
///Removes selected nodes on given level
- virtual void RemoveSelected( int );
+ virtual void RemoveSelected();
/// Callback for selection change
void OnSelectedChanged(wxListEvent& event);
int mAscendingID;
int mDescendingID;
int mFilterID;
+ unsigned int mLastLevel;
DECLARE_EVENT_TABLE()
};