Hello,
Thank you for your reply Nagaev, I very much appreciate it.
I have created two models for each one of my tables, and the read-only
table is set with view->setModel. I am having an issue with your third step
3. Inherit from WItemDelegate, overload method
WItemDelegate::setModelData with custom function, saving data to
another model (instructions table).
I am using the WItemDelegate class and following the example of how to
deal with a specialized editor and I have implemented the following in
my code:
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session& session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model = new dbo::QueryModel<
dbo::ptr<Panel1> >();
model->setQuery(session.find<Panel1>());
model->addColumn("Config_Cal_Position_THClosedB",ItemIsEditable);
model->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
WTableView *view = new WTableView (this);
view->resize(800, 300);
view->setSelectionMode(SingleSelection);
view->setModel(model);
}
};
class writeMod : public WItemDelegate
{
public:
WItemDelegate::setModelData(const boost::any& editState,
Wt::WAbstractItemModel *model, const Wt::WModelIndex& index) const
{
model ->setData(index, editState, EditRole);
}
};
I am getting the following error
make[2]: Entering directory `/home/joel/moxa/awesomesauce/src'
arm-linux-g++ -DHAVE_CONFIG_H -I. -I..
-I/home/joel/moxa/witty_dist/usr/include -I/home/joel/moxa/boost_dist/include
-I/usr/local/arm-linux/include/ -mcpu=arm920t -MT awesomesauce.o -MD -MP -MF
.deps/awesomesauce.Tpo -c -o awesomesauce.o awesomesauce.cpp
awesomesauce.cpp:193: error: ISO C++ forbids declaration of ‘setModelData’ with
no type
awesomesauce.cpp:193: error: cannot define member function
‘Wt::WItemDelegate::setModelData’ within ‘writeMod’
awesomesauce.cpp: In constructor ‘MyApplication::MyApplication(const
Wt::WEnvironment&)’:
awesomesauce.cpp:218: error: no matching function for call to
‘writeMod::writeMod(Wt::Dbo::Session&, Wt::WContainerWidget*)’
awesomesauce.cpp:191: note: candidates are: writeMod::writeMod()
awesomesauce.cpp:191: note: writeMod::writeMod(const writeMod&)
make[2]: *** [awesomesauce.o] Error 1
make[2]: Leaving directory `/home/joel/moxa/awesomesauce/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/joel/moxa/awesomesauce'
make: *** [all] Error 2
I am new to c++ and web development so I know these errors probably seem
basic, I have tried to use WItemDelegate in a number of different ways
but I cannot get my code to compile. I tried using my
WItemDelegate::setModelData statment within the mainWindow class, but I
got a compiler error telling me that I cannot use this expression with
the class, that is why I created a new class writeMod.
I am going to continue to try and figure out what is going on, but if
someone has any ideas I would be very grateful.
Thanks,
Joel
On 12-05-29 02:51 AM, Nagaev Boris wrote:
Hello,
I think, this should help:
1. Create two models, first is targeted to read-only table, second to
instructions table.
2. Set one model (read-only table) with view->setModel
3. Inherit from WItemDelegate, overload method
WItemDelegate::setModelData with custom function, saving data to
another model (instructions table).
4. Set this item delegate using view->setItemDelegateForColumn for all
editable columns
Probably, you have to create two classes (one class per table) and to
map them both (Dbo::Session::mapClass).
To avoid code duplication, you can create one base class with all
needed fields, and inherit from them two empty classes.
On Tue, May 29, 2012 at 2:28 AM, Joel<[email protected]> wrote:
Hello,
I am working on an application which queries a sqlite3 database and adds
columns to a WTableView so that they can be displayed on a web browser. The
data that is displayed on the web browser is editable but I do not want to
write the edited result to the same table which it was queried from.
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session& session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model = new dbo::QueryModel<
dbo::ptr<Panel1> >();
model->setQuery(session.find<Panel1>());
model->addColumn("Config_Cal_Position_THClosedB",ItemIsEditable);
model->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
WTableView *view = new WTableView (this);
view->resize(800, 300);
view->setSelectionMode(SingleSelection);
view->setModel(model);
}
The<Panel1> table is a view only table, in order to edit the data I have to
do so through an instruction table via the following sqlite3 command
insert into instructions(instruction_type, port, param1, param2, param3)
values (0,<1-4>, 86,<register name>,<register value>);
So basically, I am attempting to read from table<Panel1>, have the ability
to edit the data on a browser, and write the edited result to the<register
value> parameter of the instruction table.
Your help would be greatly appreciated!
Thanks,
Joel
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WTableView>
#include <Wt/WText>
#include <Wt/WItemDelegate>
using namespace Wt;
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <Wt/Dbo/QueryModel>
#include <Wt/Dbo/SqlConnection>
#include <Wt/Dbo/WtSqlTraits>
namespace dbo = Wt::Dbo;
#include <string>
using namespace std;
// DataBase definition.
class Panel1 {
public:
int Config_Cal_Position_THClosedB, Config_IDs_Rams_Ram1AID;
template<class Action>
void persist(Action& a)
{
dbo::field(a, Config_Cal_Position_THClosedB, "Config_Cal_Position_THClosedb");
dbo::field(a, Config_Cal_Position_THClosedB, "Config_IDs_Rams_Ram1AID");
}
};
class Instructions {
public:
int instruction_type, param1, param2, param3, port, param4;
template<class Action>
void persist(Action& b)
{
dbo::field(b, instruction_type, "instruction_type");
dbo::field(b, param1, "param1");
dbo::field(b, param2, "param2");
dbo::field(b, param3, "param3");
dbo::field(b, port, "port");
dbo::field(b, param4, "param4");
}
};
void create_database (void)
{
dbo::Session session;
dbo::backend::Sqlite3 sqlite3 ("slipsmart.sl3");
session.setConnection (sqlite3);
session.mapClass<Panel1> ("p1");
session.mapClass<Instructions> ("instructions");
}
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session & session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model = new dbo::QueryModel< dbo::ptr<Panel1> >();
model->setQuery(session.find<Panel1>());
model->addColumn("Config_Cal_Position_THClosedB",ItemIsEditable);
model->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
WTableView *view = new WTableView (this);
view->resize(800, 300);
view->setSelectionMode(SingleSelection);
view->setModel(model);
}
};
class writeMod : public WItemDelegate
{
public:
WItemDelegate::setModelData(const boost::any& editState, Wt::WAbstractItemModel *model, const Wt::WModelIndex& index) const
{
model ->setData(index, editState, EditRole);
}
};
class MyApplication : public WApplication
{
private:
dbo::Session session;
dbo::backend::Sqlite3 sqlite3;
public:
MyApplication (WEnvironment const & env)
: WApplication (env), sqlite3 ("slipsmart.sl3")
{
session.setConnection (sqlite3);
session.mapClass<Panel1>("p1");
session.mapClass<Instructions>("instructions");
setTitle("Slipsmart Version 2.0");
root () -> addWidget (new mainWindow (session, root ()));
root () -> addWidget(new writeMod (session, root()));
}
~MyApplication (void) { std::cout << "MyApplication dead" << std::endl; }
};
WApplication * createApplication (WEnvironment const & env)
{ return new MyApplication (env); }
int main(int argc, char **argv)
{
create_database ();
return WRun (argc, argv, & createApplication);
}
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest