Skip to content

Commit

Permalink
Add enable in CTasks and CTask
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Feb 12, 2025
1 parent ccd42f8 commit e361e9a
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 50 deletions.
2 changes: 1 addition & 1 deletion App/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
ui->menuTools->insertMenu(ui->actionExit_E,
RabbitCommon::CTools::Instance()->GetLogMenu(this));
ui->menuTools->insertSeparator(ui->actionExit_E);

m_TrayIconMenu.addAction(
QIcon::fromTheme("window-close"),
tr("Exit"),
Expand Down
6 changes: 3 additions & 3 deletions App/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ int main(int argc, char *argv[])
return 0;
}

CMainWindow m;
CMainWindow win;
#if defined(Q_OS_ANDROID)
m.showMaximized();
win.showMaximized();
#else
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
bool bShow = set.value("Options/MainWindow/Show", false).toBool();
if(bShow)
m.show();
win.show();
#endif

int nRet = a.exec();
Expand Down
4 changes: 4 additions & 0 deletions Src/FrmTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int CFrmTasks::SetTasks(QSharedPointer<CTasks> tasks)
}
ui->leTasksTitle->setText(m_Tasks->GetTitle());
ui->leTasksID->setText(QString::number(m_Tasks->GetId()));
ui->cbTasksEnable->setChecked(m_Tasks->GetEnable());
ui->teTasksContent->setText(m_Tasks->GetContent());

SetSlider(0); //m_Tasks->GetCurrentIndex());
Expand All @@ -85,6 +86,7 @@ int CFrmTasks::SetTask(QSharedPointer<CTask> task)
}
//ui->gpTask->setTitle(tr("Task: ") + task->objectName());
ui->leTaskID->setText(QString::number(task->GetId()));
ui->cbTaskEnable->setChecked(task->GetEnable());
ui->leTaskTitle->setText(task->GetTitle());
ui->teTaskContent->setText(task->GetContent());
ui->spInterval->setValue(task->GetInterval() / 60000);
Expand Down Expand Up @@ -203,8 +205,10 @@ void CFrmTasks::on_pbApply_clicked()
if(!task)
return;
m_Tasks->SetTitle(ui->leTasksTitle->text());
m_Tasks->SetEnable(ui->cbTasksEnable->isChecked());
m_Tasks->SetContent(ui->teTasksContent->toPlainText());

task->SetEnable(ui->cbTaskEnable->isChecked());
task->SetTitle(ui->leTaskTitle->text());
task->SetContent(ui->teTaskContent->toPlainText());
task->SetInterval(ui->spInterval->value() * 60 * 1000);
Expand Down
58 changes: 31 additions & 27 deletions Src/FrmTasks.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<string>Tasks</string>
</property>
<property name="windowIcon">
<iconset theme="task">
</iconset>
<iconset theme="task"/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
Expand All @@ -33,7 +32,7 @@
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="invertedAppearance">
<bool>true</bool>
Expand All @@ -42,7 +41,7 @@
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
<enum>QSlider::TickPosition::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>0</number>
Expand Down Expand Up @@ -108,8 +107,7 @@
<string/>
</property>
<property name="icon">
<iconset theme="task">
</iconset>
<iconset theme="task"/>
</property>
<property name="autoDefault">
<bool>false</bool>
Expand All @@ -122,6 +120,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbTasksEnable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -155,7 +160,7 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -180,7 +185,7 @@
<string>Previous</string>
</property>
<property name="icon">
<iconset theme="up"></iconset>
<iconset theme="up"/>
</property>
</widget>
</item>
Expand All @@ -199,14 +204,14 @@
<string>Next</string>
</property>
<property name="icon">
<iconset theme="down"></iconset>
<iconset theme="down"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -287,8 +292,14 @@
<string/>
</property>
<property name="icon">
<iconset theme="task">
</iconset>
<iconset theme="task"/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbTaskEnable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -325,7 +336,7 @@
<string>Task interval(Unit: minute). If is 0, then run now.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
<property name="maximum">
<number>1440</number>
Expand Down Expand Up @@ -367,7 +378,7 @@
<string>Prompt interval(Unit: second). If is 0, don't prompt</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
<property name="maximum">
<number>86400</number>
Expand Down Expand Up @@ -439,8 +450,7 @@
<string>Add</string>
</property>
<property name="icon">
<iconset theme="add">
</iconset>
<iconset theme="add"/>
</property>
</widget>
</item>
Expand All @@ -459,8 +469,7 @@
<string>Remove</string>
</property>
<property name="icon">
<iconset theme="subtract">
</iconset>
<iconset theme="subtract"/>
</property>
</widget>
</item>
Expand All @@ -476,15 +485,14 @@
<string>Save</string>
</property>
<property name="icon">
<iconset theme="document-save">
</iconset>
<iconset theme="document-save"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -506,8 +514,7 @@
<string>Close</string>
</property>
<property name="icon">
<iconset theme="window-close">
</iconset>
<iconset theme="window-close"/>
</property>
</widget>
</item>
Expand All @@ -517,9 +524,6 @@
</item>
</layout>
</widget>
<resources>
<include location="Resource/ResourceTasks.qrc"/>
<include location="Resource/ResourceTasks.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
3 changes: 3 additions & 0 deletions Src/FrmTasksList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void CFrmTasksList::slotRefresh()
if(!pItem) return;
pItem->setToolTip(p->GetContent());
pItem->setData(p->GetId());
pItem->setCheckable(true);
if(p->GetEnable())
pItem->setCheckState(Qt::Checked);
m_Model.appendRow(pItem);
}
m_lvTasks.setCurrentIndex(m_Model.index(0, 0));
Expand Down
12 changes: 12 additions & 0 deletions Src/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CTask::CTask(int nInterval, int nPromptInterval, QObject *parent)
int CTask::Init()
{
SetId(-1);
SetEnable(true);
setObjectName("Task");
SetTitle(objectName());
SetContent(GetTitle());
Expand Down Expand Up @@ -145,6 +146,17 @@ int CTask::SetId(int id)
return m_nId;
}

