Skip to content

Commit 624d1c0

Browse files
committed
Added an checkbox popup in ModelDatabaseDiffForm so the user can select
the object types to be forcibly re-created. Added other minor UI adjustments in ModelDatabaseDiffForm
1 parent 6aa3e44 commit 624d1c0

File tree

11 files changed

+126
-86
lines changed

11 files changed

+126
-86
lines changed

assets/conf/diff-presets.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
import-ext-objs="false"
2121
ignore-import-errors="false"
2222
ignore-duplic-errors="false"
23-
run-in-transaction="true"/>
23+
run-in-transaction="true"
24+
match-by-signature="true"
25+
only-matching="true"
26+
forced-filtering="constraint,rule,trigger,index,policy"/>
2427
</diff-presets>

assets/conf/dtd/diff-presets.dtd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
<!ATTLIST preset match-by-signature (false|true) "true">
3131
<!ATTLIST preset only-matching (false|true) "true">
3232
<!ATTLIST preset forced-filtering CDATA #IMPLIED>
33+
<!ATTLIST preset force-objs-re-creation CDATA #IMPLIED>

assets/conf/schemas/preset.sch

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
{spacer} ignore-duplic-errors="{ignore-duplic-errors}"
3838
{spacer} run-in-transaction="{run-in-transaction}"
3939

40+
%if {force-objs-re-creation} %then
41+
{spacer} force-objs-re-creation="{force-objs-re-creation}"
42+
%end
43+
4044
%if {ignore-error-codes} %then
4145
{spacer} ignore-error-codes="{ignore-error-codes}"
4246
%end

libs/libgui/src/tools/modeldatabasediffform.cpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@
2727
bool ModelDatabaseDiffForm::low_verbosity {false};
2828
std::map<QString, attribs_map> ModelDatabaseDiffForm::config_params;
2929

30+
const QString ModelDatabaseDiffForm::ForceObjsBtnLabel { QT_TR_NOOP("Force re-creation (%1)") };
31+
3032
ModelDatabaseDiffForm::ModelDatabaseDiffForm(QWidget *parent, Qt::WindowFlags flags) : BaseConfigWidget (parent)
3133
{
3234
setupUi(this);
3335
setWindowFlags(flags);
3436

35-
obj_types_wgt = new ObjectTypesListWidget(this, { ObjectType::Column, ObjectType::Constraint,
36-
ObjectType::Relationship, ObjectType::Permission });
37+
forced_obj_types_wgt = new ObjectTypesListWidget(this, { /* ObjectType::Column, ObjectType::Constraint, */
38+
ObjectType::Relationship, ObjectType::Permission,
39+
ObjectType::Database, ObjectType::Tag,
40+
ObjectType::Textbox, ObjectType::GenericSql });
41+
forced_obj_types_wgt->setTypesCheckState(Qt::Unchecked);
3742

3843
QWidgetAction *wgt_act = new QWidgetAction(this);
39-
wgt_act->setDefaultWidget(obj_types_wgt);
44+
wgt_act->setDefaultWidget(forced_obj_types_wgt);
4045

41-
QMenu *obj_types_menu = new QMenu(this);
42-
obj_types_menu->addAction(wgt_act);
43-
filter_objs_types_tb->setMenu(obj_types_menu);
46+
QMenu *forced_obj_types_menu = new QMenu(this);
47+
forced_obj_types_menu->addAction(wgt_act);
48+
forced_objs_types_tb->setMenu(forced_obj_types_menu);
4449

4550
src_server_supported = server_supported = true;
4651
pg_version_alert_frm->setVisible(false);
@@ -142,6 +147,8 @@ ModelDatabaseDiffForm::ModelDatabaseDiffForm(QWidget *parent, Qt::WindowFlags fl
142147
connect(ignore_tb, &QToolButton::toggled, this, &ModelDatabaseDiffForm::filterDiffInfos);
143148
connect(ignore_error_codes_chk, &QCheckBox::toggled, error_codes_edt, &QLineEdit::setEnabled);
144149
connect(src_model_rb, &QRadioButton::toggled, src_model_name_lbl, &QLabel::setEnabled);
150+
connect(src_model_rb, &QRadioButton::toggled, src_model_name_edt, &QLabel::setEnabled);
151+
145152

146153
connect(src_connections_cmb, &QComboBox::activated, this, __slot(this, ModelDatabaseDiffForm::listDatabases));
147154
connect(src_database_cmb, &QComboBox::currentIndexChanged, this, &ModelDatabaseDiffForm::enableDiffMode);
@@ -185,7 +192,17 @@ ModelDatabaseDiffForm::ModelDatabaseDiffForm(QWidget *parent, Qt::WindowFlags fl
185192
GuiUtilsNs::populateObjectsTable(filtered_objs_view, std::vector<attribs_map>());
186193
});
187194

188-
connect(force_objs_recreation_chk, &QCheckBox::toggled, filter_objs_types_tb, &QToolButton::setEnabled);
195+
connect(forced_obj_types_wgt, &ObjectTypesListWidget::s_typesCheckStateChanged, this, [this](Qt::CheckState) {
196+
forced_objs_types_tb->setText(ForceObjsBtnLabel
197+
.arg(forced_obj_types_wgt->
198+
getTypesCountPerCheckState(Qt::Checked)));
199+
});
200+
201+
connect(forced_obj_types_wgt, &ObjectTypesListWidget::s_typeCheckStateChanged, this, [this](ObjectType, Qt::CheckState) {
202+
forced_objs_types_tb->setText(ForceObjsBtnLabel
203+
.arg(forced_obj_types_wgt->
204+
getTypesCountPerCheckState(Qt::Checked)));
205+
});
189206

190207
#ifdef DEMO_VERSION
191208
#warning "DEMO VERSION: forcing ignore errors in diff."
@@ -219,18 +236,19 @@ void ModelDatabaseDiffForm::setModelWidget(ModelWidget *model_wgt)
219236
{
220237
if(model_wgt)
221238
{
222-
QString filename = QFileInfo(model_wgt->getFilename()).fileName();
223-
source_model=loaded_model=model_wgt->getDatabaseModel();
224-
src_model_name_lbl->setText(QString("%1 [%2]").arg(source_model->getName()).arg(filename.isEmpty() ? tr("not saved") : filename));
225-
src_model_name_lbl->setToolTip(model_wgt->getFilename().isEmpty() ? tr("Model not saved yet") : model_wgt->getFilename());
239+
source_model = loaded_model = model_wgt->getDatabaseModel();
240+
src_model_name_lbl->setText(source_model->getName());
241+
src_model_name_edt->setText(QString("%1").arg(model_wgt->getFilename().isEmpty() ? tr("(not yet saved to a file)") : model_wgt->getFilename()));
226242
}
227243
else
228244
{
229245
src_model_name_lbl->setText(tr("(none)"));
230-
src_model_name_lbl->setToolTip("");
246+
src_model_name_edt->setText(tr("(none)"));
231247
src_database_rb->setChecked(true);
232248
src_model_rb->setEnabled(false);
233249
}
250+
251+
src_model_name_edt->setCursorPosition(0);
234252
}
235253

236254
void ModelDatabaseDiffForm::setLowVerbosity(bool value)
@@ -705,9 +723,8 @@ void ModelDatabaseDiffForm::diffModels()
705723
diff_helper->setDiffOption(ModelsDiffHelper::OptPreserveDbName, preserve_db_name_chk->isChecked());
706724
diff_helper->setDiffOption(ModelsDiffHelper::OptDontDropMissingObjs, dont_drop_missing_objs_chk->isChecked());
707725
diff_helper->setDiffOption(ModelsDiffHelper::OptDropMissingColsConstr, drop_missing_cols_constr_chk->isChecked());
708-
diff_helper->setDiffOption(ModelsDiffHelper::OptForceRecreation, force_objs_recreation_chk->isChecked());
709726

710-
diff_helper->setForcedRecreateTypes(obj_types_wgt->getTypesPerCheckState(Qt::Checked));
727+
diff_helper->setForcedRecreateTypes(forced_obj_types_wgt->getTypesPerCheckState(Qt::Checked));
711728
diff_helper->setModels(source_model, imported_model);
712729

713730
/* If the user has chosen diff between a model and database
@@ -1287,6 +1304,12 @@ void ModelDatabaseDiffForm::selectPreset()
12871304
ignore_error_codes_chk->setChecked(!conf[Attributes::IgnoreErrorCodes].isEmpty());
12881305
error_codes_edt->setText(conf[Attributes::IgnoreErrorCodes]);
12891306

1307+
forced_obj_types_wgt->blockSignals(true);
1308+
forced_obj_types_wgt->setTypesCheckState(Qt::Unchecked);
1309+
forced_obj_types_wgt->blockSignals(false);
1310+
1311+
forced_obj_types_wgt->setTypeNamesCheckState(conf[Attributes::ForceObjsReCreation].split(','), Qt::Checked);
1312+
12901313
/* Compatibility with previous versions of diff-presets.conf
12911314
* We configure diff filters only when one of the attributes related
12921315
* to them is present */
@@ -1312,7 +1335,7 @@ void ModelDatabaseDiffForm::togglePresetConfiguration(bool toggle, bool is_edit)
13121335
edit_preset_tb->setVisible(!toggle);
13131336
remove_preset_tb->setVisible(!toggle);
13141337
preset_name_edt->clear();
1315-
save_preset_tb->setEnabled(toggle && (is_edit && presets_cmb->count() > 0));
1338+
//save_preset_tb->setEnabled(toggle && (is_edit && presets_cmb->count() > 0));
13161339

13171340
if(is_edit)
13181341
preset_name_edt->setText(presets_cmb->currentText());
@@ -1399,6 +1422,7 @@ void ModelDatabaseDiffForm::savePreset()
13991422
conf[Attributes::IgnoreImportErrors] = ignore_errors_chk->isChecked() ? Attributes::True : Attributes::False;
14001423
conf[Attributes::IgnoreErrorCodes] = error_codes_edt->text();
14011424
conf[Attributes::RunInTransaction] = run_in_transaction_chk->isChecked() ? Attributes::True : Attributes::False;
1425+
conf[Attributes::ForceObjsReCreation] = forced_obj_types_wgt->getTypeNamesPerCheckState(Qt::Checked).join(',');
14021426

14031427
conf[Attributes::MatchBySignature] = pd_filter_wgt->isMatchBySignature() ? Attributes::True : Attributes::False;
14041428
conf[Attributes::OnlyMatching] = pd_filter_wgt->isOnlyMatching() ? Attributes::True : Attributes::False;
@@ -1432,8 +1456,9 @@ void ModelDatabaseDiffForm::enablePartialDiff()
14321456

14331457
if(src_model_rb->isChecked())
14341458
{
1435-
pd_input_lbl->setText(QString("<strong>%1</strong>").arg(src_model_name_lbl->text()));
1436-
pd_input_lbl->setToolTip(src_model_name_lbl->toolTip());
1459+
pd_input_lbl->setText(QString("<strong>%1 [%2]</strong>").arg(src_model_name_lbl->text(),
1460+
QFileInfo(src_model_name_edt->text()).fileName()));
1461+
pd_input_lbl->setToolTip(src_model_name_edt->text());
14371462
pd_input_ico_lbl->setPixmap(QPixmap(GuiUtilsNs::getIconPath("dbmodel")));
14381463
}
14391464
else if(src_database_cmb->currentIndex() > 0)

libs/libgui/src/tools/modeldatabasediffform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ class __libgui ModelDatabaseDiffForm: public BaseConfigWidget, public Ui::ModelD
5757

5858
static std::map<QString, attribs_map> config_params;
5959

60+
static const QString ForceObjsBtnLabel;
61+
6062
QEventLoop event_loop;
6163

6264
bool is_adding_new_preset;
6365

6466
NumberedTextEditor *sqlcode_txt;
6567

66-
ObjectTypesListWidget *obj_types_wgt;
68+
ObjectTypesListWidget *forced_obj_types_wgt;
6769

6870
FileSelectorWidget *file_sel;
6971

libs/libgui/src/tools/modelsdiffhelper.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ ModelsDiffHelper::ModelsDiffHelper()
5757
diff_opts[OptPreserveDbName]=true;
5858
diff_opts[OptDontDropMissingObjs]=false;
5959
diff_opts[OptDropMissingColsConstr]=false;
60-
diff_opts[OptForceRecreation]=false;
6160
}
6261

