Skip to content
Permalink
Browse files

implemented BookmarkManagerDialog.(refs #79)

  • Loading branch information...
haraki committed Jun 15, 2019
1 parent 62531b7 commit c1b115785d7348789fbbd893a323b221ff71f084
Showing with 288 additions and 14 deletions.
  1. +7 −1 bookmarkeditdialog.cpp
  2. +158 −3 bookmarkmanagerdialog.cpp
  3. +22 −2 bookmarkmanagerdialog.h
  4. +87 −7 bookmarkmanagerdialog.ui
  5. +14 −1 mainwindow.cpp
@@ -1,5 +1,6 @@
#include <QFileDialog>
#include <QPushButton>
#include <QStyle>
#include <QDebug>
#include "bookmarkeditdialog.h"
#include "ui_bookmarkeditdialog.h"
@@ -15,6 +16,8 @@ BookmarkEditDialog::BookmarkEditDialog(const QString& currentDirPath, const Book
{
ui->setupUi(this);

ui->selectPathToolButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileDialogStart));

ui->nameLineEdit->setText(info.getName());
ui->pathLineEdit->setText(info.getPath());

@@ -55,7 +58,10 @@ void BookmarkEditDialog::on_selectPathToolButton_clicked()
dirPath,
QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly);

ui->pathLineEdit->setText(dirPath);
if(!dirPath.isEmpty())
{
ui->pathLineEdit->setText(dirPath);
}

checkNamePathEmpty();
}
@@ -1,19 +1,174 @@
#include "bookmarkmanagerdialog.h"
#include <QMessageBox>
#include <QDebug>
#include "bookmarkinfo.h"
#include "bookmarkinfomodel.h"
#include "bookmarkmanagerdialog.h"
#include "ui_bookmarkmanagerdialog.h"
#include "bookmarkeditdialog.h"

namespace Farman
{

BookmarkManagerDialog::BookmarkManagerDialog(QWidget *parent) :
BookmarkManagerDialog::BookmarkManagerDialog(const QString& currentDirPath, QWidget *parent/* = Q_NULLPTR*/) :
QDialog(parent),
ui(new Ui::BookmarkManagerDialog)
ui(new Ui::BookmarkManagerDialog),
m_bookmarkInfoModel(new BookmarkInfoModel(false, false)),
m_currentDirPath(currentDirPath)
{
ui->setupUi(this);

ui->upToolButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarShadeButton));
ui->downToolButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));

ui->bookmarksTableView->setModel(m_bookmarkInfoModel);
ui->bookmarksTableView->setCurrentIndex(m_bookmarkInfoModel->index(0, 0));

ui->bookmarksTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}

BookmarkManagerDialog::~BookmarkManagerDialog()
{
delete m_bookmarkInfoModel;

delete ui;
}

void BookmarkManagerDialog::accept()
{
m_bookmarkInfoModel->saveToSettings();

QDialog::accept();
}

void BookmarkManagerDialog::on_newPushButton_clicked()
{
qDebug() << "BookmarkManagerDialog::on_newPushButton_clicked()";

BookmarkInfo retInfo;
if(launchBookmarkEditDialog(BookmarkInfo(), retInfo) != QDialog::Accepted)
{
return;
}

qDebug() << "retInfo name : " << retInfo.getName() << ", path : " << retInfo.getPath();

int row = m_bookmarkInfoModel->rowCount();
qDebug() << "row : " << row;
if(!m_bookmarkInfoModel->insertRows(row, 1))
{
qDebug() << "insert error.";

return;
}

qDebug() << "insert success.";

m_bookmarkInfoModel->setData(m_bookmarkInfoModel->index(row, 0), retInfo.getName());
m_bookmarkInfoModel->setData(m_bookmarkInfoModel->index(row, 1), retInfo.getPath());
}

void BookmarkManagerDialog::on_editPushButton_clicked()
{
qDebug() << "BookmarkManagerDialog::on_editPushButton_clicked()";

QModelIndex index = ui->bookmarksTableView->currentIndex();
if(!index.isValid())
{
return;
}

editBookmark(index);
}

void BookmarkManagerDialog::on_deletePushButton_clicked()
{
qDebug() << "BookmarkManagerDialog::on_deletePushButton_clicked()";

QModelIndex index = ui->bookmarksTableView->currentIndex();
if(!index.isValid())
{
return;
}

if(QMessageBox::question(this,
tr("Confirm"),
tr("Are you sure you want to delete this bookmark?") + "<br><br>"
+ tr("Name : ") + m_bookmarkInfoModel->data(index, BookmarkInfoModel::NameRole).toString() + "<br>"
+ tr("Path : ") + m_bookmarkInfoModel->data(index, BookmarkInfoModel::PathRole).toString())
!= QMessageBox::Yes)
{
return;
}

m_bookmarkInfoModel->removeRow(index.row());
}

void BookmarkManagerDialog::on_upToolButton_clicked()
{
qDebug() << "BookmarkManagerDialog::on_upToolButton_clicked()";

QModelIndex index = ui->bookmarksTableView->currentIndex();
if(!index.isValid() || index.row() <= 0)
{
return;
}

m_bookmarkInfoModel->moveRow(ui->bookmarksTableView->rootIndex(), index.row(), ui->bookmarksTableView->rootIndex(), index.row() - 1);
}

void BookmarkManagerDialog::on_downToolButton_clicked()
{
qDebug() << "BookmarkManagerDialog::on_downToolButton_clicked()";

QModelIndex index = ui->bookmarksTableView->currentIndex();
if(!index.isValid() || index.row() >= m_bookmarkInfoModel->rowCount() - 1)
{
return;
}

m_bookmarkInfoModel->moveRow(ui->bookmarksTableView->rootIndex(), index.row(), ui->bookmarksTableView->rootIndex(), index.row() + 2);
}

void BookmarkManagerDialog::on_bookmarksTableView_doubleClicked(const QModelIndex &index)
{
if(!index.isValid())
{
return;
}

editBookmark(index);
}

void BookmarkManagerDialog::editBookmark(const QModelIndex& index)
{
BookmarkInfo retInfo;
if(launchBookmarkEditDialog({BookmarkInfo::Type::User,
m_bookmarkInfoModel->data(index, BookmarkInfoModel::NameRole).toString(),
m_bookmarkInfoModel->data(index, BookmarkInfoModel::PathRole).toString()},
retInfo) != QDialog::Accepted)
{
return;
}

int row = index.row();
m_bookmarkInfoModel->setData(m_bookmarkInfoModel->index(row, 0), retInfo.getName());
m_bookmarkInfoModel->setData(m_bookmarkInfoModel->index(row, 1), retInfo.getPath());
}

QDialog::DialogCode BookmarkManagerDialog::launchBookmarkEditDialog(const BookmarkInfo& in, BookmarkInfo& out)
{
BookmarkEditDialog dialog(m_currentDirPath, in, this);

QDialog::DialogCode ret = static_cast<QDialog::DialogCode>(dialog.exec());

if(ret != QDialog::Accepted)
{
return ret;
}

out = dialog.getBookmarkInfo();

return QDialog::Accepted;
}

} // namespace Farman
@@ -2,6 +2,8 @@
#define BOOKMARKMANAGERDIALOG_H

#include <QDialog>
#include "bookmarkinfo.h"
#include "bookmarkinfomodel.h"

namespace Ui {
class BookmarkManagerDialog;
@@ -15,11 +17,29 @@ class BookmarkManagerDialog : public QDialog
Q_OBJECT

public:
explicit BookmarkManagerDialog(QWidget *parent = nullptr);
~BookmarkManagerDialog();
explicit BookmarkManagerDialog(const QString& currentDirPath, QWidget *parent = Q_NULLPTR);
~BookmarkManagerDialog() Q_DECL_OVERRIDE;

void accept() Q_DECL_OVERRIDE;

private Q_SLOTS:
void on_newPushButton_clicked();
void on_editPushButton_clicked();
void on_deletePushButton_clicked();
void on_upToolButton_clicked();
void on_downToolButton_clicked();

void on_bookmarksTableView_doubleClicked(const QModelIndex &index);

private:
void editBookmark(const QModelIndex& index);
QDialog::DialogCode launchBookmarkEditDialog(const BookmarkInfo& in, BookmarkInfo& out);

Ui::BookmarkManagerDialog *ui;

BookmarkInfoModel *m_bookmarkInfoModel;

const QString m_currentDirPath;
};

} // namespace Farman
@@ -6,18 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>489</width>
<height>413</height>
</rect>
</property>
<property name="windowTitle">
<string>Bookmark Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTableView" name="bookmarksTableView"/>
</item>
<item row="0" column="1">
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
@@ -37,13 +34,19 @@
<property name="text">
<string>...</string>
</property>
<property name="shortcut">
<string>Shift+Num+Up</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="downToolButton">
<property name="text">
<string>...</string>
</property>
<property name="shortcut">
<string>Shift+Num+Down</string>
</property>
</widget>
</item>
<item>
@@ -61,7 +64,7 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -71,8 +74,85 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTableView" name="bookmarksTableView">
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="newPushButton">
<property name="text">
<string>New(&amp;N)</string>
</property>
<property name="shortcut">
<string>N</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editPushButton">
<property name="text">
<string>Edit(&amp;E)</string>
</property>
<property name="shortcut">
<string>E</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deletePushButton">
<property name="text">
<string>Delete(&amp;D)</string>
</property>
<property name="shortcut">
<string>D</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>bookmarksTableView</tabstop>
<tabstop>newPushButton</tabstop>
<tabstop>editPushButton</tabstop>
<tabstop>deletePushButton</tabstop>
<tabstop>upToolButton</tabstop>
<tabstop>downToolButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

0 comments on commit c1b1157

Please sign in to comment.
You can’t perform that action at this time.