Compare commits

...

1 Commits

2 changed files with 30 additions and 11 deletions

View File

@ -3,6 +3,7 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QUndoStack> #include <QUndoStack>
@ -45,10 +46,10 @@ MainWindow::MainWindow(QWidget* parent)
restoreGeometry(settings.value("geometry").toByteArray()); restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray()); restoreState(settings.value("windowState").toByteArray());
m_tableModel = m_core->getModel(); // m_tableModel = m_core->getModel();
// ui->tableView->setModel(m_tableModel.get()); // ui->tableView->setModel(m_tableModel.get());
m_sortModel = m_core->getSortFilterModel(); m_proxyModel = m_core->getSortFilterModel();
ui->tableView->setModel((QAbstractItemModel*)m_sortModel.get()); ui->tableView->setModel((QAbstractItemModel*)m_proxyModel.get());
ui->tableView->setSortingEnabled(true); ui->tableView->setSortingEnabled(true);
createActions(); createActions();
@ -194,7 +195,7 @@ void MainWindow::deleteCurrentItem() {
if (currentIndex == QModelIndex()) { if (currentIndex == QModelIndex()) {
qDebug() << "No current item. Nothing to remove."; qDebug() << "No current item. Nothing to remove.";
} else { } else {
m_sortModel->removeRows(currentIndex.row(), 1); m_proxyModel->removeRows(currentIndex.row(), 1);
} }
} }
@ -212,7 +213,7 @@ void MainWindow::deleteSelectedtItems() {
const int topRow = iter->top(); const int topRow = iter->top();
const int bottomRow = iter->bottom(); const int bottomRow = iter->bottom();
const int nRows = bottomRow - topRow + 1; const int nRows = bottomRow - topRow + 1;
m_sortModel->removeRows(topRow, nRows); m_proxyModel->removeRows(topRow, nRows);
} }
} }
} }
@ -278,6 +279,24 @@ void MainWindow::exportCSV() {
} }
} }
void MainWindow::findItems() {
showStatusMessage(tr("Invoked 'Edit|Find items'"));
bool ok;
QString text = QInputDialog::getText(this, tr("Find items"), tr("Enter the text to search for:"),
QLineEdit::Normal, "", &ok);
if (ok && !text.isEmpty()) {
const QItemSelection itemsToSelect = m_proxyModel->findItems(text);
if (itemsToSelect.empty()) {
ui->tableView->setCurrentIndex(QModelIndex());
ui->tableView->selectionModel()->select(QModelIndex(), QItemSelectionModel::ClearAndSelect);
} else {
ui->tableView->setCurrentIndex(itemsToSelect.first().topLeft());
ui->tableView->selectionModel()->select(itemsToSelect, QItemSelectionModel::ClearAndSelect);
}
}
}
void MainWindow::createActions() { void MainWindow::createActions() {
// TODO add generic menu actions (file/new, edit/cut, ...) // TODO add generic menu actions (file/new, edit/cut, ...)
createFileActions(); createFileActions();
@ -425,8 +444,7 @@ void MainWindow::createEditActions() {
m_findItemAct = make_unique<QAction>(tr("&Find item(s)"), this); m_findItemAct = make_unique<QAction>(tr("&Find item(s)"), this);
m_findItemAct->setShortcuts(QKeySequence::Find); m_findItemAct->setShortcuts(QKeySequence::Find);
m_findItemAct->setStatusTip(tr("Opens a dialog to find item(s) by containing text")); m_findItemAct->setStatusTip(tr("Opens a dialog to find item(s) by containing text"));
// connect(m_findItemAct, &QAction::triggered, this, &MainWindow::findItems); connect(m_findItemAct.get(), &QAction::triggered, this, &MainWindow::findItems);
m_findItemAct->setEnabled(false);
ui->menu_Edit->addAction(m_findItemAct.get()); ui->menu_Edit->addAction(m_findItemAct.get());
} }
@ -444,7 +462,7 @@ void MainWindow::createGuiDialogs() {
/// new item dialog /// new item dialog
m_newItemDialog = make_unique<NewItemDialog>(this); m_newItemDialog = make_unique<NewItemDialog>(this);
m_newItemDialog->createContent(); m_newItemDialog->createContent();
connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_sortModel.get(), connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_proxyModel.get(),
&GeneralSortFilterModel::appendItems); &GeneralSortFilterModel::appendItems);
/// edit item dialog /// edit item dialog
m_editItemDialog = make_unique<EditItemDialog>(ui->tableView, this); m_editItemDialog = make_unique<EditItemDialog>(ui->tableView, this);

View File

@ -60,13 +60,14 @@ class MainWindow : public QMainWindow {
void importCSV(); void importCSV();
void exportCSV(); void exportCSV();
/// 'Edit' slots
void findItems();
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
// GenericCore* m_core;
unique_ptr<GenericCore> m_core; unique_ptr<GenericCore> m_core;
shared_ptr<TableModel> m_tableModel; shared_ptr<GeneralSortFilterModel> m_proxyModel;
shared_ptr<GeneralSortFilterModel> m_sortModel;
QUndoStack* m_modelUndoStack; QUndoStack* m_modelUndoStack;
unique_ptr<QUndoView> m_modelUndoView; unique_ptr<QUndoView> m_modelUndoView;