Project

General

Profile

Actions

Bug #1038

closed

WCompositeWidget localization...

Added by Łukasz Matuszewski over 12 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
-
Start date:
10/24/2011
Due date:
% Done:

0%

Estimated time:

Description

I have header only custom widget:

#ifndef _MIR_WCUSTOMTABLEVIEW_H_
#define _MIR_WCUSTOMTABLEVIEW_H_
/*
 * Copyright (c) 2011,
 * Technical University Of Gdansk,
 * Faculty of Electronics, Telecommunications and Informatics,
 * Multimedia Systems Department
 * and/or its affiliates. All rights reserved.
 */
#include <Wt/WEnvironment>
#include <Wt/WContainerWidget>
#include <Wt/WCompositeWidget>
#include <Wt/WAbstractItemModel>
#include <Wt/WTableView>
#include <Wt/WAnchor>
#include <Wt/WPushButton>
#include <Wt/WCheckBox>
#include <Wt/WLink>
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/QueryModel>
#include <Wt/WEvent>
#include <Wt/WHBoxLayout>
#include <Wt/WSlider>
#include <Wt/WEvent>

#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/any.hpp>

#include <vector>

#include "utils/mir_trkeys.h"
#include "utils/mir_cssclasses.h"
#include "widgets/mir_wcustomtableviewpushbutton.h"
#include "mir_databasemodule.h"
#include "resources/mir_sp_paramselresource.h"

namespace SyNaT
{
  namespace MIR
  {
/*  */
#define MIR_TABLE_EXP_NO_NAME "table_exp_no_name"
#define MIR_TABLE_EXP_SELECTION_NAME "table_exp_selection_name"
#define MIR_TABLE_EXP_ARTIST_NAME "table_exp_artist_name"
#define MIR_TABLE_EXP_ALBUM_NAME  "table_exp_album_name"
#define MIR_TABLE_EXP_GENRE_NAME "table_exp_genre_name"
#define MIR_TABLE_EXP_TITLE_NAME "table_exp_title_name"
#define MIR_TABLE_EXP_YEAR_OF_RECORDING_NAME "table_exp_year_of_recording"
#define MIR_TABLE_EXP_TRACK_NUMBER_NAME "table_exp_track_number"
#define MIR_TABLE_EXP_DOWNLOAD_NAME "table_exp_download_name"
#define MIR_TABLE_EXP_DOWNLOAD "table_exp_download"
#define MIR_TABLE_EXP_DOWNLOAD_PARAMS_NAME "table_exp_download_params_name"
#define MIR_TABLE_EXP_DOWNLOAD_PARAMS "table_exp_download_params"
#define MIR_TABLE_EXP_SEARCH "table_exp_search"
#define MIR_TABLE_EXP_LIKE "table_exp_like"

#define MIR_VEC_OF_PARAMS "vec_of_params"
#define MIR_VECS_OF_PARAMS "vecs_of_params"

/* Dla widżetu WCustomTableView */
#define MIR_WCTV_FIRST "wctv_first"
#define MIR_WCTV_PREV "wctv_prev"
#define MIR_WCTV_NEXT "wctv_next"
#define MIR_WCTV_LAST "wctv_last"
#define MIR_WCTV_EXPORT_SEL_PARS "wctv_export_sel_pars"
#define MIR_WCTV_SAVE_SEL "wctv_save_sel"
#define MIR_WCTV_APPLY_SEARCH "wctv_apply_search"
#define MIR_WCTV_SELECT_ALL_FILTERED "wctv_select_all_filtered"
#define MIR_WCTV_UNSELECT_ALL_FILTERED "wctv_unselect_all_filtered"
#define MIR_WCTV_INVERSE_SELECTION "wctv_inverse_selection"

    using namespace Wt;
    using namespace std;
    namespace dbo = Wt::Dbo;

    template <class Result>
    class WCustomTableView : public WCompositeWidget
    {
      friend class WCustomTableViewPushButton<Result>;

      public:

