Skip to content
This repository has been archived by the owner on Sep 24, 2023. It is now read-only.

Commit

Permalink
Add config option for number of task selector entries
Browse files Browse the repository at this point in the history
Allows to have a longer or shorter list of quick task selection
entries in the main window's toolbar button menu and the tray icon
context menu.

Change-Id: I5d7767af59b391dabf69329f3ec3b1c1f5929df7
Reviewed-on: https://codereview.kdab.com/56895
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Frank Osterfeld <frank.osterfeld@kdab.com>
  • Loading branch information
krake-kdab committed Apr 16, 2018
1 parent 0685060 commit e5c080a
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Charm/Widgets/CharmPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ CharmPreferences::CharmPreferences(const Configuration &config, QWidget *parent_
m_ui.cbToolButtonStyle->setCurrentIndex(4);
break;
}

m_ui.sbNumberOfTaskSelectorEntries->setValue(config.numberOfTaskSelectorEntries);

// resize( minimumSize() );
}

Expand Down Expand Up @@ -125,6 +128,11 @@ bool CharmPreferences::enableCommandInterface() const
return m_ui.cbEnableCommandInterface->isChecked();
}

int CharmPreferences::numberOfTaskSelectorEntries() const
{
return m_ui.sbNumberOfTaskSelectorEntries->value();
}

Configuration::DurationFormat CharmPreferences::durationFormat() const
{
switch (m_ui.cbDurationFormat->currentIndex()) {
Expand Down
1 change: 1 addition & 0 deletions Charm/Widgets/CharmPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CharmPreferences : public QDialog
bool warnUnuploadedTimesheets() const;
bool requestEventComment() const;
bool enableCommandInterface() const;
int numberOfTaskSelectorEntries() const;

Qt::ToolButtonStyle toolButtonStyle() const;

Expand Down
27 changes: 25 additions & 2 deletions Charm/Widgets/CharmPreferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>302</height>
<width>505</width>
<height>311</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -236,6 +236,29 @@
</property>
</widget>
</item>
<item row="7" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="lbNumberOfTaskSelectorEntries">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Limit recently used tasks to</string>
</property>
<property name="buddy">
<cstring>sbNumberOfTaskSelectorEntries</cstring>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QSpinBox" name="sbNumberOfTaskSelectorEntries">
<property name="value">
<number>5</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
5 changes: 4 additions & 1 deletion Charm/Widgets/TimeTrackingTaskSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "SelectTaskDialog.h"
#include "ViewHelpers.h"

#include "Core/Configuration.h"
#include "Core/Event.h"
#include "Core/Task.h"

Expand Down Expand Up @@ -139,7 +140,9 @@ void TimeTrackingTaskSelector::populate(const QVector<WeeklySummary> &summaries)

const TaskIdList interestingTasksToAdd = DATAMODEL->mostRecentlyUsedTasks();

for (int i = 0; i < 5 && i < interestingTasksToAdd.size(); ++i)
const int maxEntries = qMin(interestingTasksToAdd.size(),
CONFIGURATION.numberOfTaskSelectorEntries);
for (int i = 0; i < maxEntries; ++i)
m_menu->addAction(createTaskAction(interestingTasksToAdd.at(i)));
m_menu->addSeparator();
m_menu->addAction(m_startOtherTaskAction);
Expand Down
4 changes: 4 additions & 0 deletions Charm/Widgets/TimeTrackingView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ void TimeTrackingView::configurationChanged()
break;
}

// re-populate menu:
m_taskSelector->populate(m_summaries);
emit taskMenuChanged();

m_narrowFont = font(); // stay with the desktop
m_narrowFont.setPointSize(m_fixedFont.pointSize());

Expand Down
1 change: 1 addition & 0 deletions Charm/Widgets/TimeTrackingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void TimeTrackingWindow::slotEditPreferences(bool)
CONFIGURATION.warnUnuploadedTimesheets = dialog.warnUnuploadedTimesheets();
CONFIGURATION.requestEventComment = dialog.requestEventComment();
CONFIGURATION.enableCommandInterface = dialog.enableCommandInterface();
CONFIGURATION.numberOfTaskSelectorEntries = dialog.numberOfTaskSelectorEntries();
emit saveConfiguration();
}
}
Expand Down
1 change: 1 addition & 0 deletions Core/CharmConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const QString MetaKey_Key_RequestEventComment = QStringLiteral("RequestEventComm
const QString MetaKey_Key_ToolButtonStyle = QStringLiteral("ToolButtonStyle");
const QString MetaKey_Key_ShowStatusBar = QStringLiteral("ShowStatusBar");
const QString MetaKey_Key_EnableCommandInterface = QStringLiteral("EnableCommandInterface");
const QString MetaKey_Key_NumberOfTaskSelectorEntries = QStringLiteral("NumberOfTaskSelectorEntries");

const QString TrueString(QStringLiteral("true"));
const QString FalseString(QStringLiteral("false"));
Expand Down
1 change: 1 addition & 0 deletions Core/CharmConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern const QString MetaKey_Key_RequestEventComment;
extern const QString MetaKey_Key_ToolButtonStyle;
extern const QString MetaKey_Key_ShowStatusBar;
extern const QString MetaKey_Key_EnableCommandInterface;
extern const QString MetaKey_Key_NumberOfTaskSelectorEntries;

extern const QString TrueString;
extern const QString FalseString;
Expand Down
9 changes: 6 additions & 3 deletions Core/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Configuration::Configuration(TaskPrefilteringMode _taskPrefilteringMode,
DurationFormat _durationFormat, bool _detectIdling,
Qt::ToolButtonStyle _buttonstyle, bool _showStatusBar,
bool _warnUnuploadedTimesheets, bool _requestEventComment,
bool _enableCommandInterface)
bool _enableCommandInterface, int _numberOfTaskSelectorEntries)
: taskPrefilteringMode(_taskPrefilteringMode)
, timeTrackerFontSize(_timeTrackerFontSize)
, durationFormat(_durationFormat)
Expand All @@ -61,6 +61,7 @@ Configuration::Configuration(TaskPrefilteringMode _taskPrefilteringMode,
, warnUnuploadedTimesheets(_warnUnuploadedTimesheets)
, requestEventComment(_requestEventComment)
, enableCommandInterface(_enableCommandInterface)
, numberOfTaskSelectorEntries(_numberOfTaskSelectorEntries)
, configurationName(DEFAULT_CONFIG_GROUP)
{
}
Expand All @@ -79,7 +80,8 @@ bool Configuration::operator==(const Configuration &other) const
&& configurationName == other.configurationName
&& installationId == other.installationId
&& localStorageType == other.localStorageType
&& localStorageDatabase == other.localStorageDatabase;
&& localStorageDatabase == other.localStorageDatabase
&& numberOfTaskSelectorEntries == other.numberOfTaskSelectorEntries;
}

