Hello,

Nageaev, thank you very much for taking the time to make a compilable and working version of my application. I

I just have a quick follow up question based on the changes.

When I compile my program I get the following error:

  what():  Sqlite3: insert into "p1copy" ("version", "Config_IDs_Rams_Ram1AID", 
"Config_IDs_Rams_Ram1BID", "Config_IDs_Rams_Ram2AID", "Config_IDs_Rams_Ram2BID") values (?, ?, ?, ?, ?): 
table p1copy has no column named version

Now I know this is a sqlite3 error that has occured because of the version field and when I suppress the version field I get a Segmentation fault.

Thanks again for your response.
Joel


On 12-05-30 12:22 AM, Nagaev Boris wrote:
Hello!

Changes:

1. WItemDelegate is not a widget. It should be set to view by
view->setItemDelegateForColumn() (or setItemDelegate if you want it
for all the columns)

2. Function create_database should call session.createTables() to create tables.

3. Fields in Panel1 were mixed up (Config_Cal_Position_THClosedB wa
mapped twice and Config_Cal_Position_THClosedB was mapped to
"Config_Cal_Position_THClosedb" (last letter "b", not "B").

4. To make this work, I removed Instructions table and create Panel2
class -- a copy of Panel1. Fields of Instructions differ from fields
of Panel1, so entry of Panel1 can't be saved to Instructions directly
(column to column): some domain specific transformation is needed
(change code of writeMod::setModelData to apply custom transformation
from one table to another).

5. When declaring methods in C++ inside class (event if they are
overloaded from ancestor class), do not mention class name. I mean, it
should be "setModelData" instead of "WItemDelegate::setModelData".

6. Every function or method should have return type (except
constructor and destructor). So it should be "void setModelData"

7. I have added constructor to writeMod class. It takes a pointer to
another model (writable) and save it as a field. Then in
setModelData() method this saved pointer would be used to save data
to.

8. Each operation with database should be done under active
transaction (see create_database())


Compilable and working version is attached.

One entry of Panel1 is created from the beginning. Whenever it is
edited in the view, modified version of it is stored to "p2" table.
This code can be changed to implement "Instructions" logic.

On Wed, May 30, 2012 at 3:45 AM, Joel<[email protected]>  wrote:
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


------------------------------------------------------------------------------
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

------------------------------------------------------------------------------
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

Reply via email to