        WCustomTableView(DatabaseModule *dm, dbo::Session *session, bool likeStatement = false, WContainerWidget *parent = 0)
          : WCompositeWidget(new WContainerWidget(), parent), m_checkable(false)
          , m_current_page(0), m_nav_bar_created(false), m_num_of_pages_in_nav_bar(1)
          , m_first_page_in_nav_bar(0), m_last_page_in_nav_bar(m_num_of_pages_in_nav_bar-1)
          , m_dm(dm), m_session(session), m_pref_num_of_pages_in_nav_bar(4)
        {
          this->m_page_nav_bar = new WContainerWidget();
          this->addChild(this->m_page_nav_bar);
          this->m_page_nav_bar->setClearSides(Left | Right);
          WContainerWidget *options_bar = new WContainerWidget();
          this->addChild(options_bar);
          options_bar->setClearSides(Left | Right);
//          WPushButton *wpb = new WPushButton(tr(MIR_WCTV_SAVE_SEL), options_bar);
//          wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
//          new WText("&nbsp;&nbsp;&nbsp;", XHTMLText, options_bar);
          WAnchor *ar = new WAnchor(WLink(new SP::ParamsSelResource(this->m_dm)), tr(MIR_WCTV_EXPORT_SEL_PARS), options_bar);
          ar->setTarget(TargetNewWindow);
          options_bar = new WContainerWidget();
          this->addChild(options_bar);
          options_bar->setClearSides(Left | Right);
          this->m_txt = new WText(tr(MIR_TABLE_EXP_SEARCH).arg(WString::Empty), options_bar);
          this->m_txt->disable();
          this->m_sle = new WLineEdit(options_bar);
          this->m_sle->disable();
          if (likeStatement)
          {
            this->m_wcb = new WCheckBox(tr(MIR_TABLE_EXP_LIKE), options_bar);
            this->m_wcb->disable();
          }
          if (!WApplication::instance()->environment().ajax())
            this->m_wpb = new WPushButton(tr(MIR_WCTV_APPLY_SEARCH), options_bar);
          options_bar = new WContainerWidget();
          this->addChild(options_bar);
          options_bar->setClearSides(Left | Right);
          WHBoxLayout *layout = new WHBoxLayout();
          this->m_selectAll = new WPushButton(tr(MIR_WCTV_SELECT_ALL_FILTERED));
          layout->addWidget(this->m_selectAll);
          this->m_selectAll->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
          this->m_inverseSelection = new WPushButton(tr(MIR_WCTV_INVERSE_SELECTION));
          layout->addWidget(this->m_inverseSelection);
          this->m_inverseSelection->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
//          new WText("&nbsp;&nbsp;&nbsp;", XHTMLText, options_bar);
          this->m_unselectAll = new WPushButton(tr(MIR_WCTV_UNSELECT_ALL_FILTERED));
          layout->addWidget(this->m_unselectAll);
          this->m_unselectAll->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
          options_bar->setLayout(layout, AlignTop | AlignJustify);
          options_bar = new WContainerWidget();
          options_bar->setClearSides(Left | Right);
          layout = new WHBoxLayout();
          this->m_wtv = new WTableView();
          layout->addWidget(this->m_wtv);
          this->m_slider = new WSlider(Vertical);
          this->m_slider->setTickPosition(WSlider::TicksRight);
          layout->addWidget(this->m_slider);
          options_bar->setLayout(layout, AlignTop | AlignJustify);
          this->addChild(options_bar);
        }

        virtual ~WCustomTableView()
        {
        }

        WText &searchText()
        {
          return *(this->m_txt);
        }

        WLineEdit &searchLineEdit()
        {
          return *(this->m_sle);
        }

        WPushButton &searchPushButtonNoAjax()
        {
          return *(this->m_wpb);
        }

        WCheckBox &searchCheckBoxLike()
        {
          return *(this->m_wcb);
        }

        WPushButton &selectAllPushButton()
        {
          return *(this->m_selectAll);
        }

        WPushButton &inverseSelection()
        {
          return *(this->m_inverseSelection);
        }

        WPushButton &unselectAllPushButton()
        {
          return *(this->m_unselectAll);
        }

        WSlider &slider()
        {
          return *(this->m_slider);
        }

        int update_slider()
        {
          int reminder = this->model()->rowCount() % this->rowsPerPage();
          int max = this->pageCount() + (reminder > 0 ? 0 : -1);
          this->m_slider->setRange(0, max);
          int tickInterval = (int) (this->height().value() / max);

          if (tickInterval < 10)
            tickInterval = (int) ((10 * max) / this->height().value());
          this->m_slider->setTickInterval(tickInterval);
          return max;
        }

        virtual void load()
        {
          if (!this->loaded())
          {
            this->m_first_page_in_nav_bar = 0;
            this->m_page_nav_bar->setLayout(this->create_page_nav_bar(), AlignTop | AlignJustify);
            this->m_slider->setValue(this->update_slider());

            this->m_slider->sliderMoved().connect(this, &WCustomTableView::slt_sliderMoved);

            this->m_nav_bar_created = true;
          }
          this->WCompositeWidget::load();
        }

        int rowsPerPage() const
        {
          return this->m_rows_per_page;
        }

        void setRowsPerPage(const int rows)
        {
          this->m_rows_per_page = rows;
        }

        void slt_sliderMoved(int page_clicked)
        {
          bool nbnu = false;
          if (this->pageCount() >= page_clicked)
          {
            page_clicked = this->m_slider->maximum() - page_clicked;

            if (this->m_current_page != page_clicked)
            {
              if (page_clicked <= this->pageCount())
                this->scrollTo(
                      this->model()
                        ->index(page_clicked * this->rowsPerPage(), 0), WTableView::PositionAtTop);
              this->m_first_page_in_nav_bar = page_clicked;
              this->m_last_page_in_nav_bar = page_clicked + this->m_num_of_pages_in_nav_bar - 1;
              if (this->m_first_page_in_nav_bar + this->m_num_of_pages_in_nav_bar > this->m_slider->maximum())
              {
                this->m_first_page_in_nav_bar = this->m_slider->maximum() - this->m_num_of_pages_in_nav_bar + 1;
                this->m_last_page_in_nav_bar = this->m_slider->maximum();
              }
              this->m_current_page = page_clicked;

              nbnu = true;
            }
          }
          else
          {
            this->update_slider();
            this->m_slider->setValue(this->m_slider->maximum());
          }
          this->update_page_nav_bar(nbnu);
        }

        dbo::QueryModel<Result> *model() const
        {
          return dynamic_cast<dbo::QueryModel<Result> *>(this->m_wtv->model());
        }

        void setModel(dbo::QueryModel<Result> *model)
        {
          if (model)
            model->layoutChanged().connect(this, &WCustomTableView::slt_modelLayoutChanged);
          this->m_wtv->setModel(model);
        }

        void slt_modelLayoutChanged()
        {
          int sortColumn = this->sortColumn();
          if (sortColumn > -1)
          {
            WString headerName = boost::any_cast<WString>(this->model()->headerData(sortColumn));
            this->m_txt->setText(tr(MIR_TABLE_EXP_SEARCH).arg(headerName));
            this->m_txt->enable();
            this->m_sle->enable();
            this->m_wcb->enable();
          }
          else
          {
            this->m_txt->setText(tr(MIR_TABLE_EXP_SEARCH).arg(WString::Empty));
            this->m_txt->disable();
            this->m_sle->disable();
            this->m_wcb->disable();
          }
        }

        void setSortingEnabled(int column, bool enabled)
        {
          this->m_wtv->setSortingEnabled(column, enabled);
        }

        virtual void setRowHeight(const WLength& rowHeight)
        {
          this->m_wtv->setRowHeight(rowHeight);
        }

        virtual void setColumnWidth(int column, const WLength& width)
        {
          this->m_wtv->setColumnWidth(column, width);
        }

        void sortByColumn(int column, SortOrder order)
        {
          this->m_wtv->sortByColumn(column, order);
        }

        virtual void setAlternatingRowColors(bool enable)
        {
          this->m_wtv->setAlternatingRowColors(enable);
        }

        void setItemDelegateForColumn(int column, WAbstractItemDelegate *delegate)
        {
          this->m_wtv->setItemDelegateForColumn(column, delegate);
        }

        virtual void setSelectable(bool selectable)
        {
          this->m_wtv->setSelectable(selectable);
        }

        virtual void setCheckable(const bool checkable)
        {
          this->m_checkable = checkable;
        }

        virtual void resize(const int& widthPx, const int& heightPx)
        {
          this->WCompositeWidget::resize(widthPx, heightPx);
          this->m_wtv->resize(widthPx, heightPx-120);
          this->m_slider->setHeight(heightPx-120);
        }

        virtual void resize(const WLength& width, const WLength& height)
        {
          this->WCompositeWidget::resize(width, height);
        }

        virtual void resize_inner_table_view(const WLength& width, const WLength& height)
        {
          this->m_wtv->resize(width, height);
        }