void Configuration::writeTo(QSettings &settings)
Expand Down Expand Up @@ -148,7 +150,8 @@ void Configuration::dump(const QString &why)
<< "--> showStatusBar: " << showStatusBar << endl
<< "--> warnUnuploadedTimesheets: " << warnUnuploadedTimesheets << endl
<< "--> requestEventComment: " << requestEventComment << endl
<< "--> enableCommandInterface: " << enableCommandInterface;
<< "--> enableCommandInterface: " << enableCommandInterface
<< "--> numberOfTaskSelectorEntries: " << numberOfTaskSelectorEntries;
}

quint32 Configuration::createInstallationId() const
Expand Down
3 changes: 2 additions & 1 deletion Core/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Configuration
bool warnUnuploadedTimesheets = true;
bool requestEventComment = false;
bool enableCommandInterface = false;
int numberOfTaskSelectorEntries = 5;

// these are stored in QSettings, since we need this information to locate and open the database:
QString configurationName;
Expand All @@ -102,7 +103,7 @@ class Configuration
Configuration(TaskPrefilteringMode taskPrefilteringMode, TimeTrackerFontSize,
DurationFormat durationFormat, bool detectIdling, Qt::ToolButtonStyle buttonstyle,
bool showStatusBar, bool warnUnuploadedTimesheets, bool _requestEventComment,
bool enableCommandInterface);
bool enableCommandInterface, int _numberOfTaskSelectorEntries);
Configuration();
};

Expand Down
6 changes: 5 additions & 1 deletion Core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ void Controller::persistMetaData(Configuration &configuration)
{ MetaKey_Key_ShowStatusBar,
stringForBool(configuration.showStatusBar) },
{ MetaKey_Key_EnableCommandInterface,
stringForBool(configuration.enableCommandInterface) }
stringForBool(configuration.enableCommandInterface) },
{ MetaKey_Key_NumberOfTaskSelectorEntries,
QString::number(configuration.numberOfTaskSelectorEntries) }
};
int NumberOfSettings = sizeof settings / sizeof settings[0];

Expand Down Expand Up @@ -270,6 +272,8 @@ void Controller::provideMetaData(Configuration &configuration)
loadConfigValue(MetaKey_Key_ToolButtonStyle, configuration.toolButtonStyle);
loadConfigValue(MetaKey_Key_ShowStatusBar, configuration.showStatusBar);
loadConfigValue(MetaKey_Key_EnableCommandInterface, configuration.enableCommandInterface);
loadConfigValue(MetaKey_Key_NumberOfTaskSelectorEntries, configuration.numberOfTaskSelectorEntries);
configuration.numberOfTaskSelectorEntries = qMax(0, configuration.numberOfTaskSelectorEntries);

CONFIGURATION.dump();
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/ControllerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ void ControllerTests:: persistProvideMetaDataTest()
Configuration configs[] = {
Configuration(Configuration::TaskPrefilter_ShowAll, Configuration::TimeTrackerFont_Small,
Configuration::Minutes, true, Qt::ToolButtonIconOnly, true, true, true,
false),
false, 5),
Configuration(Configuration::TaskPrefilter_CurrentOnly,
Configuration::TimeTrackerFont_Regular,
Configuration::Minutes, false, Qt::ToolButtonTextOnly, false, false, false,
false),
false, 5),
Configuration(Configuration::TaskPrefilter_SubscribedAndCurrentOnly,
Configuration::TimeTrackerFont_Large,
Configuration::Minutes, true, Qt::ToolButtonTextBesideIcon, true, true, true,
false),
false, 5),
};
const int NumberOfConfigurations = sizeof configs / sizeof configs[0];

Expand Down

0 comments on commit e5c080a

Please sign in to comment.