bool CTask::GetEnable() const
{
return m_bEnable;
}

int CTask::SetEnable(bool bEnable)
{
m_bEnable = bEnable;
return 0;
}

QString CTask::GetDescription() const
{
return tr("Task is base unit. Is a minimal execution unit.\n"
Expand Down
4 changes: 4 additions & 0 deletions Src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CTask : public QObject
Q_PROPERTY(QString title READ GetTitle WRITE SetTitle)
Q_PROPERTY(QString content READ GetContent WRITE SetContent)
Q_PROPERTY(int id READ GetId WRITE SetId)
Q_PROPERTY(bool enable READ GetEnable WRITE SetEnable)
Q_PROPERTY(int interval READ GetInterval WRITE SetInterval)
Q_PROPERTY(int promptInterval READ GetPromptInterval WRITE SetPromptInterval)
Q_PROPERTY(bool end READ End)
Expand All @@ -42,6 +43,8 @@ class CTask : public QObject

Q_INVOKABLE virtual int GetId() const;
Q_INVOKABLE virtual int SetId(int id);
Q_INVOKABLE virtual bool GetEnable() const;
Q_INVOKABLE virtual int SetEnable(bool bEnable);
Q_INVOKABLE virtual QString GetDescription() const;
Q_INVOKABLE virtual int SetTitle(QString szTitle);
Q_INVOKABLE virtual QString GetTitle() const;
Expand Down Expand Up @@ -105,6 +108,7 @@ protected Q_SLOTS:

private:
int m_nId;
bool m_bEnable;
QString m_szTitle;
QString m_szContent;
QIcon m_Icon;
Expand Down
15 changes: 15 additions & 0 deletions Src/Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CTasks::CTasks(QObject *parent) : QObject(parent)
m_CurrentPostion = 0;
m_nIdTask = 0;
m_nId = -1;
m_bEnable = true;
setObjectName("Tasks");
SetTitle(objectName());
}
Expand Down Expand Up @@ -157,6 +158,17 @@ int CTasks::SetId(int id)
return m_nId;
}

bool CTasks::GetEnable() const
{
return m_bEnable;
}

int CTasks::SetEnable(bool bEnable)
{
m_bEnable = bEnable;
return 0;
}

QString CTasks::GetTitle()
{
return m_szTitle;
Expand Down Expand Up @@ -212,6 +224,9 @@ int CTasks::Check()
qWarning() << "CTasks::Check(): task pointer is null";
return 0;
}

if(!task->GetEnable())
return 0;

nRet = task->Check();
if(nRet)
Expand Down
4 changes: 4 additions & 0 deletions Src/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CTasks : public QObject
{
Q_OBJECT
Q_PROPERTY(int id READ GetId WRITE SetId)
Q_PROPERTY(bool enable READ GetEnable WRITE SetEnable)
Q_PROPERTY(QString title READ GetTitle WRITE SetTitle)
Q_PROPERTY(QString content READ GetContent WRITE SetContent)
Q_PROPERTY(bool end READ End)
Expand All @@ -31,6 +32,8 @@ class CTasks : public QObject

Q_INVOKABLE int GetId();
Q_INVOKABLE int SetId(int id);
Q_INVOKABLE virtual bool GetEnable() const;
Q_INVOKABLE virtual int SetEnable(bool bEnable);
Q_INVOKABLE int SetTitle(const QString &szTitle);
Q_INVOKABLE QString GetTitle();
Q_INVOKABLE int SetContent(const QString &szContent);
Expand Down Expand Up @@ -78,6 +81,7 @@ class CTasks : public QObject
QVector<QSharedPointer<CTask> > m_Task;
int m_nIdTask;
int m_nId;
bool m_bEnable;
QString m_szTitle;
QString m_szContent;
QIcon m_Icon;
Expand Down
2 changes: 2 additions & 0 deletions Src/TasksList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ int CTasksList::Check()
int nRet = 0;
foreach (QSharedPointer<CTasks> task, m_Tasks)
{
if(!task->GetEnable())
continue;
nRet = task->Check();
if(0 == nRet)
{
Expand Down
Loading

0 comments on commit e361e9a

Please sign in to comment.