        virtual void scrollTo(const WModelIndex& index,
            Wt::WTableView::ScrollHint hint = Wt::WTableView::EnsureVisible)
        {
          this->m_wtv->scrollTo(index, hint);
        }

        virtual int pageCount() const
        {
          return (int) (this->model()->rowCount() / (this->rowsPerPage()));
        }

        virtual int pageSize() const
        {
          return this->m_wtv->pageSize();
        }

        virtual void setPrefNumOfPagesInNavBar(int num_of_pages)
        {
          this->m_pref_num_of_pages_in_nav_bar = num_of_pages;
        }

        virtual int sortColumn()
        {
          return this->m_wtv->sortColumn();
        }

        virtual void refresh()
        {
          this->m_wtv->refresh();
        }

        void update_page_nav_bar(const bool navBarNeedUpdate = false)
        {
          if (navBarNeedUpdate && this->m_nav_bar_created)
          {
            if (this->pageCount() < this->m_first_page_in_nav_bar + this->m_pref_num_of_pages_in_nav_bar - 1)
            {
              this->m_num_of_pages_in_nav_bar = this->pageCount() - this->m_first_page_in_nav_bar;
              this->m_current_page = 0;
              this->m_first_page_in_nav_bar = 0;
              this->model()->reload();
              this->m_wtv
                ->scrollTo(
                    this->model()->index(0, 0), WTableView::PositionAtTop);
            }
            else
              this->m_num_of_pages_in_nav_bar = this->m_pref_num_of_pages_in_nav_bar;

            this->m_page_nav_bar->clear();
            this->m_page_numbers.clear();
            this->m_page_nav_bar->setLayout(this->create_page_nav_bar(), AlignTop | AlignJustify);
          }
          if (this->m_page_numbers.at(0)->text().toUTF8() != boost::lexical_cast<string>(this->m_first_page_in_nav_bar + 1))
          {
            int first_page_in_nav_bar = this->m_first_page_in_nav_bar;

            BOOST_FOREACH(WCustomTableViewPushButton<Result> *b, this->m_page_numbers)
            {
              b->setText(boost::lexical_cast<string>(first_page_in_nav_bar++ + 1));
            }
          }
          BOOST_FOREACH(WCustomTableViewPushButton<Result> *b, this->m_page_numbers)
          {
            string current_page = boost::lexical_cast<string>(this->m_current_page + 1);
            if (b->text().toUTF8() == current_page)
            {
              b->setStyleClass(MIR_STRCAT3(MIR_CSS_PAGE_NAV_BUTTON," ",MIR_CSS_PAGE_NAV_BUTTON_SELECTED));
            }
            else
            {
              b->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            }
          }

        }

      protected:

        virtual WHBoxLayout *create_page_nav_bar()
        {
          WHBoxLayout *layout = new WHBoxLayout();
          int page_count = this->m_wtv->pageCount();
          if (page_count > this->m_pref_num_of_pages_in_nav_bar)
            page_count = this->m_pref_num_of_pages_in_nav_bar;
          this->m_num_of_pages_in_nav_bar = page_count;
          if (this->m_wtv->pageCount() > 0)
          {
            WCustomTableViewPushButton<Result> *wpb = new WCustomTableViewPushButton<Result>(tr(MIR_WCTV_FIRST), this);
            this->m_wpbFirst = wpb;
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_first_page_clicked);
            wpb = new WCustomTableViewPushButton<Result>(tr(MIR_WCTV_PREV), this);
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_prev_page_clicked);
            wpb = new WCustomTableViewPushButton<Result>("<", this);
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_prev_pages_clicked);

            for(int i = this->m_first_page_in_nav_bar; i < this->m_first_page_in_nav_bar + page_count; i++)
            {
              wpb = new WCustomTableViewPushButton<Result>(boost::lexical_cast<string>(i+1), this);
              layout->addWidget(wpb);
              wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
              wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_page_clicked);
              this->m_page_numbers.push_back(wpb);
            }

            this->m_last_page_in_nav_bar = this->m_first_page_in_nav_bar + page_count - 1;

