@@ -10,29 +10,59 @@ ColumnDisplayFormatDialog::ColumnDisplayFormatDialog(const QString& colname, QSt
1010 // Create UI
1111 ui->setupUi (this );
1212 ui->comboDisplayFormat ->addItem (tr (" Default" ), " default" );
13- ui->comboDisplayFormat ->addItem ( tr ( " Apple NSDate to date " ), " appleDate " );
13+ ui->comboDisplayFormat ->insertSeparator (ui-> comboDisplayFormat -> count () );
1414 ui->comboDisplayFormat ->addItem (tr (" Decimal number" ), " decimal" );
1515 ui->comboDisplayFormat ->addItem (tr (" Exponent notation" ), " exponent" );
1616 ui->comboDisplayFormat ->addItem (tr (" Hex blob" ), " hexblob" );
1717 ui->comboDisplayFormat ->addItem (tr (" Hex number" ), " hex" );
18- ui->comboDisplayFormat ->addItem (tr (" Java epoch (milliseconds) to date" ), " javaEpoch" );
19- ui->comboDisplayFormat ->addItem (tr (" Julian day to date" ), " julian" );
20- ui->comboDisplayFormat ->addItem (tr (" Lower case" ), " lower" );
2118 ui->comboDisplayFormat ->addItem (tr (" Octal number" ), " octal" );
2219 ui->comboDisplayFormat ->addItem (tr (" Round number" ), " round" );
20+ ui->comboDisplayFormat ->insertSeparator (ui->comboDisplayFormat ->count ());
21+ ui->comboDisplayFormat ->addItem (tr (" Apple NSDate to date" ), " appleDate" );
22+ ui->comboDisplayFormat ->addItem (tr (" Java epoch (milliseconds) to date" ), " javaEpoch" );
23+ ui->comboDisplayFormat ->addItem (tr (" Julian day to date" ), " julian" );
2324 ui->comboDisplayFormat ->addItem (tr (" Unix epoch to date" ), " epoch" );
24- ui->comboDisplayFormat ->addItem (tr (" Upper case" ), " upper" );
2525 ui->comboDisplayFormat ->addItem (tr (" Windows DATE to date" ), " winDate" );
26+ ui->comboDisplayFormat ->insertSeparator (ui->comboDisplayFormat ->count ());
27+ ui->comboDisplayFormat ->addItem (tr (" Lower case" ), " lower" );
28+ ui->comboDisplayFormat ->addItem (tr (" Upper case" ), " upper" );
2629 ui->labelDisplayFormat ->setText (ui->labelDisplayFormat ->text ().arg (column_name));
2730
31+ formatFunctions[" lower" ] = " lower(" + sqlb::escapeIdentifier (column_name) + " )" ;
32+ formatFunctions[" upper" ] = " upper(" + sqlb::escapeIdentifier (column_name) + " )" ;
33+ formatFunctions[" epoch" ] = " datetime(" + sqlb::escapeIdentifier (column_name) + " , 'unixepoch')" ;
34+ formatFunctions[" javaEpoch" ] = " strftime('%Y-%m-%d %H:%M:%S.', " + sqlb::escapeIdentifier (column_name) +
35+ " /1000, 'unixepoch') || (" + sqlb::escapeIdentifier (column_name) + " %1000)" ;
36+ formatFunctions[" winDate" ] = " datetime('1899-12-30', " + sqlb::escapeIdentifier (column_name) + " || \" days\" )" ;
37+ formatFunctions[" appleDate" ] = " datetime('2001-01-01', " + sqlb::escapeIdentifier (column_name) + " || \" seconds\" )" ;
38+ formatFunctions[" julian" ] = " datetime(" + sqlb::escapeIdentifier (column_name) + " )" ;
39+ formatFunctions[" round" ] = " round(" + sqlb::escapeIdentifier (column_name) + " )" ;
40+ formatFunctions[" hex" ] = " printf('0x%x', " + sqlb::escapeIdentifier (column_name) + " )" ;
41+ formatFunctions[" octal" ] = " printf('%o', " + sqlb::escapeIdentifier (column_name) + " )" ;
42+ formatFunctions[" exponent" ] = " printf('%e', " + sqlb::escapeIdentifier (column_name) + " )" ;
43+ formatFunctions[" hexblob" ] = " hex(" + sqlb::escapeIdentifier (column_name) + " )" ;
44+ formatFunctions[" decimal" ] = " printf('%d', " + sqlb::escapeIdentifier (column_name) + " )" ;
45+
2846 // Set the current format, if it's empty set the default format
2947 if (current_format.isEmpty ())
3048 {
3149 ui->comboDisplayFormat ->setCurrentIndex (0 );
3250 updateSqlCode ();
3351 } else {
34- ui->comboDisplayFormat ->addItem (tr (" Custom" ), " custom" );
35- ui->comboDisplayFormat ->setCurrentIndex (ui->comboDisplayFormat ->findData (" custom" ));
52+ QString formatName;
53+ for (auto & formatKey : formatFunctions.keys ()) {
54+ if (current_format == formatFunctions.value (formatKey)) {
55+ formatName = formatKey;
56+ break ;
57+ }
58+ }
59+
60+ if (formatName.isEmpty ()) {
61+ ui->comboDisplayFormat ->insertSeparator (ui->comboDisplayFormat ->count ());
62+ ui->comboDisplayFormat ->addItem (tr (" Custom" ), " custom" );
63+ formatName = " custom" ;
64+ }
65+ ui->comboDisplayFormat ->setCurrentIndex (ui->comboDisplayFormat ->findData (formatName));
3666 ui->editDisplayFormat ->setText (current_format);
3767 }
3868}
@@ -56,30 +86,7 @@ void ColumnDisplayFormatDialog::updateSqlCode()
5686
5787 if (format == " default" )
5888 ui->editDisplayFormat ->setText (sqlb::escapeIdentifier (column_name));
59- else if (format == " lower" )
60- ui->editDisplayFormat ->setText (" lower(" + sqlb::escapeIdentifier (column_name) + " )" );
61- else if (format == " upper" )
62- ui->editDisplayFormat ->setText (" upper(" + sqlb::escapeIdentifier (column_name) + " )" );
63- else if (format == " epoch" )
64- ui->editDisplayFormat ->setText (" datetime(" + sqlb::escapeIdentifier (column_name) + " , 'unixepoch')" );
65- else if (format == " javaEpoch" )
66- ui->editDisplayFormat ->setText (" strftime('%Y-%m-%d %H:%M:%S.', " + sqlb::escapeIdentifier (column_name) + " /1000, 'unixepoch') || (" + sqlb::escapeIdentifier (column_name) + " %1000)" );
67- else if (format == " winDate" )
68- ui->editDisplayFormat ->setText (" datetime ('1899-12-30', " + sqlb::escapeIdentifier (column_name) + " || \" days\" )" );
69- else if (format == " appleDate" )
70- ui->editDisplayFormat ->setText (" datetime ('2001-01-01', " + sqlb::escapeIdentifier (column_name) + " || \" seconds\" )" );
71- else if (format == " julian" )
72- ui->editDisplayFormat ->setText (" datetime(" + sqlb::escapeIdentifier (column_name) + " )" );
73- else if (format == " round" )
74- ui->editDisplayFormat ->setText (" round(" + sqlb::escapeIdentifier (column_name) + " )" );
75- else if (format == " hex" )
76- ui->editDisplayFormat ->setText (" printf('0x%x', " + sqlb::escapeIdentifier (column_name) + " )" );
77- else if (format == " octal" )
78- ui->editDisplayFormat ->setText (" printf('%o', " + sqlb::escapeIdentifier (column_name) + " )" );
79- else if (format == " exponent" )
80- ui->editDisplayFormat ->setText (" printf('%e', " + sqlb::escapeIdentifier (column_name) + " )" );
81- else if (format == " hexblob" )
82- ui->editDisplayFormat ->setText (" hex(" + sqlb::escapeIdentifier (column_name) + " )" );
83- else if (format == " decimal" )
84- ui->editDisplayFormat ->setText (" printf('%d', " + sqlb::escapeIdentifier (column_name) + " )" );
89+ else
90+ ui->editDisplayFormat ->setText (formatFunctions.value (format));
91+
8592}
0 commit comments