From c6026e8a0fbebdb07c7689231d564763155a334a Mon Sep 17 00:00:00 2001 From: Kelly Byrd Date: Tue, 31 Jan 2017 22:35:46 -0800 Subject: [PATCH] Re #4224 Add "rename" item to Category context menu in companion. (#4360) - Adds "rename" to the context menu for categories, it uses the same code path as the default dblClick handler for the base class. - Added a separator so the context menu looks more like the one for models - Some whitespace changes in mdichild.h, my editor truncates whitespace on blank lines. --- companion/src/mdichild.cpp | 15 +++++++++++++++ companion/src/mdichild.h | 11 ++++++----- companion/src/modelslist.cpp | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 80f9d5b54..49e67e3fe 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -139,6 +139,8 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos) else if (IS_HORUS(firmware->getBoard())) { if (modelsListModel->getCategoryIndex(modelIndex) >= 0) { contextMenu.addAction(CompanionIcon("add.png"), tr("&Add model"), this, SLOT(modelAdd())); + contextMenu.addSeparator(); + contextMenu.addAction(CompanionIcon("rename.png"), tr("&Rename category"), this, SLOT(categoryRename())); contextMenu.addAction(CompanionIcon("delete.png"), tr("&Delete category"), this, SLOT(categoryDelete())); } else { @@ -370,6 +372,19 @@ void MdiChild::categoryAdd() setModified(); } +void MdiChild::categoryRename() +{ + QModelIndex modelIndex = ui->modelsList->currentIndex(); + int categoryIndex = modelsListModel->getCategoryIndex(modelIndex); + if (categoryIndex < 0 || categoryIndex >= (int)radioData.categories.size()) { + return; + } + + // Not calling setModified() here because QAbstractItemView::edit will + // haandle it if the user actually makes a change + ui->modelsList->edit(modelIndex); +} + void MdiChild::categoryDelete() { int categoryIndex = modelsListModel->getCategoryIndex(ui->modelsList->currentIndex()); diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 64985ae32..c4248327d 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -54,7 +54,7 @@ class MdiChild : public QWidget int getCurrentRow() const; void refresh(bool expand=false); void keyPressEvent(QKeyEvent * event); - + signals: void copyAvailable(bool val); @@ -69,12 +69,13 @@ class MdiChild : public QWidget void on_radioSettings_clicked(); void setDefault(); void onFirmwareChanged(); - + public slots: void showModelsListContextMenu(const QPoint & pos); void checkAndInitModel(int row); void generalEdit(); void categoryAdd(); + void categoryRename(); void categoryDelete(); void modelAdd(); void modelEdit(); @@ -84,7 +85,7 @@ class MdiChild : public QWidget void confirmDelete(); void deleteSelectedModels(); void onDataChanged(const QModelIndex & index); - + void cut(); void copy(); void paste(); @@ -101,11 +102,11 @@ class MdiChild : public QWidget void doCopy(QByteArray * gmData); void doPaste(QByteArray * gmData, int index); void initModelsList(); - + MainWindow * parent; Ui::MdiChild * ui; TreeModel * modelsListModel; - + QString curFile; Firmware * firmware; diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index d8d732894..ab0f227a7 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -321,7 +321,7 @@ ModelsListWidget::ModelsListWidget(QWidget * parent): { setColumnWidth(0, 50); setColumnWidth(2, 100); - + active_highlight_color = palette().color(QPalette::Active, QPalette::Highlight); } @@ -337,7 +337,7 @@ void ModelsListWidget::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) return; - + if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return;