            wpb = new WCustomTableViewPushButton<Result>(">", this);
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_next_pages_clicked);
            wpb = new WCustomTableViewPushButton<Result>(tr(MIR_WCTV_NEXT), this);
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_next_page_clicked);
            wpb = new WCustomTableViewPushButton<Result>(tr(MIR_WCTV_LAST), this);
            layout->addWidget(wpb);
            wpb->setStyleClass(MIR_STRINGIFY(MIR_CSS_PAGE_NAV_BUTTON));
            wpb->clicked().connect(wpb, &WCustomTableViewPushButton<Result>::slt_last_page_clicked);
          }
          this->update_page_nav_bar();
          return layout;
        }

      private:
        WTableView                                   *m_wtv;

        DatabaseModule                               *m_dm;

        WContainerWidget                             *m_page_nav_bar;

        WLineEdit                                    *m_sle;

        WText                                        *m_txt;

        WPushButton                                  *m_wpb;

        WCheckBox                                    *m_wcb;

        WPushButton                                  *m_selectAll;

        WPushButton                                  *m_inverseSelection;

        WPushButton                                  *m_unselectAll;

        WSlider                                                      *m_slider;

        dbo::Session                                 *m_session;

        vector<WCustomTableViewPushButton<Result> *>  m_page_numbers;

        WCustomTableViewPushButton<Result>           *m_wpbFirst;

        bool                                          m_checkable;

        int                                           m_first_page_in_nav_bar;

        int                                           m_last_page_in_nav_bar;

        int                                           m_current_page;

        int                                           m_num_of_pages_in_nav_bar;

        int                                           m_pref_num_of_pages_in_nav_bar;

        int                                           m_rows_per_page;

        bool                                          m_nav_bar_created;
    };

  }
}
#endif /* _MIR_WCUSTOMTABLEVIEW_H_ */

and i use it in this code:

        WTable *wtab = new WTable();
        wtab->setMargin(WLength::Auto, Left | Right);
        WTableCell *cell = wtab->elementAt(0,0);

        this->m_rows = 20;

        this->m_wtv = new WCustomTableView<Wt::Dbo::ptr<NazArtNazAlbItp> >(this->m_dm, &this->m_session, true, cell);
        this->m_wtv->setRowsPerPage(this->m_rows);

        NazArtNazAlbItpModel *qmodel = new NazArtNazAlbItpModel(this->m_dm, this);
        {
          db::Transaction transaction(m_session);
          db::Query< db::ptr<NazArtNazAlbItp> > query =
              m_session.query< db::ptr<NazArtNazAlbItp> >
                ("select u  from MIR_NAZARTNAZALBITP u ");

          qmodel->setQuery(query, true);
        }
        qmodel->addColumn("NAA_ID", tr(MIR_TABLE_EXP_SELECTION_NAME), ItemIsUserCheckable);
        qmodel->addColumn("ART_NAZWA_ARTYSTY", tr(MIR_TABLE_EXP_ARTIST_NAME));
        qmodel->addColumn("ALB_NAZWA_ALBUMU", tr(MIR_TABLE_EXP_ALBUM_NAME));
        qmodel->addColumn("GAT_GATUNEK", tr(MIR_TABLE_EXP_GENRE_NAME));
        qmodel->addColumn("UTW_TYTUL_UTWORU", tr(MIR_TABLE_EXP_TITLE_NAME));
        qmodel->addColumn("UTW_ROK_NAGRANIA", tr(MIR_TABLE_EXP_YEAR_OF_RECORDING_NAME));
        qmodel->addColumn("UTW_NR_SCIEZKI", tr(MIR_TABLE_EXP_TRACK_NUMBER_NAME));
        qmodel->addColumn("NAA_ID", tr(MIR_TABLE_EXP_DOWNLOAD_PARAMS_NAME));
        if(this->m_dm->isUser(MIR_MUSIC_FILE_OPERATOR))
          qmodel->addColumn("NAA_ID", tr(MIR_TABLE_EXP_DOWNLOAD_NAME));
        qmodel->setBatchSize(this->m_rows * 100);
        int cols = this->m_dm->isUser(MIR_MUSIC_FILE_OPERATOR) ? 9 : 8, colWidth = 120;
        this->m_wtv->setModel(qmodel);
        this->m_wtv->setSortingEnabled(0, false);
        this->m_wtv->setSortingEnabled(1, true);
        this->m_wtv->setSortingEnabled(2, true);
        this->m_wtv->setSortingEnabled(3, true);
        this->m_wtv->setSortingEnabled(4, true);
        this->m_wtv->setSortingEnabled(5, true);
        this->m_wtv->setSortingEnabled(6, true);
        this->m_wtv->setSortingEnabled(7, false);
        if(this->m_dm->isUser(MIR_MUSIC_FILE_OPERATOR))
          this->m_wtv->setSortingEnabled(8, false);
        this->m_wtv->setRowHeight(22);

        this->m_wtv->setColumnWidth(0, 50);
        for (int i = 1; i < cols - 4; i++)
        {
          this->m_wtv->setColumnWidth(i, colWidth);
        }
        this->m_wtv->setColumnWidth(cols - 4, 120);
        this->m_wtv->setColumnWidth(cols - 3, 120);
        this->m_wtv->setColumnWidth(cols - 2, 120);
        this->m_wtv->setColumnWidth(cols - 1, 80);

        this->m_wtv->resize((cols - 5) * colWidth + (cols - 5) * 7 + 3 * 120 + 80 + 50 + 5 * 7, 20 + this->m_rows * 22 + 120);
        this->m_wtv->setAlternatingRowColors(true);
        this->m_wtv->setSelectable(true);
        if (WApplication::instance()->environment().ajax())
        {
          this->m_wtv->searchLineEdit().keyWentUp().connect(this, &ExplorerControls::slt_changeQueryAndReloadModel);
          this->m_wtv->searchCheckBoxLike().changed().connect(this, &ExplorerControls::slt_changeQueryAndReloadModel);
        }
        else
          this->m_wtv->searchPushButtonNoAjax().clicked().connect(this, &ExplorerControls::slt_changeQueryAndReloadModel);
        this->m_wtv->selectAllPushButton().clicked().connect(this, &ExplorerControls::slt_selectAllFiltered);
        this->m_wtv->inverseSelection().clicked().connect(this, &ExplorerControls::slt_inverseSelection);
        this->m_wtv->unselectAllPushButton().clicked().connect(this, &ExplorerControls::slt_unselectAllFiltered);
        this->m_was_rendered = true;
        return wtab;

