void ConstraintWidget::selectConstraintType(void) { ConstraintType constr_type=ConstraintType(constr_type_cmb->currentText()); tablespace_lbl->setVisible(constr_type==ConstraintType::primary_key || constr_type==ConstraintType::unique); tablespace_sel->setVisible(constr_type==ConstraintType::primary_key || constr_type==ConstraintType::unique); if(!tablespace_sel->isVisible()) tablespace_sel->clearSelector(); expression_lbl->setVisible(constr_type==ConstraintType::check || constr_type==ConstraintType::exclude); expression_txt->setVisible(constr_type==ConstraintType::check || constr_type==ConstraintType::exclude); no_inherit_chk->setVisible(constr_type==ConstraintType::check); no_inherit_lbl->setVisible(constr_type==ConstraintType::check); warn_frm->setVisible(constr_type==ConstraintType::check); /*fill_factor_lbl->setVisible(constr_type==ConstraintType::unique || constr_type==ConstraintType::primary_key || constr_type==ConstraintType::exclude); */ fill_factor_chk->setVisible(constr_type==ConstraintType::unique || constr_type==ConstraintType::primary_key || constr_type==ConstraintType::exclude); fill_factor_sb->setVisible(constr_type==ConstraintType::unique || constr_type==ConstraintType::primary_key || constr_type==ConstraintType::exclude); info_frm->setVisible(constr_type==ConstraintType::primary_key); deferrable_lbl->setVisible(constr_type!=ConstraintType::check); deferrable_chk->setVisible(constr_type!=ConstraintType::check); deferral_cmb->setVisible(constr_type!=ConstraintType::check); deferral_lbl->setVisible(constr_type!=ConstraintType::check); match_lbl->setVisible(constr_type==ConstraintType::foreign_key); match_cmb->setVisible(constr_type==ConstraintType::foreign_key); on_delete_cmb->setVisible(constr_type==ConstraintType::foreign_key); on_delete_lbl->setVisible(constr_type==ConstraintType::foreign_key); on_update_cmb->setVisible(constr_type==ConstraintType::foreign_key); on_update_lbl->setVisible(constr_type==ConstraintType::foreign_key); columns_tbw->setVisible(constr_type!=ConstraintType::check && constr_type!=ConstraintType::exclude); indexing_chk->setVisible(constr_type==ConstraintType::exclude); indexing_cmb->setVisible(constr_type==ConstraintType::exclude); if(constr_type!=ConstraintType::foreign_key) { columns_tbw->setTabEnabled(1, false); columns_tbw->setCurrentIndex(0); ref_table_sel->clearSelector(); } else columns_tbw->setTabEnabled(1, true); excl_elems_grp->setVisible(constr_type==ConstraintType::exclude); }
void ConstraintWidget::selectConstraintType(void) { static QWidget *tab=columns_tbw->widget(1); static QString rot_tab=columns_tbw->tabText(1); ConstraintType tipo_rest=ConstraintType(constr_type_cmb->currentText()); tablespace_lbl->setVisible(tipo_rest==ConstraintType::primary_key || tipo_rest==ConstraintType::unique); tablespace_sel->setVisible(tipo_rest==ConstraintType::primary_key || tipo_rest==ConstraintType::unique); if(!tablespace_sel->isVisible()) tablespace_sel->clearSelector(); check_expr_lbl->setVisible(tipo_rest==ConstraintType::check); check_expr_txt->setVisible(tipo_rest==ConstraintType::check); fill_factor_lbl->setVisible(tipo_rest==ConstraintType::foreign_key || tipo_rest==ConstraintType::primary_key); fill_factor_sb->setVisible(tipo_rest==ConstraintType::foreign_key || tipo_rest==ConstraintType::primary_key); deferrable_lbl->setVisible(tipo_rest==ConstraintType::foreign_key); deferrable_chk->setVisible(tipo_rest==ConstraintType::foreign_key); deferral_cmb->setVisible(tipo_rest==ConstraintType::foreign_key); deferral_lbl->setVisible(tipo_rest==ConstraintType::foreign_key); match_lbl->setVisible(tipo_rest==ConstraintType::foreign_key); match_cmb->setVisible(tipo_rest==ConstraintType::foreign_key); on_delete_cmb->setVisible(tipo_rest==ConstraintType::foreign_key); on_delete_lbl->setVisible(tipo_rest==ConstraintType::foreign_key); on_update_cmb->setVisible(tipo_rest==ConstraintType::foreign_key); on_update_lbl->setVisible(tipo_rest==ConstraintType::foreign_key); columns_tbw->setVisible(tipo_rest!=ConstraintType::check); if(tipo_rest!=ConstraintType::foreign_key) columns_tbw->removeTab(1); else columns_tbw->addTab(tab, rot_tab); }
void ConstraintWidget::applyConfiguration(void) { try { Constraint *constr=nullptr; unsigned i, col_id, count; Column *column=nullptr; ObjectTableWidget *aux_col_tab=nullptr; vector<ExcludeElement> excl_elems; startConfiguration<Constraint>(); constr=dynamic_cast<Constraint *>(this->object); constr->setConstraintType(ConstraintType(constr_type_cmb->currentText())); constr->setExpression(expression_txt->toPlainText().toUtf8()); if(fill_factor_chk->isChecked()) constr->setFillFactor(fill_factor_sb->value()); else constr->setFillFactor(0); constr->setMatchType(MatchType(match_cmb->currentText())); constr->setDeferrable(deferrable_chk->isChecked()); constr->setDeferralType(DeferralType(deferral_cmb->currentText())); constr->setActionType(ActionType(on_delete_cmb->currentText()),Constraint::DELETE_ACTION); constr->setActionType(ActionType(on_update_cmb->currentText()),Constraint::UPDATE_ACTION); constr->setNoInherit(no_inherit_chk->isChecked()); if(indexing_chk->isChecked()) constr->setIndexType(IndexingType(indexing_cmb->currentText())); else constr->setIndexType(BaseType::null); if(constr->getConstraintType()==ConstraintType::foreign_key) constr->setReferencedTable(dynamic_cast<BaseTable *>(ref_table_sel->getSelectedObject())); constr->removeColumns(); for(col_id=Constraint::SOURCE_COLS; col_id <= Constraint::REFERENCED_COLS; col_id++) { aux_col_tab=(col_id==Constraint::SOURCE_COLS ? columns_tab : ref_columns_tab); count=aux_col_tab->getRowCount(); for(i=0; i < count; i++) { column=reinterpret_cast<Column *>(aux_col_tab->getRowData(i).value<void *>()); constr->addColumn(column, col_id); } } excl_elems_wgt->getElements(excl_elems); constr->addExcludeElements(excl_elems); //Raises an error if the user try to create a primary key that has columns added by relationship (not supported) if(constr->getConstraintType()==ConstraintType::primary_key && constr->isReferRelationshipAddedColumn()) throw Exception(ERR_PK_USING_COLS_ADDED_BY_REL,__PRETTY_FUNCTION__,__FILE__,__LINE__); BaseObjectWidget::applyConfiguration(); /* Raises an error if the constraint type requires at least one column to be assinged and there is no columns configured on the form */ if(((constr->getConstraintType()==ConstraintType::foreign_key || constr->getConstraintType()==ConstraintType::primary_key) && constr->getColumnCount(Constraint::SOURCE_COLS)==0) || (constr->getConstraintType()==ConstraintType::foreign_key && constr->getColumnCount(Constraint::REFERENCED_COLS)==0)) throw Exception(ERR_CONSTR_NO_COLUMNS,__PRETTY_FUNCTION__,__FILE__,__LINE__); finishConfiguration(); //For the foreign keys, updates the fk relationships on the model if(constr->getConstraintType()==ConstraintType::foreign_key) this->model->updateTableFKRelationships(dynamic_cast<Table *>(this->table)); } catch(Exception &e) { Messagebox msg_box; cancelConfiguration(); msg_box.show(e); } }
void ConstraintWidget::applyConfiguration(void) { try { Constraint *constr=NULL; unsigned i, col_id, count; Column *column=NULL; ObjectTableWidget *aux_col_tab=NULL; startConfiguration<Constraint>(); constr=dynamic_cast<Constraint *>(this->object); constr->setConstraintType(ConstraintType(constr_type_cmb->currentText())); constr->setCheckExpression(check_expr_txt->toPlainText().toUtf8()); constr->setFillFactor(fill_factor_sb->value()); constr->setMatchType(MatchType(match_cmb->currentText())); constr->setDeferrable(deferrable_chk->isChecked()); constr->setDeferralType(DeferralType(deferral_cmb->currentText())); constr->setActionType(ActionType(on_delete_cmb->currentText()),false); constr->setActionType(ActionType(on_update_cmb->currentText()),true); if(constr->getConstraintType()==ConstraintType::foreign_key) constr->setReferencedTable(ref_table_sel->getSelectedObject()); constr->removeColumns(); for(col_id=Constraint::SOURCE_COLS; col_id <= Constraint::REFERENCED_COLS; col_id++) { aux_col_tab=(col_id==Constraint::SOURCE_COLS ? columns_tab : ref_columns_tab); count=aux_col_tab->getRowCount(); for(i=0; i < count; i++) { column=reinterpret_cast<Column *>(aux_col_tab->getRowData(i).value<void *>()); constr->addColumn(column, col_id); } } BaseObjectWidget::applyConfiguration(); /* Raises an error if the constraint type requires at least one column to be assinged and there is no columns configured on the form */ if(((constr->getConstraintType()==ConstraintType::foreign_key || constr->getConstraintType()==ConstraintType::primary_key) && constr->getColumnCount(Constraint::SOURCE_COLS)==0) || (constr->getConstraintType()==ConstraintType::foreign_key && constr->getColumnCount(Constraint::REFERENCED_COLS)==0)) throw Exception(ERR_CONSTR_NO_COLUMNS,__PRETTY_FUNCTION__,__FILE__,__LINE__); finishConfiguration(); //For the foreign keys, updates the fk relationships on the model if(constr->getConstraintType()==ConstraintType::foreign_key) this->model->updateTableFKRelationships(this->table); } catch(Exception &e) { MessageBox msg_box; cancelConfiguration(); msg_box.show(e); } }