boost函数rowclicked是指向函数的指针,该函数返回void并将整数作为参数。我试图为这个指针传递IF条件,基本上说如果rowclicked被激活,我希望分配一些值
boost::function<void(int)> rowClicked;
userClass->getTable()- >rowClicked=boost::bind(&UserController::onCellTableclicked,this);
这是If条件
if(userClass->getTable()->rowClicked)
{
std::cout<<"Row Clicked";
m=i;n=j;
}
}
我做了哪些更改,以便为已经在类构造函数中绑定的boost函数传递IF条件。
userClass->getTable()->rowClicked=boost::bind(&UserController::onCellTableclicked,this);
来自其中一个主要cpp文件的完整代码 :
#include "UserController.h"
// needed to bind the boost function
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include "UserClass.h"
// needed for used classes
#include <SUIButton.h>
#include <SUIProgressBar.h>
#include <SUIDialog.h>
#include <SUILabel.h>
#include <SUIGraphicsView.h>
#include <SUITableWidget.h>
// needed for the timer
#include <SUITimer.h>
//needed for time
#include <SUITime.h>
//needed for date
#include <SUIDate.h>
//needed for date time
#include <SUIDateTime.h>
//void getMonth( int,UserClass*);
//int co=1;
int cou=1;
int m,n;
// needed for output
#include <iostream>
UserController::UserController(UserClass *userClass) :
userClass(userClass), // assign the instance of userClass
timer(SUI::Timer::createTimer()), // instantiate the timer
timeTimer(SUI::Timer::createTimer()),
time(SUI::Time::createTime()),
date(SUI::Date::createDate())
{
// bind the Button clicked callback
userClass->getStartButton()->clicked = boost::bind(&UserController::onStartButtonClicked,this);
userClass->getStopButton()->clicked = boost::bind(&UserController::onStopButtonClicked,this);
// bind the ProgreimeoutssBar valueChanged callback
userClass->getProgressBar()->progressChanged = boost::bind(&UserController::onProgressBarValueChanged,this);
//std::cout<<userClass->getTable()->cellClicked;
//std::cout<<row;
userClass->getTable()->rowClicked=boost::bind(&UserController::onCellTableclicked,this);
//std::cout
userClass->getleftarrow()->clicked=boost::bind(&UserController::onLeftArrowClicked,this);
userClass->getrightarrow()->clicked=boost::bind(&UserController::onRightArrowClicked,this);
// userClass->getimvimage1()->getGraphicsScene()
// setup the timer
timer->setSingleShot(true);
timer->setInterval(100);
timeTimer->setSingleShot(false);
timeTimer->setInterval(1);
// bind the Timer timeout callback
timer->timeout = boost::bind(&UserController::onTimerTimeout,this);
timeTimer->timeout = boost::bind(&UserController::onTimeTimerTimeout,this);
//start the time
time->start();
//initialise date
date->currentDate();
userClass->getDateLabel()->setText(date->toString("dd.MM.yyyy"));
date->setDate(date->getYear(),date->getMonth(),1);
//std::cout<<co;
// std::cout<<date->getDayOfWeek();
//dislay month on calendar label
int mon=date->getMonth();
//enum month={"January"=1,"February","March","April","May","June","July","August","September","October","November","December"};
switch(mon)
{
case 1: userClass->getCalendarLabel()->setText("January");break;
case 2: userClass->getCalendarLabel()->setText("February");break;
case 3: userClass->getCalendarLabel()->setText("March");break;
case 4: userClass->getCalendarLabel()->setText("April");break;
case 5: userClass->getCalendarLabel()->setText("May");break;
case 6: userClass->getCalendarLabel()->setText("June");break;
case 7: userClass->getCalendarLabel()->setText("July");break;
case 8: userClass->getCalendarLabel()->setText("August");break;
case 9: userClass->getCalendarLabel()->setText("September");break;
case 10: userClass->getCalendarLabel()->setText("October");break;
case 11: userClass->getCalendarLabel()->setText("November");break;
case 12: userClass->getCalendarLabel()->setText("December");break;
}
//int mo=date->getMonth();
//getMonth(mo);
userClass->getyearlabel()->setText(std::to_string(date->getYear()));
int c=date->getDayOfWeek();
int count=1;
int i=1;
for(int j=c;j<=6;j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
}
for (int i=2;i<=6;i++)
{
for(int j=0;j<=6 && count<=date->getDaysInMonth();j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
if(count<=date->getDaysInMonth())
continue;
else break;
/* if(userClass->getTable()->rowClicked)
{
std::cout<<"Row Clicked";
m=i;n=j;
}*/
}
}
//userClass->getimvimage1()->getGraphicsScene(GraphicsScene)
//show the dialog
userClass->getDialog()->show();
userClass->getStopButton()->setEnabled(false);
}
UserController::~UserController()
{
delete userClass;
}
void UserController::onStopButtonClicked() {
std::cout << "Stop clicked" << std::endl;
// stop the timers
timer->stop();
timeTimer->stop();
// enable/disable the buttons
userClass->getStopButton()->setEnabled(false);
userClass->getStartButton()->setEnabled(true);
}
void UserController::onProgressBarValueChanged() {
// spam output when the ProgressBar value changed
std::cout << "ProgressBar value changed to: " << userClass->getProgressBar()->getValue() << std::endl;
}
void UserController::onTimerTimeout() {
// when the timer timed out increase the value of the ProgressBar with 1
userClass->getProgressBar()->setValue(userClass->getProgressBar()->getValue() + 1);
// if the ProgressBar value is smaller than 75 restart the timer
if (userClass->getProgressBar()->getValue() < 75)
timer->start();
}
void UserController::onTimeTimerTimeout() {
// every interval, add 1 msec
time->addMSecs(1);
timer->setSingleShot(true);
// set the label text
userClass->getTimeLabel()->setText(time->toString("HH:mm:ss.zzz"));
}
void UserController::onStartButtonClicked() {
// on clicked start the timer
std::cout << "Start clicked" << std::endl;
timer->start();
timeTimer->start();
// restart the time to current time
time->restart();
// enable/disable the buttonsuserClass->getTimeLabel()->setText(time->toString("HH:mm:ss.zzz"));
userClass->getStopButton()->setEnabled(true);
userClass->getStartButton()->setEnabled(false);
}
void UserController::onLeftArrowClicked()
{
std::cout<<"Left Arrow"<<std::endl;
for(int i=1;i<=6;i++)
{
for(int j=0;j<=6;j++)
{
userClass->getTable()->setItemText(i,j," ");
}
}
int mo=date->getMonth()-1;
int year=date->getYear();
if(mo==0)
{
year=date->getYear()-1;
mo=12;
}
date->setDate(year,mo,1);
//std::cout<<mo<<std::endl;
int c=date->getDayOfWeek();
int count=1;
int i=1;
for(int j=c;j<=6;j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
}
for (int i=2;i<=6;i++)
{
for(int j=0;j<=6 && count<=date->getDaysInMonth();j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
if(count<=date->getDaysInMonth())
continue;
else break;
}
}
switch(mo)
{
case 1: userClass->getCalendarLabel()->setText("January");break;
case 2: userClass->getCalendarLabel()->setText("February");break;
case 3: userClass->getCalendarLabel()->setText("March");break;
case 4: userClass->getCalendarLabel()->setText("April");break;
case 5: userClass->getCalendarLabel()->setText("May");break;
case 6: userClass->getCalendarLabel()->setText("June");break;
case 7: userClass->getCalendarLabel()->setText("July");break;
case 8: userClass->getCalendarLabel()->setText("August");break;
case 9: userClass->getCalendarLabel()->setText("September");break;
case 10: userClass->getCalendarLabel()->setText("October");break;
case 11: userClass->getCalendarLabel()->setText("November");break;
case 12: userClass->getCalendarLabel()->setText("December");break;
}
userClass->getyearlabel()->setText(std::to_string(date->getYear()));
}
void UserController::onRightArrowClicked()
{
std::cout<<"Right Arrow"<<std::endl;
for(int i=1;i<=6;i++)
{
for(int j=0;j<=6;j++)
{
userClass->getTable()->setItemText(i,j," ");
}
}
int mo=date->getMonth()+1;
int year=date->getYear();
if(mo==13)
{
year=date->getYear()+1;
mo=1;
}
date->setDate(year,mo,1);
date->setDate(date->getYear(),mo,1);
int c=date->getDayOfWeek();
int count=1;
int i=1;
for(int j=c;j<=6;j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
}
for (int i=2;i<=6;i++)
{
for(int j=0;j<=6 && count<=date->getDaysInMonth();j++)
{
userClass->getTable()->setItemText(i,j,std::to_string(count));
count++;
if(count<=date->getDaysInMonth())
continue;
else break;
}
}
switch(mo)
{
case 1: userClass->getCalendarLabel()->setText("January");break;
case 2: userClass->getCalendarLabel()->setText("February");break;
case 3: userClass->getCalendarLabel()->setText("March");break;
case 4: userClass->getCalendarLabel()->setText("April");break;
case 5: userClass->getCalendarLabel()->setText("May");break;
case 6: userClass->getCalendarLabel()->setText("June");break;
case 7: userClass->getCalendarLabel()->setText("July");break;
case 8: userClass->getCalendarLabel()->setText("August");break;
case 9: userClass->getCalendarLabel()->setText("September");break;
case 10: userClass->getCalendarLabel()->setText("October");break;
case 11: userClass->getCalendarLabel()->setText("November");break;
case 12: userClass->getCalendarLabel()->setText("December");break;
}
userClass->getyearlabel()->setText(std::to_string(date->getYear()));
}
/*void getMonth( int mon,UserClass *userClass)
{
switch(mon)
{
case 1: userClass->getCalendarLabel()->setText(date->toString("January"));break;
case 2: userClass->getCalendarLabel()->setText(date->toString("February"));break;
case 3: userClass->getCalendarLabel()->setText(date->toString("March"));break;
case 4: userClass->getCalendarLabel()->setText(date->toString("April"));break;
case 5: userClass->getCalendarLabel()->setText(date->toString("May"));break;
case 6: userClass->getCalendarLabel()->setText(date->toString("June"));break;
case 7: userClass->getCalendarLabel()->setText(date->toString("July"));break;
case 8: userClass->getCalendarLabel()->setText(date->toString("August"));break;
case 9: userClass->getCalendarLabel()->setText(date->toString("September"));break;
case 10: userClass->getCalendarLabel()->setText(date->toString("October"));break;
case 11: userClass->getCalendarLabel()->setText(date->toString("November"));break;
case 12: userClass->getCalendarLabel()->setText(date->toString("December"));break;
}
}*/
void UserController::onCellTableclicked() {
//date->currentDate();
//std::cout<<(userClass->getTable()->isEnabled());
// std::cout<<"Just Print:"<<cou<<std::endl;
// cou++;
// userClass->getTable()->clearFocus();
// userClass->getTable()->getCellID(int row, int col);
// int day=userClass->getTable()->getItemText(row,col);
//userClass->getTable()->toBaseWidget(this)->getWidget()->setText("Cl");
//ObjectFactory::getInstance()->toBaseWidget(this)->getWidget()->hasFocus();
// getWidget()->currentIndex().row()
//std::cout<<userClass->getTable()->rowClicked();
//std::string day=userClass->getTable()->getItemText(m,n);
userClass->getTable()->
//userClass->getTable()->currentIndex().row();
//std::cout<<getWidget()->currentIndex().row();
//date->setDate(1991,1,std::atoi(day.c_str()));
//userClass->getDateLabel()->setText(date->toString("dd.MM.yyyy"));
//userClass->getTable()->getWidget()->setText("Cl");
}