Skip to content

Conversation

@stefonarch
Copy link
Member

@stefonarch stefonarch commented Jan 20, 2026

While looking if it would be possible to show results also on KP_Enter and Return (which seems quite hard to implement) I noticed that the calculator shows results in realtime by entering "=" before, afaik that is undocumented (for all the years I had to press = (shift+0) which wasn't convenient).

With this PR the calculator will start also when entering numbers and an operator and act the same as when "=" is inserted.

immagine

@stefonarch stefonarch moved this to Improvements in Release 2.4 Jan 20, 2026
providers.cpp Outdated
s.chop(1);
}

QRegularExpression mathPattern(QStringLiteral("^[0-9+\\-*/ ]+$"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I personally don't agree, that the calculator should be triggered w/o the equal sign (either at the beginning or at the end).
  2. Constructing (and compiling) the regex on each call is not resource friendly.
  3. The regexp is really a simple one and doesn't cover all possible equations.

Copy link
Member Author

@stefonarch stefonarch Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points (except 1. as I dislike = as it's not handy on my keyboard) . What about something like this

    if (s.at(0).isDigit())
    {
        is_math = true;
    }

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you, but with this I would also go safe side and check the s.empty()-ness before accessing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@tsujan
Copy link
Member

tsujan commented Jan 28, 2026

I don't agree with the idea behind this (if I have understood it correctly). Redundant computations aren't good in general, and it solves no problem.

@stefonarch
Copy link
Member Author

stefonarch commented Jan 28, 2026

it solves no problem

It's years that I search for an easier method than hitting always = for showing the result or starting the calculator (which I learned only looking at the code now). Actually I wanted to use enter or KP_Enter for showing the result first, but that's way more complicated.

Just being able to start typing something like 895-216 and immediately having the result is a real improvement. We check for = at start and at end, another check for digit isn't that redundant IMO.

@tsujan
Copy link
Member

tsujan commented Jan 28, 2026

A KDE or GNOME dev may not care about these things. But keeping an app lightweight isn't something that's done automatically; it consists of small steps of avoiding extra resource usage.

In addition, it may seem good in an elementary case like 895-216 but can be a nuisance in long or complex cases.

@stefonarch
Copy link
Member Author

Example for nuisance?

Chatgpt:

what is the additional impact from isDigit on computation (let's assume on an old laptop) here?

immagine

@tsujan
Copy link
Member

tsujan commented Jan 28, 2026

Chatgpt:

That's more than enough for me ;)

@stefonarch
Copy link
Member Author

stefonarch commented Jan 28, 2026

It was you who said time ago its coredump analysis was really correct. Ignore the messenger of the unwanted truth?

@tsujan
Copy link
Member

tsujan commented Jan 28, 2026

Yes, that case was an exception. It has no "idea" what we're doing here, let alone a perspective, because it has no intelligence but an algorithm to satisfy the questioner.

@stefonarch
Copy link
Member Author

So you would say it's wrong and the computation is indeed measurable and we'll loose therefore lightweight in the runner? Getting tired here.

@tsujan
Copy link
Member

tsujan commented Jan 28, 2026

I don't intend to convince you. I just told my opinion and my reasons for it, as @palinek did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Improvements

Development

Successfully merging this pull request may close these issues.

3 participants