Новичок
Профиль
Группа: Участник
Сообщений: 17
Регистрация: 4.10.2006
Репутация: нет Всего: нет
|
Код | #include "createank.h" #include <qlabel.h> #include <qpushbutton.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qmessagebox.h> #include <qregexp.h> #include <qlineedit.h> #include <qvbuttongroup.h> #include <qhbuttongroup.h> #include <qradiobutton.h> #include <qcheckbox.h> #include <qobjectlist.h> #include <qvbox.h> #include <qscrollview.h> #include <stdio.h> #include <qcombobox.h> #include "MainWidget.h"
extern int IdAnk; void CreateAnk::dro(char *table,int index,QGridLayout *parent,int *x, int *y, int main_y,QWidget *qo) { QString elem_child; MySQLConnect connect; char mas[1000]; char name[100]; if(TypeOperation==1 || TypeOperation==2) sprintf(mas,"select * from %s where id_conteyner = %d",table,index); if(TypeOperation==3) sprintf(mas,"select id_conteyner,name,cols,rows,child,type,typeank,close_table,open_table,tr,message from %s where id_conteyner = %d and id = %d",table,index,AnkType); connect.query(mas); connect.next_row(); connect.row_index(mas,8); int open_table = atoi(mas); int count_cols; connect.row_index(mas,2); count_cols = atoi(mas); count_cols = count_cols==0?1:count_cols; int count_rows; connect.row_index(mas,3); count_rows = atoi(mas); count_rows = count_rows==0?1:count_rows;
QGridLayout *Layout; if(open_table==1) {
Layout = new QGridLayout(qo,count_cols,count_rows,5,5); parent->addLayout((QLayout*)Layout,*y,*x); *x=0;*y=0; parent=Layout; } //выделим первый номер из списка дочерних connect.row_index(mas,4); QString child=mas; int zap_poz = child.find(","); if(zap_poz==-1) { elem_child=child.left(zap_poz); child=""; } else { elem_child=child.left(zap_poz); child = child.right(child.length()-zap_poz-1); } if(child.isEmpty()) {//выводим элементы int answer; //получаем ответ if(TypeOperation==2) { MySQLConnect temp_connect;
sprintf(mas,"select * from answer where id_cont = %s and id_org=%d and typeank= %d",elem_child.ascii(),AnkOrg,AnkType); temp_connect.query(mas); if(temp_connect.count()>0) { temp_connect.next_row(); temp_connect.row_index(mas,2); answer = atoi(mas); } else { answer = 0; } } connect.row_index(mas,5); int type = atoi(mas); if(type==2) {
QLineEdit *le = new QLineEdit(qo,elem_child); if(TypeOperation==2) { sprintf(mas,"%d",answer); le->setText(mas); } parent->addWidget(le,*y,*x); if(main_y>=poz && main_y<(poz+COUNT_VIEW)) { le->show(); } else { le->hide(); } } if(type==30)//горизонталные радиобатаны { //тут будут группироваться переключатели QHButtonGroup *hgr = new QHButtonGroup("Chouse",qo); connect.row_index(mas,2); int count_radio = atoi(mas); for(int i=0;i<count_radio;i++) { MySQLConnect temp_connect; connect.row_index(mas,10);//message QString temp = mas; QStringList list = QStringList::split(",",temp);
int name_index = atoi(mas); char mas_temp[1000]; sprintf(mas_temp,"select message from message where id = %s",list[i].ascii()); temp_connect.query("set Names cp1251;"); temp_connect.query(mas_temp); temp_connect.next_row(); temp_connect.row_index(mas,0);
sprintf(name,"%s_%d",elem_child.ascii(),i); QRadioButton *qr = new QRadioButton(QString::fromLocal8Bit(mas),hgr,name); if(i==answer) qr->setChecked(TRUE); } parent->addWidget(hgr,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { hgr->show(); } else { hgr->hide(); } //QObject::connect(hgr,SIGNAL(clicked),this,SLOT(RadioClicked(int))); } if(type==4 || type==3)//вертикльные радиобатаны { //тут будут группироваться переключатели QButtonGroup *hgr; if(type==4) hgr = new QVButtonGroup("Chouse",qo); if(type==3) hgr = new QHButtonGroup("Chouse",qo); connect.row_index(mas,2); int count_radio = atoi(mas);
for(int i=0;i<count_radio;i++) { if(TypeOperation==1 || TypeOperation==2)//заполняем анкету или просмотр { MySQLConnect temp_connect; connect.row_index(mas,10);//message QString temp = mas; QStringList list = QStringList::split(",",temp);
int name_index = atoi(mas); char mas_temp[1000]; sprintf(mas_temp,"select message from message where id = %s",list[i].ascii()); temp_connect.query("set Names cp1251;"); temp_connect.query(mas_temp); temp_connect.next_row(); temp_connect.row_index(mas,0);
sprintf(name,"%s_%d",elem_child.ascii(),i); QRadioButton *qr=new QRadioButton(QString::fromLocal8Bit(mas),hgr,name); if(i==answer) qr->setChecked(TRUE); } if(TypeOperation==3) { sprintf(name,"%s_%d_t",elem_child.ascii(),i); QLineEdit *le = new QLineEdit(hgr,name); sprintf(name,"%s_%d",elem_child.ascii(),i); QRadioButton *qr=new QRadioButton("123",hgr,name);
} }
//выведем свои варианты ответа if(TypeOperation==1 || TypeOperation==2) { connect.row_index(mas,12); //my_count for(int j=i;j<i+atoi(mas);j++) { sprintf(name,"%s_%d_t",elem_child.ascii(),j); QLineEdit *le = new QLineEdit(hgr,name); if(TypeOperation==2) { MySQLConnect ttemp_connect; int name_index = atoi(elem_child); char mas_temp[1000]; sprintf(mas_temp,"select value from answer_message where id_cont = %d and id_org=%d and typeank= %d",name_index,AnkOrg,AnkType); ttemp_connect.query("set Names cp1251;"); ttemp_connect.query(mas_temp); ttemp_connect.next_row(); ttemp_connect.row_index(mas_temp,0); le->setText(mas_temp); }
sprintf(name,"%s_%d",elem_child.ascii(),j); QRadioButton *qr=new QRadioButton("123",hgr,name); if(j==answer) qr->setChecked(TRUE);
} } parent->addWidget(hgr,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { hgr->show(); } else { hgr->hide(); } //QObject::connect(hgr,SIGNAL(clicked),this,SLOT(RadioClicked(int))); } if(type==6)//просто текст { QLabel *lbl = new QLabel(elem_child,qo,elem_child); parent->addWidget(lbl,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { lbl->show(); } else { lbl->hide(); } }
if(type==5)//чекбоксы { if(TypeOperation==1 || TypeOperation==2) connect.row_index(mas,13); if(TypeOperation==3) strcpy(mas,"1"); if(atoi(mas)==1) { QHButtonGroup *hgr = new QHButtonGroup("",qo); sprintf(name,"%s_t",elem_child.ascii()); QLineEdit *le = new QLineEdit(hgr,name); if(TypeOperation==2) { MySQLConnect temp_connect; int name_index = atoi(elem_child); char mas_temp[1000]; sprintf(mas_temp,"select value from answer_message where id_cont = %d and id_org=%d and typeank= %d",name_index,AnkOrg,AnkType); temp_connect.query("set Names cp1251;"); temp_connect.query(mas_temp); temp_connect.next_row(); temp_connect.row_index(mas,0);
le->setText(mas); } sprintf(name,"%s",elem_child.ascii()); QCheckBox *chb = new QCheckBox("",hgr,name); if(answer) chb->setChecked(TRUE); parent->addWidget(hgr,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { hgr->show(); } else { hgr->hide(); } } else { MySQLConnect temp_connect; connect.row_index(mas,10);//message int name_index = atoi(mas); char mas_temp[1000]; sprintf(mas_temp,"select message from message where id = %d",name_index); temp_connect.query("set Names cp1251;"); temp_connect.query(mas_temp); temp_connect.next_row(); temp_connect.row_index(mas,0); QCheckBox *chb = new QCheckBox(QString::fromLocal8Bit(mas),qo,elem_child); if(answer) chb->setChecked(TRUE); parent->addWidget(chb,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { chb->show(); } else { chb->hide(); } }
}
if(type==8) { QLineEdit *le = new QLineEdit(qo,elem_child); parent->addWidget(le,*y,*x); if(main_y>=poz && main_y<poz+COUNT_VIEW) { le->show(); } else { le->hide(); } } (*x)++; elem_child=""; }
while(!elem_child.isEmpty()) { dro(table,elem_child.toInt(),Layout,x,y,main_y,qo); zap_poz = child.find(","); elem_child=child.left(zap_poz); child = child.right(child.length()-zap_poz-1); if(child=="0") child=""; }
connect.row_index(mas,9); int tr = atoi(mas); if(tr == 1) { (*y)++; (*x)=0; }
}
CreateAnk::CreateAnk(char *_table,int Org,int type, int typeank,int _count_view,int _poz, QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { AnkType=typeank; COUNT_VIEW = _count_view; TypeOperation = type; poz=_poz; AnkOrg=Org; strcpy(table,_table); if ( !name ) setName( "CreateAnk" ); setGeometry(5,5,100,100); //resize( 515, 285 );
//setMinimumSize( 200, 120 ); //setMaximumSize( 200, 120 ); setFixedSize(600,600); setProperty( "caption", tr( "CreateAnk" ) ); setProperty( "sizeGripEnabled", QVariant( TRUE, 0 ) );
DrawAnk(); // signals and slots connections }
/* * Destroys the object and frees any allocated resources */ CreateAnk::~CreateAnk() { // no need to delete child widgets, Qt does it all for us }
void CreateAnk::DrawAnk() { MySQLConnect *connect = new MySQLConnect; connect->query("set Names cp1251;"); //получаем вопросы, относящиеся к данному типу анкеты char mas[1000]; char mas_name[100]; int index=AnkType; if(TypeOperation==1 || TypeOperation==2)//это случай просмотра и создания анкеты. необходимо выбирать номера вопросов { sprintf(mas,"select * from typeank_in where id=%d ;",index);//формируем запрос connect->query(mas); if(connect->error==1) QMessageBox::about(this,"Error","can not select question for anket");
connect->next_row(); connect->row_index(mas,1); QString str = mas; QStringList list = QStringList::split(",",str); str = "select * from cont where id_conteyner in ("; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { str.append(*it); str.append(","); }
str.remove(str.length()-1,1);
str.append(") order by number");
connect->query(str.ascii()); } if(TypeOperation==3) { sprintf(mas,"select id_conteyner,name from template where id = %d ",AnkType); connect->query(mas); } if(connect->error==1) QMessageBox::about(this,"Error","can not select question"); x=0; y =0; CountQuestion = connect->count();
x=0; y =0; MainLayout = new QGridLayout(this,connect->count(),2,0,0);//создаётся главный лайоут, в него в функции dro напихивается ещё куча таких. ВОт его и нужно прикрутить к прокрутке MainLayout->setResizeMode(QLayout::Minimum); //MainLayout->setResizeMode(QLayout::Minimum); //poz =; int main_y=0;
while (connect->next_row()) { //вывели название вопроса connect->row_index(mas,1); if(TypeOperation == 1 || TypeOperation==2) { sprintf(mas_name,"%d_l",main_y); QLabel *lbl = new QLabel(QString::fromLocal8Bit(mas),this,mas_name); if(main_y>=poz && main_y<poz+COUNT_VIEW) { lbl->show(); } else { lbl->hide(); } MainLayout->addWidget(lbl,main_y,x); } if(TypeOperation == 3) { MainEdit = new QLineEdit(this,"MainEdit"); if(main_y>=poz && main_y<poz+COUNT_VIEW) { MainEdit->show(); } else { MainEdit->hide(); } MainLayout->addWidget(MainEdit,main_y,x); }
x++; //определим индекс вопроса connect->row_index(mas,0); int index; index = atoi(mas); y=main_y; dro(table,index,MainLayout,&x,&y,main_y,this); x=0; main_y++;
}
//QMessageBox::about(this,"Error",str); save = new QPushButton("Save",this); MainLayout->addWidget(save,main_y,0);
QGridLayout *Layout; Layout = new QGridLayout(this,1,2,5,5);
next = new QPushButton("Next",this); pred = new QPushButton("Pred",this); Layout->addWidget(pred,0,0); Layout->addWidget(next,0,1);
MainLayout->addLayout((QLayout*)Layout,main_y,1);
QObject::connect(save,SIGNAL(clicked()),this,SLOT(Save())); QObject::connect(next,SIGNAL(clicked()),this,SLOT(NextSlot())); QObject::connect(pred,SIGNAL(clicked()),this,SLOT(PredSlot()));
if(TypeOperation == 1) { sprintf(mas,"insert into ank values(%d,%d,'2006-10-06');",AnkOrg, AnkType); connect->query(mas); }
}
|
Суть кода такова. Имеется Лайоут, в него помещается много виджетов. Для форматирования эти же виджеты помещаются в лайоуты. И вот всё это дело надо прокрутить. Пока я сделал так. Я вывожу всё что есть, а потом hide делаю для тех элементов, которые не влазят . Потом при прокрутке увеличиваю текущую позицию, показываю предыдущие элементы и прячу опять не нужные. Программа при этом тормозит конкретно, окно перерисовывается дай боже. Весь код выложить не могу. Он очень большой. Просто вообще было бы интересно узнать, как сделать прокрутку Layout. В нете ничё не нашёл на эту тему. Вопрос такой ставили куча людей, а ответа на него не нашёл. Пишется всё на Qt3. Спасибо за поддержку.
|