GTKmm TreeView signal_row_activated



  • Hallo,

    ich habe eine DirView Klasse gemacht, die public Gtk::TreeView vererbt. Diese soll jetzt ein signal bekommen, aber da kommt ein Fehler bei adapter_trait.h.

    dirview.h

    #ifndef _DIRVIEW_H_
    #define _DIRVIEW_H_
    
    #include<gtkmm.h>
    #include"dirent.h"
    #include<Windows.h>
    
    class DirView : public Gtk::TreeView
    {
    protected:
    	class ModelColumns : public Gtk::TreeModel::ColumnRecord
      {
      public:
    
        ModelColumns()
        { add(m_col_name); add(m_col_size); add(m_col_ext);}
    
        Gtk::TreeModelColumn<Glib::ustring> m_col_name;
        Gtk::TreeModelColumn<unsigned __int64> m_col_size;
        Gtk::TreeModelColumn<Glib::ustring> m_col_ext;
      };
    private:
    	Glib::ustring current;
    	Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
    	ModelColumns m_Columns;
    protected:
    	bool createModel();
    	bool fillData();
    	Glib::ustring getExt(DIR *, dirent *);
    	unsigned __int64 GetSize(std::string name);
    public:
    	DirView(Glib::ustring path = "NULL");
    	~DirView(){}
    	void row_clicked();
    };
    
    #endif
    

    dirview.cpp

    #include"dirview.h"
    #include<fstream>
    #include<iostream>
    #include<io.h>
    
    DirView::DirView(Glib::ustring path)
    {
    	this->current = path;
    	createModel();
    }
    
    bool DirView::createModel()
    {
    	this->m_refTreeModel = Gtk::ListStore::create(m_Columns);
    	this->set_model(m_refTreeModel);
    
    	this->fillData();
    
    	//TreeView Columns
    	this->append_column("Name", m_Columns.m_col_name);
    	this->append_column("Size", m_Columns.m_col_size);
    	this->append_column("Extension", m_Columns.m_col_ext);
    	this->signal_row_activated().connect(sigc::mem_fun(*this,&DirView::row_clicked));
    	return true;
    }
    
    void DirView::row_clicked()
    {
    	std::cout<<"Click";
    	/*Glib::RefPtr<Gtk::TreeSelection> Selection = this->get_selection();
    	Gtk::TreeModel::iterator iter = Selection->get_selected();
    		if(*iter)
    		{
    			Gtk::TreeModel::Row row = *iter;
    			std::cout<<row[m_Columns.m_col_name]<<std::endl;
    		}*/
    }
    
    bool DirView::fillData()
    {
    	if(this->current == "NULL")
    		this->current = "C:\\";
    	DIR *dir;
    	dirent *ent;
    	if((dir = opendir(this->current.c_str()))!=NULL)
    	{
    		while((ent = readdir(dir))!=NULL)
    		{
    			Gtk::TreeModel::Row row = *(m_refTreeModel->append());
    			row[m_Columns.m_col_name] = ent->d_name;
    			if(ent->d_type !=16384)
    				row[m_Columns.m_col_size] = this->GetSize(ent->d_name);
    			else
    				row[m_Columns.m_col_size] = 0;
    			row[m_Columns.m_col_ext] = this->getExt(dir,ent);
    
    		}
    	}
    	closedir(dir);
    	return true;
    }
    
    Glib::ustring DirView::getExt(DIR *dir, dirent *ent)
    {
    	if(ent->d_type == 16384)
    		return "DIR";
    	else
    		return "FILE";
    }
    
    unsigned __int64 DirView::GetSize(std::string name)
    {
    	try{
    		std::string path = this->current.c_str() + name;
    		//muss noch code rein
    		return 1;
    	}
    	catch (std::string err)
    	{
    		std::cout<<"ERROR";
    	}
    
    }
    

    MS Visual Studio sagt dann diesen Fehler hier:
    `Fehler 2 error C2064: Ausdruck ergibt keine Funktion, die 2 Argumente übernimmt c:\gtkmm\include\sigc++-2.0\sigc++\adaptors\adaptor_trait.h 101 1 ROSZip2

    `

    Wäre schön, wenn jemand weiß, wie ich es korrigieren kann.

    Er soll beim Klick auf die TreeView eintrag halt in die Funktion void DirView::row_activated() gehen

    Vielen Dank im vorzeitlich

    Mit freundlichen Grüßen



  • `row_clicked` muss folgende signatur haben:

    void row_clicked(const Gtk::TreeModel::Path& path,Gtk::TreeViewColumn* /* column */);
    


  • Danke evilissimo,

    dirview.h

    #ifndef _DIRVIEW_H_
    #define _DIRVIEW_H_
    
    #include<gtkmm.h>
    #include"dirent.h"
    #include"pathbox.h"
    #include<Windows.h>
    #include<time.h>
    
    class DirView : public Gtk::TreeView
    {
    protected:
    	struct ErrList
    	{
    		Glib::ustring ferr;
    		tm* derr;
    		DWORD errC;
    	};
    	class ModelColumns : public Gtk::TreeModel::ColumnRecord
      {
      public:
    
        ModelColumns()
        { add(m_col_name); add(m_col_size); add(m_col_ext);}
    
        Gtk::TreeModelColumn<Glib::ustring> m_col_name;
        Gtk::TreeModelColumn<unsigned __int64> m_col_size;
        Gtk::TreeModelColumn<Glib::ustring> m_col_ext;
      };
    private:
    	Glib::ustring current;
    	Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
    	ModelColumns m_Columns;
    	PathBox *ppb;
    	ErrList err;
    protected:
    	bool createModel(bool = true);
    	bool fillData();
    	bool refresh();
    	Glib::ustring getExt(DIR *, dirent *);
    	unsigned __int64 GetSize(std::string name);
    public:
    	DirView(PathBox *p, Glib::ustring path = "NULL");
    	~DirView(){
    		m_refTreeModel->clear();
    		m_refTreeModel.clear();
    	}
    	void row_clicked(const Gtk::TreeModel::Path& path,Gtk::TreeViewColumn* c);
    	//Interoperability with Textbox
    	BOOL cd(Glib::ustring path);
    	Glib::ustring gPath()
    	{return this->current;}
    
    	//static functions
    	inline static std::string vv(std::string x)
    	{
    		std::string temp;
    		for(int i = x.size()-1;i>=0;i--)
    		{
    			temp+=x[i];
    		}
    		return temp;
    	}
    
    	inline static std::string _lookup(std::string);
    
    	static Glib::ustring _getExt(std::string filename)
    	{
    		std::string str ="";
    		for(int i = filename.size()-1;i>0;i--)
    		{
    			if(filename[i] == '.')
    				break;
    			str += filename[i];
    		}
    		str = vv(str);
    
    	}
    };
    
    #endif
    

    dirview.cpp

    #include"dirview.h"
    #include"pathbox.h"
    #include<fstream>
    #include<iostream>
    #include<io.h>
    
    DirView::DirView( PathBox *p , Glib::ustring path)
    {
    	this->current = path;
    	this->ppb = p;
    	//this->set_resize_mode(Gtk::Re
    	if(!createModel())
    	{
    		time_t s;
    		s = time(NULL);
    		this->err.derr = localtime(&s);
    		this->err.ferr = "createModel();";
    		this->err.errC = 1;
    	}
    }
    
    bool DirView::createModel(bool n)
    {
    	this->m_refTreeModel = Gtk::ListStore::create(m_Columns);
    	this->set_model(m_refTreeModel);
    
    	this->fillData();
    
    	if(n)
    	{
    		//TreeView Columns
    		this->append_column("Name", m_Columns.m_col_name);
    		this->append_column("Size", m_Columns.m_col_size);
    		this->append_column("Extension", m_Columns.m_col_ext);
    		this->signal_row_activated().connect(sigc::mem_fun(*this,&DirView::row_clicked));
    	}
    	return true;
    }
    
    void DirView::row_clicked(const Gtk::TreeModel::Path& path,Gtk::TreeViewColumn* c)
    {
    
    	Glib::RefPtr<Gtk::TreeSelection> Selection = this->get_selection();
    	Gtk::TreeModel::iterator iter = Selection->get_selected();
    		if(*iter)
    		{
    			Gtk::TreeModel::Row row = *iter;
    			if(row[m_Columns.m_col_ext] == "DIR")
    			{
    				this->current = this->current + row[m_Columns.m_col_name] + "\\";
    				this->refresh();
    			}
    			std::cout<<row[m_Columns.m_col_name]<<std::endl;
    		}
    }
    
    bool DirView::fillData()
    {
    	if(this->current == "NULL")
    		this->current = "C:\\";
    	DIR *dir;
    	dirent *ent;
    	if((dir = opendir(this->current.c_str()))!=NULL)
    	{
    		while((ent = readdir(dir))!=NULL)
    		{
    			try{
    			Gtk::TreeModel::Row row = *(m_refTreeModel->append());
    			row[m_Columns.m_col_name] = ent->d_name;
    			if(ent->d_type !=16384)
    				row[m_Columns.m_col_size] = this->GetSize(ent->d_name);
    			else
    				row[m_Columns.m_col_size] = 0;
    			row[m_Columns.m_col_ext] = this->getExt(dir,ent);
    			}
    			catch(std::string e)
    			{
    				break;
    			}
    
    		}
    	}
    	closedir(dir);
    	return true;
    }
    
    Glib::ustring DirView::getExt(DIR *dir, dirent *ent)
    {
    	if(ent->d_type == 16384)
    		return "DIR";
    	else
    		return "FILE";
    }
    
    unsigned __int64 DirView::GetSize(std::string name)
    {
    	try{
    		std::string path = this->current.c_str() + name;
    		//muss noch code rein
    		return 1;
    	}
    	catch (std::string err)
    	{
    		std::cout<<"ERROR";
    	}
    
    }
    
    bool DirView::refresh()
    {
    	this->unset_model();
    	m_refTreeModel->clear();
    	m_refTreeModel.clear();
    
    	this->createModel(false);
    	return true;
    }
    
    BOOL DirView::cd(Glib::ustring path)
    {
    	std::cout<<" Teste : "<<path.c_str()<<std::endl; 
    	this->current = path.c_str();
    	this->refresh();
    	return true;
    }
    

    pathbox.h

    #ifndef _PATHBOX_H_
    #define _PATHBOX_H_
    
    #include<iostream>
    #include"dirview.h"
    
    class PathBox : public Gtk::Entry
    {
    private:
    	DirView *pdv;
    	Glib::RefPtr<Gtk::EntryBuffer> tb;
    public:
    	PathBox(DirView &dv, Glib::ustring t)
    	{
    		this->tb = Gtk::EntryBuffer::create();
    		this->tb->set_text(t);
    		this->set_buffer(tb);	
    		pdv = &dv;
    		this->signal_key_release_event().connect(sigc::mem_fun(*this,&PathBox::key_press));
    
    	}
    	bool key_press(GdkEventKey *key)
    	{
    		std::cout<<key->keyval<<std::endl;
    		if((*key).keyval == GDK_Return) 
    			pdv->cd(this->tb->get_text());
    		return true;
    	}
    
    };
    
    #endif
    

    Warum sagt er bei pathbox.h dass vor dem * ein ; fehlt?
    Zeile 11 o.O

    Synthaxfehler DirView

    Warum erkennt er hier kein DirView mehr ?

    Danke schonmal.


Anmelden zum Antworten