Skip to content

Commit

Permalink
Customizable format for .LOG feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rotter committed Jan 4, 2018
1 parent 6e5f24a commit 563ce40
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 95 deletions.
2 changes: 1 addition & 1 deletion resources/text/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2018.01.XX
2018.01.04
----------
Added:
* .LOG feature. (#17)
Expand Down
8 changes: 0 additions & 8 deletions src/gui/dialogs/formsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
<ui version="4.0">
<class>FormSettings</class>
<widget class="QDialog" name="FormSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>740</width>
<height>323</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
Expand Down
16 changes: 16 additions & 0 deletions src/gui/settings/settingseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SettingsEditor::SettingsEditor(Settings* settings, QWidget* parent)
m_ui.m_cmbIndentMode->addItem(tr("Tabs"), true);

connect(m_ui.m_cmbIndentMode, &QComboBox::currentTextChanged, this, &SettingsEditor::dirtifySettings);
connect(m_ui.m_cmbTimestampFormat, &QComboBox::currentTextChanged, this, &SettingsEditor::dirtifySettings);
connect(m_ui.m_spinIndentSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SettingsEditor::dirtifySettings);
connect(m_ui.m_spinTabSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SettingsEditor::dirtifySettings);
connect(m_ui.m_spinLineSpacing, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &SettingsEditor::dirtifySettings);
Expand All @@ -34,6 +35,20 @@ void SettingsEditor::loadSettings() {
m_ui.m_lblFontMain->setFont(qApp->textApplication()->settings()->mainFont());
m_ui.m_spinLineSpacing->setValue(qApp->textApplication()->settings()->lineSpacing());

QStringList date_patterns;

date_patterns << QSL("yyyy-MM-ddTHH:mm:ss") << QSL("MMM dd yyyy hh:mm:ss") <<
QSL("MMM d yyyy hh:mm:ss") << QSL("ddd, dd MMM yyyy HH:mm:ss") <<
QSL("dd MMM yyyy") << QSL("yyyy-MM-dd HH:mm:ss.z") << QSL("yyyy-MM-dd") <<
QSL("yyyy") << QSL("yyyy-MM") << QSL("yyyy-MM-dd") << QSL("yyyy-MM-ddThh:mm") <<
QSL("yyyy-MM-ddThh:mm:ss");

for (const QString& pattern : date_patterns) {
m_ui.m_cmbTimestampFormat->addItem(pattern);
}

m_ui.m_cmbTimestampFormat->setCurrentText(qApp->textApplication()->settings()->logTimestampFormat());

onEndLoadSettings();
}

Expand All @@ -45,6 +60,7 @@ void SettingsEditor::saveSettings() {
qApp->textApplication()->settings()->setTabSize(m_ui.m_spinTabSize->value());
qApp->textApplication()->settings()->setIndentWithTabs(m_ui.m_cmbIndentMode->currentData().toBool());
qApp->textApplication()->settings()->setMainFont(m_ui.m_lblFontMain->font());
qApp->textApplication()->settings()->setLogTimestampFormat(m_ui.m_cmbTimestampFormat->currentText());
qApp->textApplication()->settings()->blockSignals(false);

// NOTE: Execute last command with signals ON, so that editor do refresh their settings.
Expand Down
208 changes: 124 additions & 84 deletions src/gui/settings/settingseditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,118 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0" colspan="3">
<widget class="QGroupBox" name="m_gbIndentation">
<property name="title">
<string>Indentation</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Indent with</string>
</property>
<property name="buddy">
<cstring>m_cmbIndentMode</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_spinTabSize">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>32</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_spinIndentSize">
<property name="maximum">
<number>32</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tab size</string>
</property>
<property name="buddy">
<cstring>m_spinTabSize</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Indent size</string>
</property>
<property name="buddy">
<cstring>m_spinIndentSize</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbIndentMode"/>
</item>
<item row="0" column="2" rowspan="3">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="m_gbFonts">
<property name="title">
<string>Fonts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="m_btnFontMainChange">
<property name="text">
<string>&amp;Change</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="m_lblFontMain">
<property name="text">
<string>Text editor font</string>
</property>
<property name="buddy">
<cstring>m_btnFontMainChange</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand Down Expand Up @@ -70,102 +181,30 @@
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="m_gbFonts">
<property name="title">
<string>Fonts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="m_btnFontMainChange">
<property name="text">
<string>&amp;Change</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="m_lblFontMain">
<property name="text">
<string>Text editor font</string>
</property>
<property name="buddy">
<cstring>m_btnFontMainChange</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QGroupBox" name="m_gbIndentation">
<widget class="QGroupBox" name="m_gbLog">
<property name="title">
<string>Indentation</string>
<string>.LOG Feature</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Indent with</string>
<string>Timestamp format</string>
</property>
<property name="buddy">
<cstring>m_cmbIndentMode</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_spinTabSize">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>32</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_spinIndentSize">
<property name="maximum">
<number>32</number>
<cstring>m_cmbTimestampFormat</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tab size</string>
</property>
<property name="buddy">
<cstring>m_spinTabSize</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Indent size</string>
</property>
<property name="buddy">
<cstring>m_spinIndentSize</cstring>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbTimestampFormat">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbIndentMode"/>
</item>
<item row="0" column="2" rowspan="3">
<spacer name="horizontalSpacer_3">
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -187,6 +226,7 @@
<tabstop>m_cmbIndentMode</tabstop>
<tabstop>m_spinTabSize</tabstop>
<tabstop>m_spinIndentSize</tabstop>
<tabstop>m_cmbTimestampFormat</tabstop>
<tabstop>m_btnFontMainChange</tabstop>
</tabstops>
<resources/>
Expand Down
2 changes: 1 addition & 1 deletion src/gui/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void TextEditor::setIsLog(bool is_log) {
gotoPos(length());
newLine();

const QString date_str = QDateTime::currentDateTime().toString(Qt::DateFormat::DefaultLocaleShortDate);
const QString date_str = QDateTime::currentDateTime().toString(m_textApp->settings()->logTimestampFormat());

insertText(currentPos(), date_str.toUtf8().constData());
gotoPos(length());
Expand Down
2 changes: 2 additions & 0 deletions src/miscellaneous/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace Editor {
constexpr auto ID = "editor";
constexpr auto LogTimestampFormat = "log_timestamp_format";
const QString LogTimestampFormatDef = "yyyy-MM-dd HH:mm:ss";
constexpr auto TabSize = "tab_size";
constexpr auto TabSizeDef = 2;
constexpr auto IndentSize = "indent_size";
Expand Down
9 changes: 9 additions & 0 deletions src/miscellaneous/textapplicationsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ bool TextApplicationSettings::reloadModifiedDocumentsAutomatically() const {
return qApp->settings()->value(GROUP(Editor), SETTING(Editor::ReloadModified)).toBool();
}

QString TextApplicationSettings::logTimestampFormat() const {
return qApp->settings()->value(GROUP(Editor), SETTING(Editor::LogTimestampFormat)).toString();
}

int TextApplicationSettings::tabSize() const {
return qApp->settings()->value(GROUP(Editor), SETTING(Editor::TabSize)).toInt();
}
Expand All @@ -98,6 +102,11 @@ void TextApplicationSettings::decreaseFontSize() {
setMainFont(font_old);
}

void TextApplicationSettings::setLogTimestampFormat(const QString& format) {
qApp->settings()->setValue(GROUP(Editor), Editor::LogTimestampFormat, format);
emit settingsChanged(false, false);
}

void TextApplicationSettings::setReloadModifiedDocumentsAutomatically(bool reload_automatically) {
qApp->settings()->setValue(GROUP(Editor), Editor::ReloadModified, reload_automatically);
emit settingsChanged(false, false);
Expand Down
2 changes: 2 additions & 0 deletions src/miscellaneous/textapplicationsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TextApplicationSettings : public QObject {
int lineSpacing() const;
QFont mainFont() const;
bool reloadModifiedDocumentsAutomatically() const;
QString logTimestampFormat() const;

int tabSize() const;
int indentSize() const;
Expand All @@ -46,6 +47,7 @@ class TextApplicationSettings : public QObject {
void increaseFontSize();
void decreaseFontSize();

void setLogTimestampFormat(const QString& format);
void setReloadModifiedDocumentsAutomatically(bool reload_automatically);
void setTabSize(int size);
void setIndentSize(int size);
Expand Down
2 changes: 1 addition & 1 deletion textilosaurus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ APP_LOW_NAME = "textilosaurus"
APP_REVERSE_NAME = "com.github.textilosaurus"
APP_AUTHOR = "Martin Rotter"
APP_COPYRIGHT = "(C) 2018 $$APP_AUTHOR"
APP_VERSION = "2018.01.03"
APP_VERSION = "2018.01.04"
APP_LONG_NAME = "$$APP_NAME $$APP_VERSION"
APP_EMAIL = "[email protected]"
APP_URL = "https://github.com/martinrotter/textilosaurus"
Expand Down

0 comments on commit 563ce40

Please sign in to comment.