Skip to content

Commit

Permalink
merge #88
Browse files Browse the repository at this point in the history
Merge branch
'frickler24-testing-issue-38-SIGSEGV_when_deleting_copied_profile'
into testing

* fixes #38
  • Loading branch information
Oleksii Vilchanskyi committed Mar 4, 2017
2 parents a2d4d7e + a9ff339 commit f219fc8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/ckb/kbbind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,37 @@ KbBind::KbBind(KbMode* modeParent, Kb* parentBoard, const KeyMap& keyMap) :
_winLock(false), _needsUpdate(true), _needsSave(true) {
}

///
/// \brief KbBind::KbBind // copy all existing Key bindings
/// \param modeParent
/// \param parentBoard
/// \param keyMap
/// \param other
///
KbBind::KbBind(KbMode* modeParent, Kb* parentBoard, const KeyMap& keyMap, const KbBind& other) :
QObject(modeParent), _devParent(parentBoard), lastGlobalRemapTime(globalRemapTime), _bind(other._bind),
_winLock(false), _needsUpdate(true), _needsSave(true) {
map(keyMap);

/// Create a new Hash table and copy all entries
QHash<QString, KeyAction*> newBind;
foreach(QString key, _bind.keys()) {
KeyAction* act = _bind.value(key);
if(act) {
newBind[key] = new KeyAction(act->value(), this);
}
}

/// clear the destination list (there are the original KeyActions as references, so do not delete them)
_bind.clear();
foreach(QString key, newBind.keys()) {
KeyAction* act = newBind.value(key);
if(act) {
/// and move the KeyActions we just created
_bind[key] = new KeyAction(act->value(), this);
}
}
newBind.clear(); // here we *must not* delete the KeyActions, because they are referenced by _bind now
}

KbPerf* KbBind::perf(){
Expand Down
8 changes: 7 additions & 1 deletion src/ckb/kbbind.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ class KbBind : public QObject
public:
// New binding setup
explicit KbBind(KbMode* modeParent, Kb* devParent, const KeyMap& keyMap);
// Copy a binding setup
///
/// \brief KbBind
/// \param modeParent
/// \param devParent
/// \param keyMap
/// \param other This is the KbBind object to copy from
/// Use this constructor to copy an existing Binding
KbBind(KbMode* modeParent, Kb* devParent, const KeyMap& keyMap, const KbBind& other);

// Load and save from stored settings
Expand Down
12 changes: 12 additions & 0 deletions src/ckb/kbmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const QString &guid, const QStr
_id.guid = QUuid::createUuid();
}

///
/// \brief KbMode::KbMode
/// \param parent Kb as parent (append to the Keyboard list
/// \param keyMap Map to copy from
/// \param other Mode to copy from
/// Constructor to copy an existing Keyboard-Mode KbMode &other
KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other) :
QObject(parent),
_name(other._name), _id(other._id),
Expand Down Expand Up @@ -76,3 +82,9 @@ bool KbMode::needsSave() const {
void KbMode::doUpdate(){
emit updated();
}

///
/// \brief KbMode::~KbMode
/// Destructor may be used for Debugging (issue #38 with SIGSEGV). Insert qDebug-statement
KbMode::~KbMode() {
}
2 changes: 2 additions & 0 deletions src/ckb/kbmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class KbMode : public QObject
// Mode by copy
KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other);

~KbMode();

// Mode properties
inline const QString& name() const { return _name; }
inline void name(const QString& newName) { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
Expand Down
7 changes: 7 additions & 0 deletions src/ckb/kbwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ void KbWidget::on_modesList_itemClicked(QListWidgetItem* item){
}
}

///
/// \brief KbWidget::on_modesList_customContextMenuRequested
/// \param pos
/// Opens on right click in the profiles list a context sensitive menue
/// at position pos.
///
/// When clicking on a command it is located and executed.
void KbWidget::on_modesList_customContextMenuRequested(const QPoint &pos){
QListWidgetItem* item = ui->modesList->itemAt(pos);
if(!item || !currentMode || item->data(GUID).toUuid() != currentMode->id().guid)
Expand Down
3 changes: 2 additions & 1 deletion src/ckb/keyaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class KeyAction : public QObject

~KeyAction();
private:
// Don't copy key actions (the old one needs to be deleted first)
/// ccMSC: Don't copy key actions (the old one needs to be deleted first)
/// frickler24: statement left as described, but copying is done in KbBind copy constructor
inline void operator=(const KeyAction& rhs) {}
inline KeyAction(const KeyAction& rhs) : QObject() {}

Expand Down

0 comments on commit f219fc8

Please sign in to comment.