Hi List,

i am trying to edit an item shown in a WTableView over a WSelectionBox as
editor specified by a derived WItemDelegate.

My problem is that the WSelectionBox gets cut in height to the max height
of the underlaying cell.
I tryed specifying setOverflow(OverflowVisible) und setPopup(true) but then
the rows below are shining through the WSelectionBox and if i try to edit
the last entry in the list the editor is cut off.

Does someone know a solution?

Thanks and regards
Marco
#include <boost/cast.hpp>

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WCompositeWidget>
#include <Wt/WStandardItemModel>
#include <Wt/WTableView>
#include <Wt/WVBoxLayout>
#include <Wt/WItemDelegate>
#include <Wt/WSelectionBox>

#include <vector>
#include <string>



class Playground : public Wt::WApplication {
public:
   Playground (const Wt::WEnvironment& env);

   static Wt::WApplication* CreateApplication (const Wt::WEnvironment& env)
   {
      return new Playground(env);
   }
};



using namespace Wt;

int main (int argc, char **argv)
{

  return WRun(argc, argv, &Playground::CreateApplication);
}



class ItemDelegate : public WItemDelegate {
   void OnCloseEditor (Wt::WWidget* editor, bool save) const 
   {
      closeEditor().emit(editor, save);
   }

   public:
      ItemDelegate (WObject* parent = nullptr) 
         :WItemDelegate(parent)
      {
      }

      WWidget* createEditor (const WModelIndex& index, WFlags<ViewItemRenderFlag>) const override 
      {
         auto container = new Wt::WContainerWidget;
         container->setOverflow(WContainerWidget::OverflowVisible);
         container->setPopup(true);

         auto cb = new WSelectionBox(container);
         cb->addItem(WString("option 1"));
         cb->addItem(WString("option 2"));
         cb->addItem(WString("option 3"));

         cb->setCurrentIndex(cb->findText(asString(index.data(EditRole))));

         cb->activated().connect(std::bind(&ItemDelegate::OnCloseEditor, this, container, true));
         cb->setFocus();

         return container;
      }

      void setEditState (WWidget* editor, const boost::any& value) const override 
      {
         auto container = boost::polymorphic_cast<WContainerWidget*>(editor);
         auto cb = boost::polymorphic_cast<WSelectionBox*>(container->widget(0));

         cb->setCurrentIndex(cb->findText(asString(value)));
      }

      boost::any editState (WWidget* editor) const override 
      {
         auto container = boost::polymorphic_cast<WContainerWidget*>(editor);
         auto cb = boost::polymorphic_cast<WSelectionBox*>(container->widget(0));

         return cb->currentText();
      }
};


Playground::Playground (const WEnvironment& env) 
   : WApplication(env)
{
   auto layout = new WVBoxLayout(root());
   root()->setLayout(layout);

   auto table = new WTableView(root());
   table->setEditTriggers(WTableView::SingleClicked);
   table->setItemDelegateForColumn(1, new ItemDelegate(table));
   table->setItemDelegateForColumn(2, new ItemDelegate(table));

   layout->addWidget(table);


   auto model = new WStandardItemModel(table);
   for (size_t i = 0; i < 10; ++i) {
      std::vector<WStandardItem*> row;
      row.push_back(new WStandardItem(WString("foo")));
      row.push_back(new WStandardItem(WString("option 1")));
      row.push_back(new WStandardItem(WString("option 3")));

      row[1]->setFlags(ItemIsEditable);
      row[2]->setFlags(ItemIsEditable);

      model->appendRow(row);
   }

   model->setHeaderData(0, WString("Some description"));
   model->setHeaderData(1, WString("First"));
   model->setHeaderData(2, WString("Second"));

   table->setModel(model);
}

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to