summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp67
-rw-r--r--qt-ui/divelistview.h9
-rw-r--r--qt-ui/mainwindow.cpp10
-rw-r--r--qt-ui/models.h2
4 files changed, 70 insertions, 18 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index d66313823..f0cb01a82 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -29,6 +29,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
model->setFilterKeyColumn(-1); // filter all columns
setModel(model);
setSortingEnabled(false);
+ setContextMenuPolicy(Qt::DefaultContextMenu);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
QAction *showSearchBox = new QAction(tr("Show Search Box"), this);
showSearchBox->setShortcut( Qt::CTRL + Qt::Key_F);
@@ -127,8 +128,10 @@ void DiveListView::headerClicked(int i)
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
{
- currentLayout = layout;
-
+ if (layout == DiveTripModel::CURRENT)
+ layout = currentLayout;
+ else
+ currentLayout = layout;
header()->setClickable(true);
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
@@ -272,17 +275,61 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
Q_EMIT currentDiveChanged(selected_dive);
}
-void DiveListView::mousePressEvent(QMouseEvent *event)
+void DiveListView::removeFromTrip()
{
- // all we care about is the unmodified right click
- if ( ! (event->modifiers() == Qt::NoModifier && event->buttons() & Qt::RightButton)) {
- event->ignore();
- QTreeView::mousePressEvent(event);
+ struct dive *d = (struct dive *) contextMenuIndex.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (!d) // shouldn't happen as we only are setting up this action if this is a dive
return;
+ remove_dive_from_trip(d);
+ reload(currentLayout, false);
+}
+
+void DiveListView::deleteDive()
+{
+ struct dive *d = (struct dive *) contextMenuIndex.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (d)
+ delete_single_dive(get_index_for_dive(d));
+ reload(currentLayout, false);
+}
+
+void DiveListView::testSlot()
+{
+ struct dive *d = (struct dive *) contextMenuIndex.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (d) {
+ qDebug("testSlot called on dive #%d", d->number);
+ } else {
+ QModelIndex child = contextMenuIndex.child(0, 0);
+ d = (struct dive *) child.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (d)
+ qDebug("testSlot called on trip including dive #%d", d->number);
+ else
+ qDebug("testSlot called on trip with no dive");
}
+}
+
+void DiveListView::contextMenuEvent(QContextMenuEvent *event)
+{
+ QAction *collapseAction = NULL;
+ // let's remember where we are
+ contextMenuIndex = indexAt(event->pos());
+ struct dive *d = (struct dive *) contextMenuIndex.data(TreeItemDT::DIVE_ROLE).value<void*>();
QMenu popup(this);
- popup.addAction(tr("expand all"), this, SLOT(expandAll()));
- QAction *collapseAllAction = popup.addAction(tr("collapse all"), this, SLOT(collapseAll()));
- if (popup.exec(event->globalPos()) == collapseAllAction)
+ if (currentLayout == DiveTripModel::TREE) {
+ popup.addAction(tr("expand all"), this, SLOT(expandAll()));
+ popup.addAction(tr("collapse all"), this, SLOT(collapseAll()));
+ collapseAction = popup.addAction(tr("collapse"), this, SLOT(collapseAll()));
+ if (d) {
+ popup.addAction(tr("remove dive from trip"), this, SLOT(removeFromTrip()));
+ }
+ }
+ popup.addAction(tr("delete dive"), this, SLOT(deleteDive()));
+ // "collapse all" really closes all trips,
+ // "collapse" keeps the trip with the selected dive open
+ QAction * actionTaken = popup.exec(event->globalPos());
+ if (actionTaken == collapseAction && collapseAction) {
+ this->setAnimated(false);
selectDive(current_dive, true);
+ this->setAnimated(true);
+ }
+ event->accept();
}
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index 2bce35612..a9b986f97 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -24,25 +24,30 @@ public:
DiveListView(QWidget *parent = 0);
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
- void reload(DiveTripModel::Layout layout = DiveTripModel::TREE, bool forceSort = true);
+ void reload(DiveTripModel::Layout layout, bool forceSort = true);
bool eventFilter(QObject* , QEvent* );
void unselectDives();
void selectDive(struct dive *, bool scrollto = false);
- void mousePressEvent(QMouseEvent *event);
+ void contextMenuEvent(QContextMenuEvent *event);
public slots:
void toggleColumnVisibilityByIndex();
void reloadHeaderActions();
void headerClicked(int);
void showSearchEdit();
+ void removeFromTrip();
+ void deleteDive();
+ void testSlot();
Q_SIGNALS:
void currentDiveChanged(int divenr);
+
private:
bool mouseClickSelection;
int currentHeaderClicked;
DiveTripModel::Layout currentLayout;
QLineEdit *searchBox;
+ QModelIndex contextMenuIndex;
};
#endif // DIVELISTVIEW_H
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index f4d634d7f..286aba43e 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -43,11 +43,11 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0)
setWindowIcon(QIcon(":subsurface-icon"));
connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int)));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(readSettings()));
- connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(refreshDisplay()));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui->ListWidget, SLOT(update()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui->ProfileWidget, SLOT(refresh()));
ui->mainErrorMessage->hide();
ui->ProfileWidget->setFocusProxy(ui->ListWidget);
- ui->ListWidget->reload();
+ ui->ListWidget->reload(DiveTripModel::TREE);
initialUiSetup();
readSettings();
ui->ListWidget->reloadHeaderActions();
@@ -61,7 +61,7 @@ void MainWindow::refreshDisplay()
{
if (selected_dive == -1)
current_dive_changed(dive_table.nr - 1);
- ui->ListWidget->reload();
+ ui->ListWidget->reload(DiveTripModel::CURRENT, false);
}
void MainWindow::current_dive_changed(int divenr)
@@ -107,7 +107,7 @@ void MainWindow::on_actionOpen_triggered()
ui->InfoWidget->reload();
ui->globe->reload();
- ui->ListWidget->reload();
+ ui->ListWidget->reload(DiveTripModel::TREE);
ui->ListWidget->setFocus();
}
@@ -140,7 +140,7 @@ void MainWindow::on_actionClose_triggered()
ui->InfoWidget->clearEquipment();
ui->InfoWidget->updateDiveInfo(-1);
ui->ProfileWidget->clear();
- ui->ListWidget->reload();
+ ui->ListWidget->reload(DiveTripModel::TREE);
ui->globe->reload();
clear_events();
diff --git a/qt-ui/models.h b/qt-ui/models.h
index 99d028aca..a012ec6bd 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -144,7 +144,7 @@ class DiveTripModel : public QAbstractItemModel
Q_OBJECT
public:
- enum Layout{TREE, LIST};
+ enum Layout{TREE, LIST, CURRENT};
DiveTripModel(QObject *parent = 0);
~DiveTripModel();