-
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?
Changes from 1 commit
11e77ac
c3ec584
22cd787
aec0909
1985da7
7e776e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5625,6 +5625,78 @@ void MainWindow::on_action_menuHelp_Command_Line_triggered() { | |||||||||
QDltOptManager::getInstance()->getHelpText()); | ||||||||||
} | ||||||||||
|
||||||||||
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 commentThe 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 commentThe 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 commentThe 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 My approach (in order of preference) would be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
QFont BoldFont; | ||||||||||
BoldFont.setBold(true); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
QStandardItem *headerName = new QStandardItem("Name"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
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"}; | ||||||||||
vifactor marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
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(); | ||||||||||
|
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.