// **************************************************************************** // copyright (c) 2000-2005 Horst Knorr // This file is part of the hk_kdeclasses library. // This file may be distributed and/or modified under the terms of the // GNU Library Public License version 2 as published by the Free Software // Foundation and appearing in the file LGPL included in the // packaging of this file. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // **************************************************************************** #include "hk_kdesubformdialog.h" #include "hk_kdedbdesigner.h" #include #include #include #include #include #include hk_kdesubformdialog::hk_kdesubformdialog( hk_subform* subform,QWidget* parent, const char* name, bool modal, WFlags fl ) : hk_kderelationdialogbase( parent, name, modal, fl ) { p_subform=subform; p_masterds=p_subform->datasource(); const int w=180; grid->installEventFilter(this); ok_button->installEventFilter(this); cancel_button->installEventFilter(this); grid->setColumnWidth(0,w); grid->setColumnWidth(1,w); p_form=new hk_form(); if (p_masterds)p_form->set_database(p_masterds->database()); p_form->load_form(p_subform->name()); p_slaveds=p_form->datasource(); if (p_masterds) {grid->horizontalHeader()->setLabel(0,QString::fromUtf8(l2u( p_masterds->name()).c_str())); set_stringlist(&p_mastercollist,p_masterds->columns()); } if (p_slaveds) {grid->horizontalHeader()->setLabel(1,QString::fromUtf8( l2u(p_slaveds->name()).c_str())); set_stringlist(&p_slavecollist,p_slaveds->columns()); } add_row(); //ok_button->setEnabled(false); set_existing_fields(); connect(grid,SIGNAL(valueChanged(int,int)),this,SLOT(slot_data_changed(int,int))); } hk_kdesubformdialog::~hk_kdesubformdialog() { delete p_form; } void hk_kdesubformdialog::add_row(void) { //cerr <setNumRows(grid->numRows()+1); grid->setItem(grid->numRows()-1,0,masteritem); grid->setItem(grid->numRows()-1,1,slaveitem); cerr <<"ENDE add_row"<* collist) { cerr <<"set_stringlist"<clear(); strlist->append(""); list::iterator it= collist->begin(); while (it!=collist->end()) { cerr <<"add "<<(*it)->name()<append(QString::fromUtf8(l2u((*it)->name()).c_str())); ++it; } cerr <<"ende set_stringlist"<* l=p_subform->depending_on_fields(); list::iterator it=l->begin(); cerr <<"vor while"<end()) { int masterpos=textposition(&p_mastercollist,(*it).masterfield); if (masterpos>=0)((QComboTableItem*)(grid->item(grid->numRows()-1,0)))->setCurrentItem(masterpos); int dependingpos= textposition(&p_slavecollist,(*it).dependingfield); if (dependingpos>=0)((QComboTableItem*)(grid->item(grid->numRows()-1,1)))->setCurrentItem(dependingpos); cerr <<"master:"<<(*it).masterfield<<" depending:"<<(*it).dependingfield<begin(); it != thelist->end(); ++it ) { cout << *it << " : "; } cout << endl; return thelist->findIndex(QString::fromUtf8(l2u(txt).c_str())); } int hk_kdesubformdialog::masterindex(const QString& string) { cerr <<"masterindex "<clear_depending_fields(); for (int row=0;rownumRows()-1;++row) { hk_string mastertxt=u2l(grid->item(row,0)->text().utf8().data()); hk_string slavetxt=u2l(grid->item(row,1)->text().utf8().data()); if (mastertxt.size()>0 && slavetxt.size()>0) p_subform->add_depending_fields(slavetxt,mastertxt,true); } accept(); } void hk_kdesubformdialog::slot_data_changed(int row, int /*col*/) { if (row==grid->numRows()-1 && grid->item(row,0) && !grid->item(row,0)->text().isEmpty() && !grid->item(row,1)->text().isEmpty()) { add_row(); } } void hk_kdesubformdialog::keyPressEvent(QKeyEvent* /*event*/) { /*if (event->key()==Key_Delete) { delete_rows(); }*/ } void hk_kdesubformdialog::delete_rows(void) { cerr <<"hk_kdesubformdialog::delete_rows"<selection(0).topRow(); int endrow=grid->selection(0).bottomRow(); if (endrow==grid->numRows()-1) --endrow; if (beginrow>-1&&endrow>=beginrow) { QMemArray a(endrow-beginrow+1); int c=0;//cerr <<"a new ="<currentRow()<currentRow()>-1 &&grid->currentRow()numRows()-1) grid->removeRow(grid->currentRow()); } } bool hk_kdesubformdialog::eventFilter(QObject* object,QEvent* e) { QKeyEvent* event=dynamic_cast(e); if (event && event->key()==Qt::Key_Delete && event->type()==QEvent::KeyRelease) { delete_rows(); //event->accept(); return true; } else return hk_kderelationdialogbase::eventFilter(object,e); }