@@ -211,19 +211,11 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
211211 if (index.isValid ()) {
212212 QString objectType = data (index.sibling (index.row (), ColumnObjectType), Qt::DisplayRole).toString ();
213213
214- // For names, export an escaped identifier of the item for statement composition in SQL editor.
215- // Commas are included for a list of fields. A dot is added after other items, in order to allow composing
216- // a fully qualified name by selecting together and dropping a parent item and a child (e.g. select with
217- // control an attached database and a table, and drag and drop them to get "schema1"."table1".)
218- // Note that this only makes sense when the "Drop Qualified Names" option is not set.
219- if (index.column () == ColumnName)
220- if (objectType == " field" )
221- namesData.append (getNameForDropping (item->parent ()->text (ColumnName), item->text (ColumnName)) + " , " );
222- else if (objectType != " " )
223- if (item->text (ColumnSchema) == " main" )
224- namesData.append (getNameForDropping (" " , item->text (ColumnName)) + " ." );
225- else
226- namesData.append (getNameForDropping (item->text (ColumnSchema), item->text (ColumnName)) + " ." );
214+ // For names, export a (qualified) (escaped) identifier of the item for statement composition in SQL editor.
215+ if (objectType == " field" )
216+ namesData.append (getNameForDropping (item->text (ColumnSchema), item->parent ()->text (ColumnName), item->text (ColumnName)));
217+ else if (objectType != " " )
218+ namesData.append (getNameForDropping (item->text (ColumnSchema), item->text (ColumnName), " " ));
227219
228220 if (objectType != " field" && index.column () == ColumnSQL)
229221 {
@@ -380,13 +372,23 @@ QTreeWidgetItem* DbStructureModel::addNode(QTreeWidgetItem* parent, const sqlb::
380372 return item;
381373}
382374
383- QString DbStructureModel::getNameForDropping (const QString& parentName , const QString& itemName ) const
375+ QString DbStructureModel::getNameForDropping (const QString& domain , const QString& object, const QString& field ) const
384376{
377+ // Take into account the drag&drop options for composing a name. Commas are included for composing a
378+ // list of fields. A dot is added after other items, in order to allow composing a fully qualified name
379+ // by selecting together and dropping a parent item and a child (e.g. select with control an attached
380+ // database and a table, and drag and drop them to get "schema1"."table1".) Note that this only makes
381+ // sense when the "Drop Qualified Names" option is not set.
385382 QString name;
386- if (m_dropQualifiedNames && parentName != " " )
387- name = m_dropEnquotedNames ? sqlb::escapeIdentifier (parentName) + " ." : parentName + " ." ;
383+ if (m_dropQualifiedNames) {
384+ if (domain != " main" )
385+ name = m_dropEnquotedNames ? sqlb::escapeIdentifier (domain) + " ." : domain + " ." ;
388386
389- name += m_dropEnquotedNames ? sqlb::escapeIdentifier (itemName) : itemName;
387+ name += m_dropEnquotedNames ? sqlb::escapeIdentifier (object) + " ." : object + " ." ;
388+ }
389+
390+ if (!field.isEmpty ())
391+ name += m_dropEnquotedNames ? sqlb::escapeIdentifier (field) + " , " : field + " , " ;
390392
391393 return name;
392394}
0 commit comments