When i try to change locale to/from Polish it changes only headers in WTableView which is part of WCustomTableView. It doesn't change the localized strings in for example: m_selectAll, m_inverseSelection, m_unselectAll. They are WPushButton's, and are part of WCustomTableView.

You will have to modify a little a source code of this above example to make it work.

To see in live how this works go to https://synat.eti.pg.gda.pl accept temporary the certificate and login as: lukasz with password: anakin. Then click on flag of Poland/England in left upper corner of web page. After you do that everything will be clear what i am writing about.

Best regards,

Łukasz Matuszewski


Files

mir_wcustomtableview.h (20 KB) mir_wcustomtableview.h Łukasz Matuszewski, 11/18/2011 10:59 AM
mir_wcustomtableviewpushbutton.h (7.06 KB) mir_wcustomtableviewpushbutton.h Łukasz Matuszewski, 11/18/2011 10:59 AM
mir_trkeys.h (4.89 KB) mir_trkeys.h Łukasz Matuszewski, 11/18/2011 10:59 AM
Prezentacja.zip (1.48 MB) Prezentacja.zip Łukasz Matuszewski, 02/11/2012 09:25 PM
Actions #1

Updated by Koen Deforche over 12 years ago

  • Status changed from New to Feedback
  • Assignee set to Koen Deforche
  • Target version set to 3.2.0

Hey,

I'm a bit puzzled by your code. A composite widget hides the implementation (in your case WContainerWidget) from the rest. You should add children to this implementation.

So, you should be changing your code so that you use addWidget() for the contents, instead of addChild() [of which I am not sure how that actually does anything --- and I suspect this is a bug in Wt then?]

Regards,

koen

Actions #2

Updated by Łukasz Matuszewski over 12 years ago

I will try it tomorrow (that is use addWidget thru setImplementation()) just like in blog example.

Updated by Łukasz Matuszewski over 12 years ago

I have used the pattern showed in blog example (creating Impl class and composite class) and the i18n of this doesn't work. I am using WApplication::instance()setLocale("pl"); to change locale to Polish and WApplication::instance()>setLocale("en") to change to English.

The header inside table composite widget changes but not the links around it (WTableView is i18n perfectly, but not other widgets inside composite widget - that is inside its implementation - doesn't change).

Have changed also addChild to addWidget inside implemenetation...

I am thinking this is a bug inside Wt.

BR,

Lukasz

Actions #4

Updated by Koen Deforche over 12 years ago

Hey Lukasz,

Can you provide an updated .C file too? You should not be using addChild() anymore.

Regards,

koen

Actions #5

Updated by Łukasz Matuszewski over 12 years ago

In attachment there is everything you need ... no need of .C file - this is only header based component.

Actions #6

Updated by Łukasz Matuszewski over 12 years ago

Example of usage:

  this->m_wtv = new WCustomTableView<Wt::Dbo::ptr<NazArtNazAlbItp> >(this->m_dm, &this->m_session, true, cell); 

where NazArtNazAlbItp is ORM class like:

#include <Wt/Dbo/Dbo>

#include <string>

namespace SyNaT
{
  namespace MIR
  {
    namespace SP
    {
      using namespace std;
      namespace dbo = Wt::Dbo;

      class NazArtNazAlbItp
      {
        public:
          long long m_naa_id;
          string m_nazwa_artysty;
          string m_nazwa_albumu;
          string m_gatunek;
          string m_tytul_utworu;
          short  m_rok_nagrania;
          short  m_nr_sciezki;
          template<class Action> void persist(Action& a)
          {
            dbo::field(a, m_naa_id, "NAA_ID");
            dbo::field(a, m_nazwa_artysty,     "ART_NAZWA_ARTYSTY");
            dbo::field(a, m_nazwa_albumu, "ALB_NAZWA_ALBUMU");
            dbo::field(a, m_gatunek, "GAT_GATUNEK");
            dbo::field(a, m_tytul_utworu, "UTW_TYTUL_UTWORU");
            dbo::field(a, m_rok_nagrania, "UTW_ROK_NAGRANIA");
            dbo::field(a, m_nr_sciezki, "UTW_NR_SCIEZKI");
          }
      };
    }
  }
}

namespace Wt
{
  namespace Dbo
  {

    template<>
    struct dbo_traits<SyNaT::MIR::SP::NazArtNazAlbItp> : public dbo_default_traits
    {

      static const char *versionField()
      {
        return 0;
      }

      static const char *surrogateIdField()
      {
        return "UTW_ID";
      }

    };

  }
} 
Actions #7

Updated by Koen Deforche over 12 years ago

  • Status changed from Feedback to InProgress
  • Target version changed from 3.2.0 to 3.2.1
Actions #8

Updated by Koen Deforche about 12 years ago

  • Status changed from InProgress to Feedback

Hey Lukas,

With 3.2.1 in eye-sight, I am revisiting the unresolved bugs.

I tried to make your code work, but, unfortunately, I couldn't because mir_customtableview.h includes other include files which we lack:

#include "utils/mir_trkeys.h"

#include "utils/mir_cssclasses.h"

#include "widgets/mir_wcustomtableviewpushbutton.h"

#include "mir_databasemodule.h"

#include "resources/mir_sp_paramselresource.h"

Is there any way for you to reproduce the problem in a self-contained test case (a single file preferably, but at least a set of files that have no more missing dependencies) that shows the defect ?

Regards,

koen

Actions #9

Updated by Łukasz Matuszewski about 12 years ago

The only thing is to use cmake to make makefiles (you will probably want to modify it).

Typical cmake command looks like:

cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING=Debug -DDEPLOYROOT=/var/www/wt -DWEBUSER=www-data -DWEBGROUP=www-data -DPROJECT_CONNECTOR=wthttpd -DBOOST_PREFIX=../boost -DMULTI_THREADED=YES -DCONNECTOR_HTTP=YES -DHARU_PREFIX=../libharu -DDEBUG=YES

Attached zip contains everything you need ... even compiled binary under Debian Linux 6. Only thing to correct in underlying code is:

/* YOUR CONNECTION PARAMS HERE */ // in mir_sp_prezentacja.cpp

where you must specify connection params. And of course you will probably want to modify ORM class used to map db table.

Actions #10

Updated by Koen Deforche about 12 years ago

  • Target version changed from 3.2.1 to 3.2.2
Actions #11

Updated by Koen Deforche almost 12 years ago

  • Status changed from Feedback to InProgress
  • Target version changed from 3.2.2 to 3.2.3
Actions #12

Updated by Koen Deforche over 11 years ago

  • Target version deleted (3.2.3)
Actions #13

Updated by Koen Deforche over 9 years ago

  • Status changed from InProgress to Resolved

Hey,

It's because you overload refresh() but do not call the base implementation.

refresh() is the virtual function which propagates localization changes through the widget tree.

Koen

Actions #14

Updated by Koen Deforche about 9 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF