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

Conversation

Pavithra-aa-Anand
Copy link
Collaborator

Configured all the keyboard shortcuts of DLT Viewer

Signed-off by : RenuPriya Krishnamoorthy [email protected]

Configured all the keyboard shortcuts of DLT Viewer

Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
void MainWindow::on_actionShortcuts_List_triggered(){
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

Changes were made in mainwindow.h and merged the latest changes from upstream.

Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
@alexmucde alexmucde added this to the Release v2.28.0 milestone Feb 25, 2025
Pavithra-aa-Anand and others added 2 commits February 26, 2025 09:52
Update in QList and QDialog for summarising the shortcuts

Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
shortcutDialog.setWindowTitle("Shortcuts List");
shortcutDialog.resize(600, 400);

QTableView *table = new QTableView(&shortcutDialog);
Copy link
Collaborator

@vifactor vifactor Feb 27, 2025

Choose a reason for hiding this comment

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

with the way you changed it, you still "leak" memory for these allocations. My suggestion was to define shortcutDialog on the stack, but not as a class member

Copy link

@Renu-Priya411 Renu-Priya411 Feb 27, 2025

Choose a reason for hiding this comment

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

Okay. In that case, QDialog will be initialised inside the the function as "QDialog shortcutDialog(this)". Using this case dialog will be destroyed once its out of scope. Please let me know if my understanding correct ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

void MainWindow::on_actionShortcuts_List_triggered(){
    QDialog shortcutDialog;
    [...]
    shortcutDialog.exec();
}

this is what I mean

@@ -5547,6 +5548,69 @@ 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";

layout->addWidget(table);

shortcutDialog.setLayout(layout);
shortcutDialog.show();
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
shortcutDialog.show();
shortcutDialog.exec();


QTableView *table = new QTableView(&shortcutDialog);
table->setObjectName("Shortcuts Summarise Table");
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);

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");

Comment on lines 5561 to 5562
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);

model->setHorizontalHeaderItem(1, headerFeature);

// Define shortcut list using QPair
QList<QPair<QString, QString>> shortcutsList = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how can you ensure that this list of shortcuts remains valid over the time? For example, some contributor can come and change "Copy Payload", "Ctrl + P" to "Copy Payload", "Ctrl + J", then list will be outdated, but it would be hard to notice.

Copy link

@Renu-Priya411 Renu-Priya411 Feb 28, 2025

Choose a reason for hiding this comment

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

Shall I keep the table in an editable format, so that any contributor can edit it if incase there is any change ? Remaining changes I have already made.

Copy link
Collaborator

@vifactor vifactor Feb 28, 2025

Choose a reason for hiding this comment

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

my point is that you define shortcut combinations in two different unrelated places (where is Ctrl + P first mentioned?) with time this will lead to the issue, that this table contains outdated info because somebody did not fix it when changing shortcut combination. I do not see how making the table editable can help here. What might help is to define a central place where all combinations are defined like variables and use the corresponding variable in every place where it appears

Choose a reason for hiding this comment

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

for E.g :
QString Payload = "Ctrl + P";
QString New = " Ctrl + N";

The variables will be defined in a separate place and Payload, New, etc will be used for creating a summarised table. If any changes are made to the existing shortcuts this variable has to changed within the code and if a new shortcut is created a new variable has to be added. Is this the expected way of implementation ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

something like that, yes

Copy link

@Renu-Priya411 Renu-Priya411 Mar 4, 2025

Choose a reason for hiding this comment

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

const QString shortcutNew = "Ctrl + N";

const QString shortcutOpen = "Ctrl + O";

const QString shortcutSave = "Ctrl + S";

const QString shortcutClear = "Ctrl + E";

// Store shortcuts dynamically using a list of pairs

QList<QPair<QString, QString>> shortcutsList = {

    {"New", shortcutNew},

    {"Open", shortcutOpen},

    {"Save As", shortcutSave},

    {"Clear", shortcutClear}

};

This is how the implementation looks. If any changes are made the variable has to be changed and then it has to be added to the QList. This process is more or less similar to the old one. In the old method it was one QList and here we have variables which are added to the QList. To display all the shortcuts in a table

, I want all the data in one container. Hence all the shortcuts has to be present in a consolidated containers like QList or QMap. May i know is it okay to go with this implementation ?

Copy link
Collaborator

@vifactor vifactor Mar 4, 2025

Choose a reason for hiding this comment

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

please provide a commit with the changes, it is hard to see what you are going to do exactly from the comment

Pavithra-aa-Anand and others added 2 commits March 2, 2025 19:24
Changes made for saving the list of shortcuts to variables and accessing them
Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ToDo
Development

Successfully merging this pull request may close these issues.

5 participants