-
Notifications
You must be signed in to change notification settings - Fork 253
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
base: master
Are you sure you want to change the base?
Configure Keyboard Shortcuts #637
Conversation
Configured all the keyboard shortcuts of DLT Viewer Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
src/mainwindow.cpp
Outdated
void MainWindow::on_actionShortcuts_List_triggered(){ | ||
qDebug() <<"Shortcuts Triggered"; | ||
|
||
QDialog *shortcutDialog = new QDialog(this); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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:
- Create the dialog on the stack in this function
- Have this dialog as the member of mainwindow class, create it once upon mainwindow creation
There was a problem hiding this comment.
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]>
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qDebug() <<"Shortcuts Triggered"; |
src/mainwindow.cpp
Outdated
layout->addWidget(table); | ||
|
||
shortcutDialog.setLayout(layout); | ||
shortcutDialog.show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shortcutDialog.show(); | |
shortcutDialog.exec(); |
src/mainwindow.cpp
Outdated
|
||
QTableView *table = new QTableView(&shortcutDialog); | ||
table->setObjectName("Shortcuts Summarise Table"); | ||
QStandardItemModel *model = new QStandardItemModel(0, 2, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QStandardItemModel *model = new QStandardItemModel(0, 2, this); | |
QStandardItemModel *model = new QStandardItemModel(0, 2, &shortcutDialog); |
src/mainwindow.cpp
Outdated
QFont BoldFont; | ||
BoldFont.setBold(true); | ||
|
||
QStandardItem *headerName = new QStandardItem("Name"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QStandardItem *headerName = new QStandardItem("Name"); | |
QStandardItem *headerName = new QStandardItem("Action name"); |
src/mainwindow.cpp
Outdated
QFont BoldFont; | ||
BoldFont.setBold(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QFont BoldFont; | |
BoldFont.setBold(true); | |
QFont headerFont; | |
headerFont.setBold(true); |
model->setHorizontalHeaderItem(1, headerFeature); | ||
|
||
// Define shortcut list using QPair | ||
QList<QPair<QString, QString>> shortcutsList = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like that, yes
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
Changes made for saving the list of shortcuts to variables and accessing them Signed-off by : RenuPriya Krishnamoorthy <[email protected]>
Configured all the keyboard shortcuts of DLT Viewer
Signed-off by : RenuPriya Krishnamoorthy [email protected]