Allow setting output format for --getcolor
ClosedPublic

Authored by yuehangwu on Mar 7 2017, 12:56 PM.

Details

Summary

add --format switch for setting output color and use regex to match format pattern for sanity check before trigger sprintf.
e.g. kdialog --getcolor --format "%+3.7f %.4f %5f" in "%[flag][width][precision][length]<conversion specifier>"

BUG: 340399

Test Plan

kdialog --getcolor --format "Qcolor(%#x, %+2.2lx, %#+3.3lx)"
Qcolor(0x6d, +60, +0x07b)

Diff Detail

Repository
R229 KDialog
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
yuehangwu created this revision.Mar 7 2017, 12:56 PM

Hi, @cfeck please take a look, thanks

This patch is updated almost according https://bugs.kde.org/show_bug.cgi?id=340399 except the following two.

  1. When adding %1$ %2$ to enable reorder RGB channel, I was told "ISO C++11 does not support %n$ operand number formats [-Wformat=]";
  1. For "L" specifier expects long double while in QColor only has qreal and if we call asprinf("%Lg", redF()), we'll get an Nan outcome. Since qreal of QColor is double on all platform except float on ARM, this patch does skip this length specifier.
cfeck requested changes to this revision.Mar 7 2017, 9:25 PM

Very nice. Only two minor nitpicks.

src/kdialog.cpp
905

Just remove case sensitivity flag.

937

Do not change this. The output indeed needs to be in system locale format.

This revision now requires changes to proceed.Mar 7 2017, 9:25 PM
yuehangwu updated this revision to Diff 12278.Mar 8 2017, 3:54 AM
yuehangwu edited edge metadata.
  1. remove case sensitive when strip out star;
  2. refine output with locale
cfeck accepted this revision.Mar 8 2017, 4:17 AM

Merci, good to go in.

This revision is now accepted and ready to land.Mar 8 2017, 4:17 AM
yuehangwu marked 2 inline comments as done.Mar 8 2017, 12:06 PM
In D4966#93520, @cfeck wrote:

Merci, good to go in.

thank you for your great advice too :p

This revision was automatically updated to reflect the committed changes.