Implment tree node walker
This commit is contained in:
parent
f5acf47a19
commit
cef1674ce4
6 changed files with 187 additions and 1 deletions
|
@ -148,6 +148,8 @@
|
|||
916B7E941CC151FA00811097 /* race.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999C00EC62181008DD061 /* race.cpp */; };
|
||||
9176FECE1D59745F006EF694 /* unit_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9176FECD1D59745E006EF694 /* unit_list.cpp */; };
|
||||
9176FECF1D59745F006EF694 /* unit_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9176FECD1D59745E006EF694 /* unit_list.cpp */; };
|
||||
917746C11D680C7C00E8689A /* walker_tree_node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 917746BF1D680C7C00E8689A /* walker_tree_node.cpp */; };
|
||||
917746C21D680C7C00E8689A /* walker_tree_node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 917746BF1D680C7C00E8689A /* walker_tree_node.cpp */; };
|
||||
918438611D503E4000C42277 /* unit_recall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9184385F1D503E4000C42277 /* unit_recall.cpp */; };
|
||||
918438621D503E5300C42277 /* unit_recall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9184385F1D503E4000C42277 /* unit_recall.cpp */; };
|
||||
918C8A1E1D05F9AA009744A0 /* chat_command_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 918C8A161D05F9AA009744A0 /* chat_command_handler.cpp */; };
|
||||
|
@ -1568,6 +1570,8 @@
|
|||
914F2F851D35253900A42440 /* location_palette.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = location_palette.hpp; sourceTree = "<group>"; };
|
||||
9176FECD1D59745E006EF694 /* unit_list.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unit_list.cpp; sourceTree = "<group>"; };
|
||||
9176FED01D59747F006EF694 /* unit_list.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = unit_list.hpp; sourceTree = "<group>"; };
|
||||
917746BF1D680C7C00E8689A /* walker_tree_node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = walker_tree_node.cpp; path = iterator/walker_tree_node.cpp; sourceTree = "<group>"; };
|
||||
917746C01D680C7C00E8689A /* walker_tree_node.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = walker_tree_node.hpp; path = iterator/walker_tree_node.hpp; sourceTree = "<group>"; };
|
||||
918056BE1CB1E4C0001A7F35 /* functional.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = functional.hpp; sourceTree = "<group>"; };
|
||||
9184385C1D4C786F00C42277 /* game_version.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = game_version.hpp; sourceTree = "<group>"; };
|
||||
9184385F1D503E4000C42277 /* unit_recall.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unit_recall.cpp; sourceTree = "<group>"; };
|
||||
|
@ -3219,6 +3223,8 @@
|
|||
62579C741573E535003089D5 /* walker.hpp */,
|
||||
49DA0D2C13550E9B000AFEBD /* walker_grid.cpp */,
|
||||
62579C721573E535003089D5 /* walker_grid.hpp */,
|
||||
917746BF1D680C7C00E8689A /* walker_tree_node.cpp */,
|
||||
917746C01D680C7C00E8689A /* walker_tree_node.hpp */,
|
||||
49DA0D2D13550E9B000AFEBD /* walker_widget.cpp */,
|
||||
62579C731573E535003089D5 /* walker_widget.hpp */,
|
||||
);
|
||||
|
@ -5230,6 +5236,7 @@
|
|||
9193FC751D5A62FA004F6C07 /* unit_advance.cpp in Sources */,
|
||||
9193FC791D5AC2D8004F6C07 /* game_stats.cpp in Sources */,
|
||||
9193FC7E1D5BB64F004F6C07 /* advancement.cpp in Sources */,
|
||||
917746C11D680C7C00E8689A /* walker_tree_node.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -5801,6 +5808,7 @@
|
|||
9193FC7A1D5AC2D8004F6C07 /* game_stats.cpp in Sources */,
|
||||
9193FC7B1D5AE5B2004F6C07 /* name_generator_factory.cpp in Sources */,
|
||||
9193FC7F1D5BB64F004F6C07 /* advancement.cpp in Sources */,
|
||||
917746C21D680C7C00E8689A /* walker_tree_node.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -468,6 +468,7 @@ set(wesnoth-gui_iterator_SRC
|
|||
gui/auxiliary/iterator/iterator.cpp
|
||||
gui/auxiliary/iterator/walker_grid.cpp
|
||||
gui/auxiliary/iterator/walker_widget.cpp
|
||||
gui/auxiliary/iterator/walker_tree_node.cpp
|
||||
)
|
||||
|
||||
add_library(wesnoth-gui_iterator
|
||||
|
|
|
@ -337,6 +337,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/iterator/iterator.cpp
|
||||
gui/auxiliary/iterator/walker_grid.cpp
|
||||
gui/auxiliary/iterator/walker_widget.cpp
|
||||
gui/auxiliary/iterator/walker_tree_node.cpp
|
||||
gui/auxiliary/old_markup.cpp
|
||||
gui/core/canvas.cpp
|
||||
gui/core/event/dispatcher.cpp
|
||||
|
|
99
src/gui/auxiliary/iterator/walker_tree_node.cpp
Normal file
99
src/gui/auxiliary/iterator/walker_tree_node.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
Copyright (C) 2011 - 2016 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/iterator/walker_tree_node.hpp"
|
||||
#include "gui/widgets/tree_view_node.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
ttree_node::ttree_node(gui2::ttree_view_node& node, boost::ptr_vector<gui2::ttree_view_node>& children)
|
||||
: children_(children), widget_(&node), itor_(children.begin())
|
||||
{
|
||||
}
|
||||
|
||||
twalker_::tstate ttree_node::next(const tlevel level)
|
||||
{
|
||||
if(at_end(level)) {
|
||||
return fail;
|
||||
}
|
||||
|
||||
switch(level) {
|
||||
case widget:
|
||||
if(widget_) {
|
||||
widget_ = nullptr;
|
||||
return invalid;
|
||||
} else {
|
||||
/* FALL DOWN */
|
||||
}
|
||||
case grid:
|
||||
assert(false);
|
||||
return fail;
|
||||
case child:
|
||||
if(itor_ == children_.end()) {
|
||||
/* FALL DOWN */
|
||||
} else {
|
||||
++itor_;
|
||||
return itor_ == children_.end() ? invalid : valid;
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return fail;
|
||||
}
|
||||
|
||||
bool ttree_node::at_end(const tlevel level) const
|
||||
{
|
||||
switch(level) {
|
||||
case widget:
|
||||
return widget_ == nullptr;
|
||||
case grid:
|
||||
return true;
|
||||
case child:
|
||||
return (itor_ == children_.end());
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
gui2::twidget* ttree_node::get(const tlevel level)
|
||||
{
|
||||
switch(level) {
|
||||
case widget:
|
||||
return widget_;
|
||||
case grid:
|
||||
return nullptr;
|
||||
case child:
|
||||
if(itor_ == children_.end()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return itor_.operator->();
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace iterator
|
||||
|
||||
} // namespace gui2
|
76
src/gui/auxiliary/iterator/walker_tree_node.hpp
Normal file
76
src/gui/auxiliary/iterator/walker_tree_node.hpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright (C) 2011 - 2016 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_WIDGETS_AUXILIARY_WALKER_VISITOR_GRID_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_AUXILIARY_WALKER_VISITOR_GRID_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/iterator/walker.hpp"
|
||||
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class ttree_view_node;
|
||||
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
/** A walker for a @ref gui2::ttree_view_node. */
|
||||
class ttree_node : public twalker_
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param node The tree view node which the walker is attached to.
|
||||
* @param children The node's children.
|
||||
*/
|
||||
ttree_node(gui2::ttree_view_node& node, boost::ptr_vector<gui2::ttree_view_node>& children);
|
||||
|
||||
/** Inherited from @ref gui2::iterator::twalker_. */
|
||||
virtual tstate next(const tlevel level);
|
||||
|
||||
/** Inherited from @ref gui2::iterator::twalker_. */
|
||||
virtual bool at_end(const tlevel level) const;
|
||||
|
||||
/** Inherited from @ref gui2::iterator::twalker_. */
|
||||
virtual gui2::twidget* get(const tlevel level);
|
||||
|
||||
private:
|
||||
/** The children of the node which the walker is attached to. */
|
||||
boost::ptr_vector<gui2::ttree_view_node>& children_;
|
||||
|
||||
/**
|
||||
* The node which the walker is attached to.
|
||||
*
|
||||
* This variable is used to track whether the @ref
|
||||
* gui2::iterator::twalker_::widget level has been visited.
|
||||
*/
|
||||
gui2::twidget* widget_;
|
||||
|
||||
/**
|
||||
* The iterator to the children of @ref node_.
|
||||
*
|
||||
* This variable is used to track where the @ref
|
||||
* gui2::iterator::twalker_::child level visiting is.
|
||||
*/
|
||||
boost::ptr_vector<gui2::ttree_view_node>::iterator itor_;
|
||||
};
|
||||
|
||||
} // namespace iterator
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "gui/widgets/widget.hpp"
|
||||
#include "gui/widgets/grid.hpp"
|
||||
#include "gui/auxiliary/iterator/walker_tree_node.hpp"
|
||||
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
|
||||
|
@ -137,7 +138,7 @@ public:
|
|||
*/
|
||||
virtual iterator::twalker_* create_walker() override
|
||||
{
|
||||
return nullptr;
|
||||
return new gui2::iterator::ttree_node(*this, children_);
|
||||
}
|
||||
|
||||
/** See @ref twidget::find_at. */
|
||||
|
|
Loading…
Add table
Reference in a new issue