Skip to content

Commit

Permalink
Fix crash when last tab is closed or key pressed without tab #334
Browse files Browse the repository at this point in the history
  • Loading branch information
DamirPorobic committed Feb 22, 2024
1 parent 49eb251 commit 52ed4a9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change log

## Release 0.7.1
* Fixed: Crash after pressing key when no tab exists or closing last tab. ([#271](https://github.com/ksnip/kImageAnnotator/issues/334))

## Release 0.7.0
* New: Allow copying items between tabs. ([#318](https://github.com/ksnip/kImageAnnotator/issues/318))
* New: CTRL + A does not select all text typed. ([#198](https://github.com/ksnip/kImageAnnotator/issues/198))
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(kImageAnnotator LANGUAGES CXX VERSION 0.7.0)
project(kImageAnnotator LANGUAGES CXX VERSION 0.7.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# kImageAnnotator [![Linux Build Status][github-badge-linux]][github-url-linux] [![Windows Build Status][github-badge-windows]][github-url-windows] [![Translation status][weblate-badge]][weblate-url]
Tool for annotating images

Version 0.7.0
Version 0.7.1

![kImageAnnotator](https://i.imgur.com/4vlPDUn.png "kImageAnnotator")

Expand Down
20 changes: 12 additions & 8 deletions src/common/filter/KeyEventFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ KeyEventFilter::~KeyEventFilter()
QCoreApplication::instance()->removeEventFilter(this);
}


void KeyEventFilter::setListener(IKeyEventListener *listener)
{
Q_ASSERT(listener != nullptr);

mKeyEventListener = listener;
}

Expand All @@ -58,21 +55,28 @@ void KeyEventFilter::handleKeyReleased(QEvent *event)
if(mPressedKeyCodes.contains(keyEvent->key())) {
mPressedKeyCodes.removeAll(keyEvent->key());

Q_ASSERT(mKeyEventListener != nullptr);
mKeyEventListener->keyReleased(keyEvent);
if(isListenerSet()) {
mKeyEventListener->keyReleased(keyEvent);
}
}
}

void KeyEventFilter::handleKeyPressed(QEvent *event)
{
auto keyEvent = dynamic_cast<QKeyEvent *>(event);

if(!mPressedKeyCodes.contains(keyEvent->key())) {
if(isListenerSet() && !mPressedKeyCodes.contains(keyEvent->key())) {
mPressedKeyCodes.append(keyEvent->key());

Q_ASSERT(mKeyEventListener != nullptr);
mKeyEventListener->keyPressed(keyEvent);
if(isListenerSet()) {
mKeyEventListener->keyPressed(keyEvent);
}
}
}

bool KeyEventFilter::isListenerSet()
{
return mKeyEventListener != nullptr;
}

} // namespace kImageAnnotator
1 change: 1 addition & 0 deletions src/common/filter/KeyEventFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class KeyEventFilter : public QObject

void handleKeyPressed(QEvent *event);
void handleKeyReleased(QEvent *event);
bool isListenerSet();
};

} // namespace kImageAnnotator
Expand Down

0 comments on commit 52ed4a9

Please sign in to comment.