Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Keyboard Shortcuts #637

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5625,6 +5625,78 @@ void MainWindow::on_action_menuHelp_Command_Line_triggered() {
QDltOptManager::getInstance()->getHelpText());
}

void MainWindow::on_actionShortcuts_List_triggered(){
qDebug() <<"Shortcuts Triggered";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qDebug() <<"Shortcuts Triggered";


QDialog *shortcutDialog = new QDialog(this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are going to create new dialog every time this function is triggered, show it once and keep it on the heap whole app lifecycle with no possibility to show it again, effectively leaking the memory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a static pointer will assure that QDialog is created only once and allocating a memory for it will handle memory leaking as well. May i know if your opinion on this, if i can proceed forward with this idea ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it static will work, but then you'll need to wrap whole creation logic into if (dialog) to check if it was already created.

My approach (in order of preference) would be:

  1. Create the dialog on the stack in this function
  2. Have this dialog as the member of mainwindow class, create it once upon mainwindow creation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I didnt wrap the whole logic in if(dialog). I have given a return if the dialog is already opened and the logic continues. I will try to implement your approach as well. Thank u for the input

shortcutDialog->setWindowTitle("Shortcuts List");
shortcutDialog->resize(600, 400);

// Create a table view
QTableView *table = new QTableView(shortcutDialog);
table->setObjectName("Summarise Table");

// Create and set up the model
QStandardItemModel *model = new QStandardItemModel(0, 2, this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QStandardItemModel *model = new QStandardItemModel(0, 2, this);
QStandardItemModel *model = new QStandardItemModel(0, 2, &shortcutDialog);


QFont BoldFont;
BoldFont.setBold(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QFont BoldFont;
BoldFont.setBold(true);
QFont headerFont;
headerFont.setBold(true);


QStandardItem *headerName = new QStandardItem("Name");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QStandardItem *headerName = new QStandardItem("Name");
QStandardItem *headerName = new QStandardItem("Action name");

headerName->setFont(BoldFont);
model->setHorizontalHeaderItem(0, headerName);

QStandardItem *headerFeature = new QStandardItem("Shortcuts");
headerFeature->setFont(BoldFont);
model->setHorizontalHeaderItem(1, headerFeature);

// Fill the model with data (unchanged)
QStringList names = {"New", "Open", "Save As", "Clear", "Import DLT Stream",
"Import DLT Stream with serial header", "Find", "Jump To",
"New Project", "Open Project", "Save Project", "Expand All ECU",
"Collapse All ECU", "Copy Payload", "Info", "Quit"};
QStringList shortcuts = {"Ctrl + N", "Ctrl + O", "Ctrl + S", "Ctrl + E", "Ctrl + I",
"Ctrl + J", "Ctrl + F", "Ctrl + G", "Ctrl + Shift + G",
"Ctrl + Shift + O", "Ctrl + Shift + S", "Ctrl++", "Ctrl+",
"Ctrl + P", "F1", "Ctrl + Q"};

for (int i = 0; i < names.size(); ++i) {
model->insertRow(i);
model->setData(model->index(i, 0), names[i]);
model->setData(model->index(i, 1), shortcuts[i]);

// Make the items non-editable
for (int j = 0; j < 2; ++j) {
QStandardItem *item = model->item(i, j);
if (item) {
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
}
}
}

// Center-align the data
for (int row = 0; row < model->rowCount(); ++row) {
for (int col = 0; col < model->columnCount(); ++col) {
QModelIndex index = model->index(row, col);
model->setData(index, Qt::AlignCenter, Qt::TextAlignmentRole);
}
}

// Set the model in the table
table->setModel(model);

// Set column widths
table->setColumnWidth(0, 275);
table->setColumnWidth(1, 275);

// Create a layout and add the table to it
QVBoxLayout *layout = new QVBoxLayout(shortcutDialog);
layout->addWidget(table);

shortcutDialog->setLayout(layout);
shortcutDialog->exec();
}

void MainWindow::on_pluginWidget_itemSelectionChanged()
{
QList<QTreeWidgetItem *> list = project.plugin->selectedItems();
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <QColor>
#include <QComboBox>
#include <QProgressBar>
#include <QTableWidget>
#include <QAbstractItemModel>
#include <QStandardItemModel>

#include "tablemodel.h"
#include "settingsdialog.h"
Expand Down Expand Up @@ -454,6 +457,7 @@ private slots:
void on_action_menuHelp_Support_triggered();
void on_action_menuHelp_Info_triggered();
void on_action_menuHelp_Command_Line_triggered();
void on_actionShortcuts_List_triggered();

// Config methods
void on_action_menuConfig_Context_Delete_triggered();
Expand Down
10 changes: 8 additions & 2 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>23</number>
<number>27</number>
</attribute>
</widget>
</item>
Expand All @@ -93,7 +93,7 @@
<x>0</x>
<y>0</y>
<width>1001</width>
<height>22</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -211,6 +211,7 @@
<addaction name="action_menuHelp_Support"/>
<addaction name="separator"/>
<addaction name="action_menuHelp_Command_Line"/>
<addaction name="actionShortcuts_List"/>
</widget>
<widget class="QMenu" name="menuDLT">
<property name="title">
Expand Down Expand Up @@ -1691,6 +1692,11 @@
<string>Append...</string>
</property>
</action>
<action name="actionShortcuts_List">
<property name="text">
<string>Shortcuts List</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
Loading