Skip to content

Commit

Permalink
Merge branch 'master' of github.com:otsakir/lisa-backup
Browse files Browse the repository at this point in the history
  • Loading branch information
otsakir committed Oct 17, 2024
2 parents eaf5673 + 45f471b commit 14f7dbc
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
1 change: 1 addition & 0 deletions App/dialogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(dialogs
components/qtoolbuttonanimated.h components/qtoolbuttonanimated.cpp
components/taskmanager.h components/taskmanager.cpp components/taskmanager.ui
components/sourcedetailsview.h components/sourcedetailsview.cpp components/sourcedetailsview.ui
components/listviewsources.h components/listviewsources.cpp
)


Expand Down
20 changes: 20 additions & 0 deletions App/dialogs/components/listviewsources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "listviewsources.h"

#include <QKeyEvent>
#include <QDebug>

ListViewSources::ListViewSources(QWidget *parent) : QListView(parent)
{}

void ListViewSources::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Delete)
{
emit deleteKeyPressed();
} else {
QListView::keyPressEvent(event);
}
}



20 changes: 20 additions & 0 deletions App/dialogs/components/listviewsources.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef LISTVIEWSOURCES_H
#define LISTVIEWSOURCES_H

#include <QListView>

class ListViewSources : public QListView
{
Q_OBJECT
public:
ListViewSources(QWidget* parent);

signals:
void deleteKeyPressed();


protected:
void keyPressEvent(QKeyEvent *event) override;
};

#endif // LISTVIEWSOURCES_H
35 changes: 20 additions & 15 deletions App/dialogs/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "components/taskmanager.h"
#include <components/sourcedetailsview.h>
#include "components/multipledirdialog.h"
#include "components/listviewsources.h"


MainWindow::MainWindow(bool startInTray,QString openingTaskName, AppContext* appContext, QWidget *parent)
Expand All @@ -46,9 +47,12 @@ MainWindow::MainWindow(bool startInTray,QString openingTaskName, AppContext* app

// set up models for sources listview
sourcesModel = new QStandardItemModel(0,2, this);
ui->sourcesListView->setModel(sourcesModel);
ui->sourcesListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
QItemSelectionModel* selectionModel = ui->sourcesListView->selectionModel();
sourcesListView = new ListViewSources(this);
sourcesListView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
static_cast<QHBoxLayout*>(ui->verticalLayout_sourceListWrap->layout())->insertWidget(0, sourcesListView);
sourcesListView->setModel(sourcesModel);
sourcesListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
QItemSelectionModel* selectionModel = sourcesListView->selectionModel();

// Task Manager - create component and do wiring
taskManager = new TaskManager(appContext, this);
Expand Down Expand Up @@ -92,9 +96,10 @@ MainWindow::MainWindow(bool startInTray,QString openingTaskName, AppContext* app
ui->splitterSources->insertWidget(1, sourceDetails);
connect(sourceDetails, &SourceDetailsView::gotDirty, this, &MainWindow::onModelUpdated);
connect(this, &MainWindow::gotClean, sourceDetails, &SourceDetailsView::clearDirty);
connect(ui->sourcesListView->model(), &QAbstractItemModel::rowsInserted, this, &MainWindow::onModelUpdated);
connect(ui->sourcesListView->model(), &QAbstractItemModel::rowsRemoved, this, &MainWindow::onModelUpdated);
connect(sourcesListView->model(), &QAbstractItemModel::rowsInserted, this, &MainWindow::onModelUpdated);
connect(sourcesListView->model(), &QAbstractItemModel::rowsRemoved, this, &MainWindow::onModelUpdated);
connect(ui->labelNoTaskSelected, &QLabel::linkActivated, this, &MainWindow::on_action_New_triggered);
connect(sourcesListView, &ListViewSources::deleteKeyPressed, this, &MainWindow::removeSelectedSourceFromList);

activeBackup = new BackupModel();

Expand Down Expand Up @@ -191,7 +196,7 @@ QStandardItem* MainWindow::appendSource(BackupModel::SourceDetailsIndex iSourceD
itemList << modelItem;
sourcesModel->appendRow(itemList);
// select new item in the list view
QItemSelectionModel* selModel = ui->sourcesListView->selectionModel();
QItemSelectionModel* selModel = sourcesListView->selectionModel();

return modelItem;
}
Expand All @@ -213,7 +218,7 @@ void MainWindow::updateSourceDetails(QModelIndex rowIndex)

void MainWindow::removeSelectedSourceFromList()
{
const QItemSelection selection = ui->sourcesListView->selectionModel()->selection();
const QItemSelection selection = sourcesListView->selectionModel()->selection();
if (!selection.isEmpty()) {
QModelIndex i = selection.indexes().first();
//qDebug() << "will remove " << i.data();
Expand Down Expand Up @@ -246,7 +251,7 @@ void MainWindow::initUIControls(BackupModel& backupModel) {
if (lastSourceAdded)
{
QModelIndex index = sourcesModel->indexFromItem(lastSourceAdded);
ui->sourcesListView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
sourcesListView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
emit sourceChanged(index);
}
else
Expand Down Expand Up @@ -435,16 +440,16 @@ void MainWindow::swapSources(BackupModel::SourceDetailsIndex sourceIndex1, Backu
sourcesModel->insertRow(sourceIndex2,rowItems1);

// restore selected item
ui->sourcesListView->selectionModel()->clearSelection();
QModelIndex newCurrent = ui->sourcesListView->model()->index(toIndex,0);
ui->sourcesListView->selectionModel()->select( newCurrent, QItemSelectionModel::Select );
sourcesListView->selectionModel()->clearSelection();
QModelIndex newCurrent = sourcesListView->model()->index(toIndex,0);
sourcesListView->selectionModel()->select( newCurrent, QItemSelectionModel::Select );
emit sourceChanged(newCurrent);
}


void MainWindow::moveSourceItemUp()
{
const QItemSelection selection = ui->sourcesListView->selectionModel()->selection();
const QItemSelection selection = sourcesListView->selectionModel()->selection();
if (!selection.isEmpty()) {
QModelIndex i = selection.indexes().first();
qDebug() << "will move up " << i.data();
Expand All @@ -457,12 +462,12 @@ void MainWindow::moveSourceItemUp()

void MainWindow::moveSourceItemDown()
{
const QItemSelection selection = ui->sourcesListView->selectionModel()->selection();
const QItemSelection selection = sourcesListView->selectionModel()->selection();
if (!selection.isEmpty()) {
QModelIndex i = selection.indexes().first();
qDebug() << "will move down " << i.data();
BackupModel::SourceDetailsIndex iSourceDetails = i.row();
if (iSourceDetails < ui->sourcesListView->model()->rowCount()-1) // is there any space above ?
if (iSourceDetails < sourcesListView->model()->rowCount()-1) // is there any space above ?
swapSources(iSourceDetails, iSourceDetails+1);
}
}
Expand Down Expand Up @@ -556,7 +561,7 @@ void MainWindow::askUserAndAddSources()
sourceDetails.sourcePath = dialog.selectedPaths[i];
activeBackup->allSourceDetails.append(sourceDetails);
BackupModel::SourceDetailsIndex sourceDetailsIndex = activeBackup->allSourceDetails.size()-1; // points to last item added
ui->sourcesListView->selectionModel()->setCurrentIndex(sourcesModel->indexFromItem(appendSource(sourceDetailsIndex)), QItemSelectionModel::ClearAndSelect);
sourcesListView->selectionModel()->setCurrentIndex(sourcesModel->indexFromItem(appendSource(sourceDetailsIndex)), QItemSelectionModel::ClearAndSelect);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions App/dialogs/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SourceDetailsView;
class QSystemTrayIcon;
class QStandardItemModel;
class QStandardItem;
class ListViewSources;

class MainWindow : public QMainWindow
{
Expand Down Expand Up @@ -93,6 +94,7 @@ public slots:

TriggeringComboBox* triggeringCombo;
SourceDetailsView* sourceDetails;
ListViewSources* sourcesListView;

// tray icon
QAction *restoreAction;
Expand Down
17 changes: 1 addition & 16 deletions App/dialogs/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,7 @@ font-size: 15px;
<bool>false</bool>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QListView" name="sourcesListView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_sourceListWrap">
<item>
<widget class="QWidget" name="widget" native="true">
<property name="font">
Expand Down

0 comments on commit 14f7dbc

Please sign in to comment.