ListStore problem
- From: Ugur Arpaci <ugurarpaci gmail com>
- To: gtkmm-list gnome org
- Subject: ListStore problem
- Date: Sat, 28 Aug 2010 01:18:22 +0200
Hi everyone;
With the following source code, i tried to obtain a scroll panel that includes list store, but i wanted to create only rows in that List Store.
There is a problem here, this code generates one row and one column at the same time, i want only rows though.
Can anyone check this please?
class showCurrentAppointments : public Gtk::Window
{
public:
showCurrentAppointments();
virtual ~showCurrentAppointments();
Gtk::TreeModelColumnRecord myColumn;
protected:
void quit_button_clicked();
void save_button_clicked();
Gtk::VButtonBox buttonBox;
Gtk::VBox List,Button;
Gtk::Button closeCurrentApp;
//Tree model columns:
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(colId);
add(colName);
add(colSurname);
add(colAge);
add(colEmail);
add(colMobile);
add(colDate);
}
Gtk::TreeModelColumn<unsigned int> colId;
Gtk::TreeModelColumn<Glib::ustring> colName;
Gtk::TreeModelColumn<Glib::ustring> colSurname;
Gtk::TreeModelColumn<Glib::ustring> colAge;
Gtk::TreeModelColumn<Glib::ustring> colEmail;
Gtk::TreeModelColumn<Glib::ustring> colMobile;
Gtk::TreeModelColumn<Glib::ustring> colDate;
};
ModelColumns mColumns;
Gtk::ScrolledWindow infoScrolled;
Gtk::TreeView refTreeView;
Glib::RefPtr<Gtk::ListStore> refTreeModel;
};
showCurrentAppointments::showCurrentAppointments():
closeCurrentApp(Gtk::Stock::QUIT)
{
set_title("Current Appointments");
set_default_size(1024,768);
set_resizable(true);
set_border_width(10);
refTreeModel = Gtk::ListStore::create(mColumns);
refTreeView.set_model(refTreeModel);
infoScrolled.add(refTreeView);
infoScrolled.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
infoScrolled.set_size_request(800,600);
List.pack_start(infoScrolled);
ifstream out("Appointment1.txt", ios::app);
string sName,sSurname,sAge,sEmail,sMobile,sDate;
if(!out){
std::cout<<"File cannot be opened\n";
exit(2);
}
char ch;
int order=1;
int colid=1;
char listBuffer[40];
int flagBuf=0;
for(int internal=0;internal<40;internal++)
{
if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
Gtk::TreeModel::Row row;
do{
out.get(ch);
if(order==1){
if(ch=='\t'){
sName=listBuffer;
order++;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{
if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;}
}
else if(order==2){
if(ch=='\t'){
sSurname=listBuffer;
order++;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;
}
}
else if(order==3){
if(ch=='\t'){
sAge=listBuffer;
order++;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;
}
}
else if(order==4){
if(ch=='\t'){
sEmail=listBuffer;
order++;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;
}
}
else if(order==5){
if(ch=='\t'){
sMobile=listBuffer;
order++;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;
}
}
else if(order==6){
if(ch=='\n'){
sDate=listBuffer;
order=1;
flagBuf=0;
for(int internal=0;internal<40;internal++)
{if(internal==40)
listBuffer[internal]='\0';
else
listBuffer[internal]=' ';
}
row = *(refTreeModel->append());
row[mColumns.colId]=colid;
row[mColumns.colAge]=sAge;
row[mColumns.colName]=sName;
row[mColumns.colSurname]=sSurname;
row[mColumns.colEmail]=sEmail;
row[mColumns.colDate]=sDate;
row[mColumns.colMobile]=sMobile;
refTreeView.append_column("Number",mColumns.colId);
refTreeView.append_column("Name",mColumns.colName);
refTreeView.append_column("Surname",mColumns.colSurname);
refTreeView.append_column("Age",mColumns.colAge);
refTreeView.append_column("Mobile",mColumns.colMobile);
refTreeView.append_column("Date",mColumns.colDate);
colid++;
}
else{
listBuffer[flagBuf]=ch;
flagBuf++;
}
}
}while(out);
out.close();
for(int i = 0; i < 5; i++)
{
Gtk::TreeView::Column* pColumn = refTreeView.get_column(i);
pColumn->set_reorderable();
}
buttonBox.pack_start(closeCurrentApp,Gtk::PACK_SHRINK);
Button.pack_start(List,Gtk::PACK_SHRINK);
Button.pack_start(buttonBox,Gtk::PACK_SHRINK);
add(Button);
closeCurrentApp.signal_clicked().connect(sigc::mem_fun(*this,
&showCurrentAppointments::quit_button_clicked) );
show_all_children();
}
showCurrentAppointments::~showCurrentAppointments(){
}
void showCurrentAppointments::quit_button_clicked(){
hide();
}
--
Uğur ARPACI
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]