Skip to content

Commit

Permalink
Drag'n'drop move items works
Browse files Browse the repository at this point in the history
  • Loading branch information
M Z authored and M Z committed Oct 11, 2018
1 parent c3675d3 commit 2b9cec8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tvRight->setDropIndicatorShown(true);
ui->tvLeft->setAcceptDrops(true); // - for separate vCard items
ui->tvRight->setAcceptDrops(true);
ui->tvLeft->setDragDropOverwriteMode(false);
ui->tvRight->setDragDropOverwriteMode(false);
// Configuration
configManager.setDefaults(ui->tvLeft->font().toString(),
ui->tvLeft->palette().color(QPalette::Base).name(),
Expand Down
6 changes: 6 additions & 0 deletions app/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@
</item>
<item row="1" column="1">
<widget class="QTableView" name="tvRight">
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTableView" name="tvLeft">
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
Expand Down
19 changes: 11 additions & 8 deletions model/contactmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,24 @@ bool ContactModel::dropMimeData(const QMimeData *data, Qt::DropAction action, in
d.importRecords(lines, items, true, errors);

endResetModel();
if (action == Qt::CopyAction)
return true;
else if (action == Qt::MoveAction) {
; // TODO

_changed = true;
// TODO insert to pointed line
if (action == Qt::CopyAction || action == Qt::MoveAction)
return true;
}
else
return false;
}
/*

bool ContactModel::removeRows(int row, int count, const QModelIndex &parent)
{
beginRemoveRows (QModelIndex(), row, row+count-1);
for (int i=row+count-1; i>=row; i--)
items.removeAt(i);
endRemoveRows();
_changed = true;
return false;
}
*/

bool ContactModel::open(const QString& path, FormatType fType, QStringList &errors, QString &fatalError)
{
if (path.isEmpty()) return false;
Expand Down
2 changes: 1 addition & 1 deletion model/contactmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ContactModel : public QAbstractTableModel
QMimeData* mimeData(const QModelIndexList &indexes) const;
virtual bool dropMimeData (const QMimeData * data, Qt::DropAction action,
int, int column, const QModelIndex&);
// bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
// Save and open methods
bool open(const QString& path, FormatType fType, QStringList &errors, QString &fatalError);
bool saveAs(const QString& path, FormatType fType, QStringList &errors, QString &fatalError);
Expand Down

0 comments on commit 2b9cec8

Please sign in to comment.