Skip to content

Commit

Permalink
create shortcuts for deleting items in widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia authored and Julia committed Oct 3, 2023
1 parent 81b8107 commit 1c20611
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/gui/include/gui/content_manager/content_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace hal

public:
static SettingsItemKeybind* sSettingSearch;
static SettingsItemKeybind* sSettingDeleteItem;
void addExternalWidget(ContentFactory* factory);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "gui/context_manager_widget/models/context_table_model.h"
#include "gui/context_manager_widget/models/context_table_proxy_model.h"
#include "gui/searchbar/searchbar.h"
#include "gui/settings/settings_items/settings_item_keybind.h"

#include <QListWidget>
#include <QPoint>
Expand Down Expand Up @@ -166,6 +167,11 @@ namespace hal
*/
void updateSearchIcon();

private Q_SLOTS:

void handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget);


private:
GraphTabWidget* mTabView;

Expand Down Expand Up @@ -201,6 +207,8 @@ namespace hal
QString mSearchIconStyle;
QString mSearchActiveIconStyle;

QShortcut* mShortCutDeleteItem;

void handleCreateContextClicked();
void handleRenameContextClicked();
void handleDuplicateContextClicked();
Expand Down
5 changes: 5 additions & 0 deletions plugins/gui/include/gui/grouping/grouping_manager_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gui/content_widget/content_widget.h"
#include "gui/grouping/grouping_table_model.h"
#include "hal_core/defines.h"
#include "gui/settings/settings_items/settings_item_keybind.h"

#include <QColor>
#include "gui/grouping/grouping_color_serializer.h"
Expand Down Expand Up @@ -315,6 +316,8 @@ namespace hal
*/
void handleDoubleClicked(const QModelIndex& index);

void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget);

private:
class ToolboxModuleHash
{
Expand Down Expand Up @@ -375,6 +378,8 @@ namespace hal
QString mDisabledIconStyle;
GroupingColorSerializer mColorSerializer;

QShortcut* mShortCutDeleteItem;

GroupingTableEntry getCurrentGrouping();
};
} // namespace hal
10 changes: 10 additions & 0 deletions plugins/gui/include/gui/module_widget/module_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "gui/selection_relay/selection_relay.h"
#include "gui/module_widget/module_tree_view.h"
#include "hal_core/netlist/module.h"
#include "gui/settings/settings_items/settings_item_keybind.h"


#include <QAction>
#include <QItemSelection>
Expand Down Expand Up @@ -170,6 +172,11 @@ namespace hal
void handleModuleRemoved(Module* module, u32 module_id);


private Q_SLOTS:
void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget);

void deleteSelectedItem();

private:
ModuleTreeView* mTreeView;
Searchbar* mSearchbar;
Expand All @@ -188,8 +195,11 @@ namespace hal

ModuleProxyModel* mModuleProxyModel;

QShortcut* mShortCutDeleteItem;

void openModuleInView(const QModelIndex& index);

ModuleItem* getModuleItemFromIndex(const QModelIndex& index);

};
} // namespace hal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h"
#include "hal_core/defines.h"


class QTableWidget;
class QStackedWidget;
class QSplitter;
Expand Down
11 changes: 11 additions & 0 deletions plugins/gui/src/content_manager/content_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

namespace hal
{

ExternalContent* ExternalContent::inst = nullptr;

ExternalContent* ExternalContent::instance()
Expand All @@ -60,6 +61,7 @@ namespace hal

SettingsItemDropdown* ContentManager::sSettingSortMechanism;
SettingsItemKeybind* ContentManager::sSettingSearch;
SettingsItemKeybind* ContentManager::sSettingDeleteItem;
bool ContentManager::sSettingsInitialized = initializeSettings();
bool ContentManager::initializeSettings()
{
Expand All @@ -74,12 +76,21 @@ namespace hal
"Keybindings:Global",
"Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget).");


sSettingDeleteItem =
new SettingsItemKeybind("Delete Item",
"keybinds/item_delete",
QKeySequence("Del"),
"Keybindings:Global",
"Keybind for deleting the focused Item.");
return true;
}

ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent),
mExternalIndex(0), mContextSerializer(nullptr)
{


// has to be created this early in order to receive deserialization by the core signals
mPythonWidget = new PythonEditor();

Expand Down
27 changes: 27 additions & 0 deletions plugins/gui/src/context_manager_widget/context_manager_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gui/user_action/action_rename_object.h"
#include "gui/user_action/user_action_compound.h"
#include <QShortcut>
#include <QApplication>

namespace hal
{
Expand Down Expand Up @@ -110,6 +111,14 @@ namespace hal

connect(mSearchbar, &Searchbar::textEdited, mContextTableProxyModel, &ContextTableProxyModel::handleFilterTextChanged);
connect(mSearchbar, &Searchbar::textEdited, this, &ContextManagerWidget::updateSearchIcon);

mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this);
mShortCutDeleteItem->setEnabled(false);

connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey);
connect(mShortCutDeleteItem, &QShortcut::activated, this, &ContextManagerWidget::handleDeleteContextClicked);

connect(qApp, &QApplication::focusChanged, this, &ContextManagerWidget::handleDeleteShortcutOnFocusChanged);
}

