mirror of https://github.com/KLayout/klayout.git
Some enhancements to #343 fix
- "follow selection": allows navigating between the bookmarks with the cursor keys - "manage bookmarks" now starts with the selected bookmarks also selected.
This commit is contained in:
parent
d2d22eafb5
commit
d9d3b3cafe
|
|
@ -53,7 +53,7 @@ private:
|
|||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
BookmarkManagementForm::BookmarkManagementForm (QWidget *parent, const char *name, const lay::BookmarkList &bookmarks)
|
||||
BookmarkManagementForm::BookmarkManagementForm (QWidget *parent, const char *name, const lay::BookmarkList &bookmarks, const std::set<size_t> &selected)
|
||||
: QDialog (parent), Ui::BookmarkManagementForm (),
|
||||
m_bookmarks (bookmarks)
|
||||
{
|
||||
|
|
@ -61,8 +61,18 @@ BookmarkManagementForm::BookmarkManagementForm (QWidget *parent, const char *nam
|
|||
|
||||
Ui::BookmarkManagementForm::setupUi (this);
|
||||
|
||||
QListWidgetItem *first_item = 0;
|
||||
|
||||
for (size_t i = 0; i < m_bookmarks.size (); ++i) {
|
||||
new BookmarkListLVI (bookmark_list, m_bookmarks.name (i), m_bookmarks.state (i));
|
||||
QListWidgetItem *item = new BookmarkListLVI (bookmark_list, m_bookmarks.name (i), m_bookmarks.state (i));
|
||||
item->setSelected (selected.find (i) != selected.end ());
|
||||
if (! first_item && item->isSelected ()) {
|
||||
first_item = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (first_item) {
|
||||
bookmark_list->scrollToItem (first_item);
|
||||
}
|
||||
|
||||
connect (delete_button, SIGNAL (clicked ()), this, SLOT (delete_pressed ()));
|
||||
|
|
|
|||
|
|
@ -26,8 +26,11 @@
|
|||
|
||||
#include <QObject> // required during the dependency pass
|
||||
#include "ui_BookmarkManagementForm.h"
|
||||
|
||||
#include "layLayoutView.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
|
|
@ -37,7 +40,7 @@ class BookmarkManagementForm
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BookmarkManagementForm (QWidget *parent, const char *name, const lay::BookmarkList &bookmarks);
|
||||
BookmarkManagementForm (QWidget *parent, const char *name, const lay::BookmarkList &bookmarks, const std::set<size_t> &selected);
|
||||
|
||||
/**
|
||||
* @brief Obtain the bookmark list
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
#include "layAbstractMenu.h"
|
||||
#include "layAbstractMenuProvider.h"
|
||||
|
||||
#include "laybasicConfig.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace lay
|
||||
|
|
@ -88,7 +90,7 @@ private:
|
|||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
BookmarksView::BookmarksView (LayoutView *view, QWidget *parent, const char *name)
|
||||
: QFrame (parent)
|
||||
: QFrame (parent), m_follow_selection (false)
|
||||
{
|
||||
setObjectName (QString::fromUtf8 (name));
|
||||
|
||||
|
|
@ -102,10 +104,12 @@ BookmarksView::BookmarksView (LayoutView *view, QWidget *parent, const char *nam
|
|||
layout->addWidget (mp_bookmarks);
|
||||
|
||||
mp_bookmarks->setModel (new BookmarkListModel (&view->bookmarks ()));
|
||||
mp_bookmarks->setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
mp_bookmarks->setContextMenuPolicy (Qt::CustomContextMenu);
|
||||
|
||||
connect (mp_bookmarks, SIGNAL (customContextMenuRequested (const QPoint &)), this, SLOT (context_menu (const QPoint &)));
|
||||
connect (mp_bookmarks, SIGNAL (doubleClicked (const QModelIndex &)), this, SLOT (bookmark_triggered (const QModelIndex &)));
|
||||
connect (mp_bookmarks->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_bookmark_changed (const QModelIndex &)));
|
||||
}
|
||||
|
||||
BookmarksView::~BookmarksView ()
|
||||
|
|
@ -113,10 +117,29 @@ BookmarksView::~BookmarksView ()
|
|||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
std::set<size_t>
|
||||
BookmarksView::selected_bookmarks ()
|
||||
{
|
||||
QModelIndexList sel = mp_bookmarks->selectionModel ()->selectedIndexes ();
|
||||
std::set<size_t> res;
|
||||
for (QModelIndexList::const_iterator i = sel.begin (); i != sel.end (); ++i) {
|
||||
res.insert (int (i->row ()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
BookmarksView::follow_selection (bool f)
|
||||
{
|
||||
m_follow_selection = f;
|
||||
}
|
||||
|
||||
void
|
||||
BookmarksView::init_menu (lay::AbstractMenu &menu)
|
||||
{
|
||||
MenuLayoutEntry context_menu [] = {
|
||||
MenuLayoutEntry ("follow_selection", tl::to_string (QObject::tr ("Follow Selection")), std::make_pair (cfg_bookmarks_follow_selection, "?")),
|
||||
MenuLayoutEntry::separator ("ops_group"),
|
||||
MenuLayoutEntry ("manage_bookmarks", tl::to_string (QObject::tr ("Manage Bookmarks")), SLOT (cm_manage_bookmarks ())),
|
||||
MenuLayoutEntry ("load_bookmarks", tl::to_string (QObject::tr ("Load Bookmarks")), SLOT (cm_load_bookmarks ())),
|
||||
MenuLayoutEntry ("save_bookmarks", tl::to_string (QObject::tr ("Save Bookmarks")), SLOT (cm_save_bookmarks ())),
|
||||
|
|
@ -168,6 +191,14 @@ BookmarksView::context_menu (const QPoint &p)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
BookmarksView::current_bookmark_changed (const QModelIndex &index)
|
||||
{
|
||||
if (m_follow_selection) {
|
||||
bookmark_triggered (index);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BookmarksView::bookmark_triggered (const QModelIndex &index)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
#include <QFrame>
|
||||
#include <QListView>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
|
|
@ -51,6 +53,9 @@ public:
|
|||
|
||||
void set_background_color (QColor c);
|
||||
void set_text_color (QColor c);
|
||||
void follow_selection (bool f);
|
||||
|
||||
std::set<size_t> selected_bookmarks ();
|
||||
|
||||
void refresh ();
|
||||
|
||||
|
|
@ -58,11 +63,13 @@ public:
|
|||
|
||||
public slots:
|
||||
void bookmark_triggered (const QModelIndex &index);
|
||||
void current_bookmark_changed (const QModelIndex &index);
|
||||
void context_menu (const QPoint &p);
|
||||
|
||||
private:
|
||||
LayoutView *mp_view;
|
||||
QListView *mp_bookmarks;
|
||||
bool m_follow_selection;
|
||||
};
|
||||
|
||||
} // namespace lay
|
||||
|
|
|
|||
|
|
@ -1011,6 +1011,15 @@ LayoutView::configure (const std::string &name, const std::string &value)
|
|||
}
|
||||
return true;
|
||||
|
||||
} else if (name == cfg_bookmarks_follow_selection) {
|
||||
|
||||
bool f;
|
||||
tl::from_string (value, f);
|
||||
if (mp_bookmarks_view) {
|
||||
mp_bookmarks_view->follow_selection (f);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (name == cfg_current_lib_view) {
|
||||
|
||||
if (mp_libraries_view) {
|
||||
|
|
@ -3815,7 +3824,12 @@ LayoutView::bookmark_current_view ()
|
|||
void
|
||||
LayoutView::manage_bookmarks ()
|
||||
{
|
||||
BookmarkManagementForm dialog (this, "bookmark_form", bookmarks ());
|
||||
std::set<size_t> selected_bm;
|
||||
if (mp_bookmarks_frame->isVisible ()) {
|
||||
selected_bm = mp_bookmarks_view->selected_bookmarks ();
|
||||
}
|
||||
|
||||
BookmarkManagementForm dialog (this, "bookmark_form", bookmarks (), selected_bm);
|
||||
if (dialog.exec ()) {
|
||||
bookmarks (dialog.bookmarks ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,6 +130,8 @@ static const std::string cfg_cell_list_sorting ("cell-list-sorting");
|
|||
static const std::string cfg_split_lib_views ("split-lib-views");
|
||||
static const std::string cfg_current_lib_view ("current-lib-view");
|
||||
|
||||
static const std::string cfg_bookmarks_follow_selection ("bookmarks-follow-selection");
|
||||
|
||||
static const std::string cfg_pan_distance ("pan-distance");
|
||||
static const std::string cfg_paste_display_mode ("paste-display-mode");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue