TreeViewApplication.C 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include <Wt/WApplication>
  7. #include <Wt/WText>
  8. #include "TreeViewExample.h"
  9. using namespace Wt;
  10. class TreeViewApplication: public WApplication
  11. {
  12. public:
  13. TreeViewApplication(const WEnvironment &env):
  14. WApplication(env)
  15. {
  16. WStandardItemModel *model = TreeViewExample::createModel(true, this);
  17. root()->addWidget
  18. (new TreeViewExample(model, WString::tr("treeview-introduction")));
  19. /*
  20. * Stub for the drink info
  21. */
  22. aboutDrink_ = new WText("", root());
  23. internalPathChanged().connect(this, &TreeViewApplication::handlePathChange);
  24. this->handlePathChange();
  25. }
  26. private:
  27. WText *aboutDrink_;
  28. void handlePathChange() {
  29. if (internalPathMatches("/drinks/")) {
  30. std::string drink = internalPathNextPart("/drinks/");
  31. aboutDrink_->setText(WString::tr("drink-" + drink));
  32. }
  33. }
  34. };
  35. WApplication *createApplication(const WEnvironment& env)
  36. {
  37. WApplication *app = new TreeViewApplication(env);
  38. app->setTitle("WTreeView example");
  39. app->messageResourceBundle().use(WApplication::appRoot() + "drinks");
  40. app->styleSheet().addRule("button", "margin: 2px");
  41. //app->useStyleSheet("treeview.css");
  42. return app;
  43. }
  44. int main(int argc, char **argv)
  45. {
  46. return WRun(argc, argv, &createApplication);
  47. }