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 Sep 30, 2023
1 parent 81b8107 commit 8d24ead
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 2 deletions.
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 All @@ -214,5 +222,6 @@ namespace hal
void toggleSearchbar();

QList<QShortcut*> createShortcuts() override;
void deleteSelectedContext();
};
}
6 changes: 6 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,9 @@ namespace hal
QString mDisabledIconStyle;
GroupingColorSerializer mColorSerializer;

QShortcut* mShortCutDeleteItem;

GroupingTableEntry getCurrentGrouping();
void deleteSelectedGrouping();
};
} // namespace hal
8 changes: 8 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,9 @@ namespace hal
void handleModuleRemoved(Module* module, u32 module_id);


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

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

ModuleProxyModel* mModuleProxyModel;

QShortcut* mShortCutDeleteItem;

void openModuleInView(const QModelIndex& index);

ModuleItem* getModuleItemFromIndex(const QModelIndex& index);
void deleteSelectedItem();
};
} // namespace hal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "gui/content_widget/content_widget.h"
#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h"
#include "hal_core/defines.h"
#include "gui/settings/settings_items/settings_item_keybind.h"


class QTableWidget;
class QStackedWidget;
Expand Down Expand Up @@ -76,7 +78,8 @@ namespace hal
*
* @param parent - The widget's parent.
*/
SelectionDetailsWidget(QWidget* parent = nullptr);
SelectionDetailsWidget(
QWidget* parent = nullptr);

/**
* Overrides the ContentWidget's setupToolbar method. Adds its specific actions to the given toolbar
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
29 changes: 29 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,16 @@ 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->handleDeleteContextClicked();
});

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

void ContextManagerWidget::handleCreateContextClicked()
Expand Down Expand Up @@ -167,6 +178,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 +459,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,16 @@ 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->handleDeleteGroupingClicked();
});

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

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

void GroupingManagerWidget::handleDeleteGroupingClicked()
{
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
42 changes: 41 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,17 @@ 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->deleteSelectedItem();
});

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

}

void ModuleWidget::setupToolbar(Toolbar* toolbar)
Expand Down Expand Up @@ -324,4 +335,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 8d24ead

Please sign in to comment.