void ContextManagerWidget::handleCreateContextClicked()
Expand Down Expand Up @@ -167,6 +176,8 @@ namespace hal

void ContextManagerWidget::handleDeleteContextClicked()
{
QModelIndex current = mContextTableView->currentIndex();
if (!current.isValid()) return;
GraphContext* clicked_context = getCurrentContext();
ActionDeleteObject* act = new ActionDeleteObject;
act->setObject(UserActionObject(clicked_context->id(),UserActionObjectType::Context));
Expand Down Expand Up @@ -446,4 +457,20 @@ namespace hal
{
mSearchActiveIconStyle = style;
}

void ContextManagerWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget)
{
if(!newWidget) return;
if(newWidget->parent() == this)
{
mShortCutDeleteItem->setEnabled(true);
return;
}
else
{
mShortCutDeleteItem->setEnabled(false);
return;
}
}

}
28 changes: 28 additions & 0 deletions plugins/gui/src/grouping/grouping_manager_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "gui/selection_details_widget/tree_navigation/selection_tree_view.h"

#include <QAction>
#include <QApplication>
#include <QColorDialog>
#include <QHeaderView>
#include <QImage>
Expand Down Expand Up @@ -114,6 +115,14 @@ namespace hal
connect(mGroupingTableModel, &GroupingTableModel::newEntryAdded, this, &GroupingManagerWidget::handleNewEntryAdded);
connect(mGroupingTableView, &QTableView::doubleClicked, this, &GroupingManagerWidget::handleDoubleClicked);
handleCurrentChanged();

mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this);
mShortCutDeleteItem->setEnabled(false);

connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey);
connect(mShortCutDeleteItem, &QShortcut::activated, this, &GroupingManagerWidget::handleDeleteGroupingClicked);

connect(qApp, &QApplication::focusChanged, this, &GroupingManagerWidget::handleDeleteShortcutOnFocusChanged);
}

QList<QShortcut*> GroupingManagerWidget::createShortcuts()
Expand Down Expand Up @@ -511,6 +520,10 @@ namespace hal

void GroupingManagerWidget::handleDeleteGroupingClicked()
{
if (!hasFocus() && !mGroupingTableView->hasFocus()) return;

QModelIndex current = mGroupingTableView->currentIndex();
if (!current.isValid()) return;
int irow = mProxyModel->mapToSource(mGroupingTableView->currentIndex()).row();
u32 grpId = mGroupingTableModel->groupingAt(irow).id();
ActionDeleteObject* act = new ActionDeleteObject;
Expand Down Expand Up @@ -835,4 +848,19 @@ namespace hal
{
mTableIconStyle = style;
}

void GroupingManagerWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget)
{
if(!newWidget) return;
if(newWidget->parent() == this)
{
mShortCutDeleteItem->setEnabled(true);
return;
}
else
{
mShortCutDeleteItem->setEnabled(false);
return;
}
}
} // namespace hal
40 changes: 39 additions & 1 deletion plugins/gui/src/module_widget/module_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "hal_core/netlist/module.h"
#include "hal_core/netlist/net.h"
#include "gui/module_model/module_model.h"
#include <QApplication>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QMenu>
Expand All @@ -24,7 +25,6 @@
#include <QShortcut>
#include <QTreeView>
#include <QVBoxLayout>
#include "hal_core/utilities/log.h"

namespace hal
{
Expand Down Expand Up @@ -73,6 +73,15 @@ namespace hal

connect(mSearchAction, &QAction::triggered, this, &ModuleWidget::toggleSearchbar);
connect(mSearchbar, &Searchbar::textEdited, this, &ModuleWidget::updateSearchIcon);

mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this);
mShortCutDeleteItem->setEnabled(false);

connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey);
connect(mShortCutDeleteItem, &QShortcut::activated, this, &ModuleWidget::deleteSelectedItem);

connect(qApp, &QApplication::focusChanged, this, &ModuleWidget::handleDeleteShortcutOnFocusChanged);

}

void ModuleWidget::setupToolbar(Toolbar* toolbar)
Expand Down Expand Up @@ -324,4 +333,33 @@ namespace hal
{
mSearchActiveIconStyle = style;
}

void ModuleWidget::deleteSelectedItem()
{
if(!mTreeView->currentIndex().isValid())
{
return;
}

ModuleItem* selectedItem = getModuleItemFromIndex(mTreeView->currentIndex());
if(selectedItem->parent() != nullptr)
{
gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id());
}
}

void ModuleWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget)
{
if(!newWidget) return;
if(newWidget->parent() == this)
{
mShortCutDeleteItem->setEnabled(true);
return;
}
else
{
mShortCutDeleteItem->setEnabled(false);
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace hal
connect(mSearchbar, &Searchbar::textEdited, this, &SelectionDetailsWidget::updateSearchIcon);
connect(mSelectionTreeView, &SelectionTreeView::itemDoubleClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked);
connect(mSelectionTreeView, &SelectionTreeView::focusItemClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked);

}

void SelectionDetailsWidget::selectionToModuleMenu()
Expand Down

0 comments on commit 1c20611

Please sign in to comment.