6362
ModelsDiffHelper::~ModelsDiffHelper()
@@ -67,7 +66,7 @@ ModelsDiffHelper::~ModelsDiffHelper()
6766

6867
void ModelsDiffHelper::setDiffOption(DiffOptions opt_id, bool value)
6968
{
70-
if(opt_id > OptForceRecreation)
69+
if(opt_id > OptDropMissingColsConstr)
7170
throw Exception(ErrorCode::RefElementInvalidIndex,__PRETTY_FUNCTION__,__FILE__,__LINE__);
7271

7372
if(opt_id == OptDropMissingColsConstr)
@@ -527,7 +526,7 @@ void ModelsDiffHelper::diffModels(ObjectsDiffInfo::DiffType diff_type)
527526
generateDiffInfo(ObjectsDiffInfo::AlterObject, object, aux_object);
528527

529528
//If the object is a table, do additional comparision between their child objects
530-
if(!diff_opts[OptForceRecreation] &&
529+
if(!isForcedRecreateType(object->getObjectType()) &&
531530
PhysicalTable::isPhysicalTable(object->getObjectType()))
532531
{
533532
PhysicalTable *tab=dynamic_cast<PhysicalTable *>(object),
@@ -664,7 +663,8 @@ void ModelsDiffHelper::generateDiffInfo(ObjectsDiffInfo::DiffType diff_type, Bas
664663

665664
/* If the info is for ALTER and there is a DROP info on the list,
666665
* the object will be recreated instead of modified */
667-
if((!diff_opts[OptForceRecreation] || diff_opts[OptRecreateUnmodifiable]) &&
666+
if((!isForcedRecreateType(object->getObjectType()) ||
667+
diff_opts[OptRecreateUnmodifiable]) &&
668668
diff_type == ObjectsDiffInfo::AlterObject &&
669669
isDiffInfoExists(ObjectsDiffInfo::DropObject, old_object, nullptr) &&
670670
!isDiffInfoExists(ObjectsDiffInfo::CreateObject, object, nullptr))
@@ -770,7 +770,7 @@ void ModelsDiffHelper::generateDiffInfo(ObjectsDiffInfo::DiffType diff_type, Bas
770770

771771
/* If the info is for DROP, generate the drop for referer objects of the
772772
* one marked to be dropped */
773-
if((diff_opts[OptForceRecreation] ||
773+
if((isForcedRecreateType(object->getObjectType()) ||
774774
diff_opts[OptRecreateUnmodifiable]
775775
/* diff_opts[OptReplaceModified] */) &&
776776
diff_type == ObjectsDiffInfo::DropObject)
@@ -990,7 +990,7 @@ void ModelsDiffHelper::processDiffInfos()
990990
else if(diff_type == ObjectsDiffInfo::AlterObject)
991991
{
992992
QString obj_sql, old_obj_sql;
993-
bool is_forced_create = diff_opts[OptForceRecreation] && isForcedRecreateType(object->getObjectType()),
993+
bool is_forced_create = isForcedRecreateType(object->getObjectType()),
994994
is_recreate_unmod = diff_opts[OptRecreateUnmodifiable] && !object->acceptsAlterCommand(),
995995
is_replace_mod = diff_opts[OptReplaceModified] && object->acceptsReplaceCommand();
996996

@@ -1242,7 +1242,6 @@ void ModelsDiffHelper::recreateObject(BaseObject *object, std::vector<BaseObject
12421242
}
12431243

12441244
//Get all references to the retrieved object on the database
1245-
//imported_model->getObjectReferences(aux_obj, ref_objs, false, true);
12461245
ref_objs = aux_obj->getReferences(false, { ObjectType::Permission });
12471246

12481247
/* If the to-be recreate object is a constraint check if it's a pk,

libs/libgui/src/tools/modelsdiffhelper.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ class __libgui ModelsDiffHelper: public QObject {
158158
/*! \brief Indicates to generate and execute commands to drop missing columns and constraints. For instance, if user
159159
try to diff a partial model against the original database and the OPT_DONT_DROP_MISSING_OBJS is set, DROP commands will not be generated,
160160
except for columns and constraints. This option is only considered in the process when OPT_DONT_DROP_MISSING_OBJS is enabled. */
161-
OptDropMissingColsConstr,
162-
163-
//! \brief Forces the recreation of any object maked as ALTER in the output
164-
OptForceRecreation
161+
OptDropMissingColsConstr
165162
};
166163

167164
ModelsDiffHelper();

libs/libgui/src/widgets/objecttypeslistwidget.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,18 @@ ObjectTypesListWidget::ObjectTypesListWidget(QWidget *parent, const std::vector<
4040
obj_types_lst->adjustSize();
4141

4242
connect(check_all_tb, &QToolButton::clicked, this, [this](){
43-
setItemsCheckState(Qt::Checked);
43+
setTypesCheckState(Qt::Checked);
4444
});
4545

4646
connect(uncheck_all_tb, &QToolButton::clicked, this, [this](){
47-
setItemsCheckState(Qt::Unchecked);
47+
setTypesCheckState(Qt::Unchecked);
4848
});
4949

5050
connect(obj_types_lst, &QListWidget::itemChanged, this, [this](QListWidgetItem *item){
5151
emit s_typeCheckStateChanged(item->data(Qt::UserRole).value<ObjectType>(), item->checkState());
5252
});
5353
}
5454

55-
void ObjectTypesListWidget::setItemsCheckState(Qt::CheckState state)
56-
{
57-
QListWidgetItem *item = nullptr;
58-
59-
for(int idx = 0; idx < obj_types_lst->count(); idx++)
60-
{
61-
item = obj_types_lst->item(idx);
62-
item->setCheckState(state);
63-
}
64-
65-
emit s_typesCheckStateChanged(state);
66-
}
67-
6855
void ObjectTypesListWidget::setTypeNamesCheckState(const QStringList &obj_types, Qt::CheckState state)
6956
{
7057
std::vector<ObjectType> types;
@@ -78,27 +65,32 @@ void ObjectTypesListWidget::setTypeNamesCheckState(const QStringList &obj_types,
7865
void ObjectTypesListWidget::setTypesCheckState(const std::vector<ObjectType> &obj_types, Qt::CheckState state)
7966
{
8067
ObjectType obj_type;
81-
QListWidgetItem *item = nullptr;
8268

83-
for(int idx = 0; idx < obj_types_lst->count(); idx++)
69+
for(auto &item : obj_types_lst->findItems("*", Qt::MatchWildcard))
8470
{
85-
item = obj_types_lst->item(idx);
8671
obj_type = item->data(Qt::UserRole).value<ObjectType>();
8772

8873
if(std::find(obj_types.cbegin(), obj_types.cend(), obj_type) != obj_types.cend())
8974
item->setCheckState(state);
9075
}
76+
77+
emit s_typesCheckStateChanged(state);
78+
}
79+
80+
void ObjectTypesListWidget::setTypesCheckState(Qt::CheckState state)
81+
{
82+
for(auto &item : obj_types_lst->findItems("*", Qt::MatchWildcard))
83+
item->setCheckState(state);
84+
85+
emit s_typesCheckStateChanged(state);
9186
}
9287

9388
std::vector<ObjectType> ObjectTypesListWidget::getTypesPerCheckState(Qt::CheckState state)
9489
{
9590
std::vector<ObjectType> types;
96-
QListWidgetItem *item = nullptr;
9791

98-
for(int idx = 0; idx < obj_types_lst->count(); idx++)
92+
for(auto &item : obj_types_lst->findItems("*", Qt::MatchWildcard))
9993
{
100-
item = obj_types_lst->item(idx);
101-
10294
if(item->checkState() == state)
10395
types.push_back(item->data(Qt::UserRole).value<ObjectType>());
10496
}
@@ -109,15 +101,25 @@ std::vector<ObjectType> ObjectTypesListWidget::getTypesPerCheckState(Qt::CheckSt
109101
QStringList ObjectTypesListWidget::getTypeNamesPerCheckState(Qt::CheckState state)
110102
{
111103
QStringList types;
112-
QListWidgetItem *item = nullptr;
113104

114-
for(int idx = 0; idx < obj_types_lst->count(); idx++)
105+
for(auto &item : obj_types_lst->findItems("*", Qt::MatchWildcard))
115106
{
116-
item = obj_types_lst->item(idx);
117-
118107
if(item->checkState() == state)
119108
types.append(BaseObject::getSchemaName(item->data(Qt::UserRole).value<ObjectType>()));
120109
}
121110

122111
return types;
123112
}
113+
114+
int ObjectTypesListWidget::getTypesCountPerCheckState(Qt::CheckState state)
115+
{
116+
int count = 0;
117+
118+
for(auto &item : obj_types_lst->findItems("*", Qt::MatchWildcard))
119+
{
120+
if(item->checkState() == state)
121+
count++;
122+
}
123+
124+
return count;
125+
}

libs/libgui/src/widgets/objecttypeslistwidget.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@
3232
class __libgui ObjectTypesListWidget : public QWidget, public Ui::ObjectTypesListWidget {
3333
Q_OBJECT
3434

35-
private:
36-
void setItemsCheckState(Qt::CheckState state);
37-
3835
public:
3936
explicit ObjectTypesListWidget(QWidget *parent = nullptr, const std::vector<ObjectType> &excl_types = {});
4037

4138
void setTypeNamesCheckState(const QStringList &obj_types, Qt::CheckState state);
4239
void setTypesCheckState(const std::vector<ObjectType> &obj_types, Qt::CheckState state);
40+
void setTypesCheckState(Qt::CheckState state);
4341

4442
std::vector<ObjectType> getTypesPerCheckState(Qt::CheckState state);
4543
QStringList getTypeNamesPerCheckState(Qt::CheckState state);
44+
int getTypesCountPerCheckState(Qt::CheckState state);
4645

4746
signals:
4847
void s_typeCheckStateChanged(ObjectType, Qt::CheckState);

0 commit comments

Comments
 (0)