Load GUI from XML
This commit is contained in:
44
View.cc
44
View.cc
@@ -17,7 +17,7 @@ void View::addChild(std::unique_ptr<Widget> child)
|
||||
layout();
|
||||
}
|
||||
|
||||
Widget& View::getChildByName(std::string name)
|
||||
Widget& View::getChildByName(std::string const& name)
|
||||
{
|
||||
if (name == "")
|
||||
throw ChildNotFoundException{};
|
||||
@@ -30,7 +30,7 @@ Widget& View::getChildByName(std::string name)
|
||||
throw ChildNotFoundException{};
|
||||
}
|
||||
|
||||
Widget const& View::getChildByName(std::string name) const
|
||||
Widget const& View::getChildByName(std::string const& name) const
|
||||
{
|
||||
if (name == "")
|
||||
throw ChildNotFoundException{};
|
||||
@@ -43,7 +43,45 @@ Widget const& View::getChildByName(std::string name) const
|
||||
throw ChildNotFoundException{};
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> View::removeChild(std::string name)
|
||||
Widget& View::getPath(std::string const& path)
|
||||
{
|
||||
auto slash = path.find('/');
|
||||
|
||||
// Last path element
|
||||
if (slash == std::string::npos)
|
||||
return getChildByName(path);
|
||||
|
||||
auto first = path.substr(0, slash);
|
||||
auto& child = getChildByName(first);
|
||||
try {
|
||||
View& next = dynamic_cast<View&>(child);
|
||||
|
||||
return next.getPath(path.substr(slash+1));
|
||||
} catch(std::bad_cast &ex) {
|
||||
throw ChildNotFoundException{};
|
||||
}
|
||||
}
|
||||
|
||||
Widget const& View::getPath(std::string const& path) const
|
||||
{
|
||||
auto slash = path.find('/');
|
||||
|
||||
// Last path element
|
||||
if (slash == std::string::npos)
|
||||
return getChildByName(path);
|
||||
|
||||
auto first = path.substr(0, slash);
|
||||
auto& child = getChildByName(first);
|
||||
try {
|
||||
View const& next = dynamic_cast<View const&>(child);
|
||||
|
||||
return next.getPath(path.substr(slash+1));
|
||||
} catch(std::bad_cast &ex) {
|
||||
throw ChildNotFoundException{};
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> View::removeChild(std::string const& name)
|
||||
{
|
||||
if (name == "")
|
||||
throw ChildNotFoundException{};
|
||||
|
||||
Reference in New Issue
Block a user