Skip to content

Commit 16b5be4

Browse files
committed
DbStructureModel: Also send table data when dragging one
When using drag & drop on a table also send the entire content of that table.
1 parent 6e0c68a commit 16b5be4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/DbStructureModel.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "DbStructureModel.h"
22
#include "sqlitedb.h"
3+
#include "sqlitetablemodel.h"
34
#include <QTreeWidgetItem>
45
#include <QMimeData>
56
#include <QMessageBox>
@@ -183,7 +184,26 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
183184
{
184185
// Only export data for valid indices and only for the SQL column, i.e. only once per row
185186
if(index.isValid() && index.column() == 3)
187+
{
188+
// Add the SQL code used to create the object
186189
d = d.append(data(index, Qt::DisplayRole).toString() + ";\n");
190+
191+
// If it is a table also add the content
192+
if(data(index.sibling(index.row(), 1), Qt::DisplayRole).toString() == "table")
193+
{
194+
SqliteTableModel tableModel(0, m_db);
195+
tableModel.setTable(data(index.sibling(index.row(), 0), Qt::DisplayRole).toString());
196+
for(int i=0;i<tableModel.rowCount();i++)
197+
{
198+
QString insertStatement = "INSERT INTO `" + data(index.sibling(index.row(), 0), Qt::DisplayRole).toString() + "` VALUES(";
199+
for(int j=1;j<tableModel.columnCount();j++)
200+
insertStatement += QString("'%1',").arg(tableModel.data(tableModel.index(i, j)).toString());
201+
insertStatement.chop(1);
202+
insertStatement += ");\n";
203+
d = d.append(insertStatement);
204+
}
205+
}
206+
}
187207
}
188208

189209
// Create the MIME data object

0 commit comments

Comments
 (0)