新增存款计算器
parent
2fe2dc766e
commit
48e9858b2e
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -37,6 +37,7 @@ SUBDIRS += imageswitch #图片开关控件
|
|||
SUBDIRS += netserver #网络中转服务器
|
||||
SUBDIRS += base64helper #图片文字base64互换
|
||||
SUBDIRS += smoothcurve #平滑曲线
|
||||
SUBDIRS += moneytool #存款计算器
|
||||
|
||||
#限定windows系统加载下面的项目
|
||||
win32 {
|
||||
|
|
2964
QWidgetDemo.pro.user
2964
QWidgetDemo.pro.user
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
#### 一、目录说明
|
||||
#### 一、目录说明
|
||||
1. **可以选择打开QWidgetDemo.pro一次性编译所有的,也可以进入到目录下打开pro进行编译。**
|
||||
2. **如果发现有些子项目没有加载请打开QWidgetDemo.pro仔细看里面的注释。**
|
||||
3. **编译好的可执行文件在源码同级目录下的bin目录。**
|
||||
|
@ -6,7 +6,7 @@
|
|||
5. **本项目开源的是下面表格中描述的内容,并未开源左侧的树状导航菜单控件,只是方便演示效果图直接用的自定义控件大全的效果图,懒得重新截图。**
|
||||
|
||||
| 编号 | 文件夹 | 描述 |
|
||||
| ------ | ------ | ------ |
|
||||
| :------ | :------ | :------ |
|
||||
| 1 | lightbutton | 高亮按钮控件 |
|
||||
| 2 | movewidget | 通用控件移动类 |
|
||||
| 3 | flatui | 模仿flatui类 |
|
||||
|
@ -50,6 +50,7 @@
|
|||
| 41 | miniblink | miniblink示例 |
|
||||
| 42 | base64 | 图片文字base64互换 |
|
||||
| 43 | smoothcurve | 平滑曲线 |
|
||||
| 44 | moneytool | 存款计算器 |
|
||||
|
||||
#### 二、学习群
|
||||
1. **Qt交流大会群 853086607(雨田哥)**
|
||||
|
@ -102,3 +103,4 @@
|
|||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/base64.png)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/smoothcurve.gif)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/frameless.gif)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/moneytool.gif)
|
|
@ -0,0 +1,11 @@
|
|||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Widget w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
|
||||
|
||||
TARGET = mouseline
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
CONFIG += warn_off
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += widget.cpp
|
||||
HEADERS += widget.h
|
||||
FORMS += widget.ui
|
|
@ -0,0 +1,50 @@
|
|||
#pragma execution_character_set("utf-8")
|
||||
#include "widget.h"
|
||||
#include "ui_widget.h"
|
||||
#include "qmessagebox.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Widget::on_btnOk_clicked()
|
||||
{
|
||||
//当前多少钱
|
||||
int moneyCurrent = ui->txtMoneyCurrent->text().toInt();
|
||||
//利息
|
||||
float rate = ui->txtRate->text().toFloat();
|
||||
//定期期限
|
||||
int year = ui->cboxYear->currentText().left(1).toInt();
|
||||
//总年份 必须是定期期限的倍数
|
||||
int years = ui->txtYears->text().toInt();
|
||||
//最终多少钱
|
||||
int moneyAll = 0;
|
||||
|
||||
if (years % year != 0) {
|
||||
ui->txtYears->setFocus();
|
||||
QMessageBox::critical(this, "错误", "总年份必须是期限的整数倍数!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui->cboxType->currentIndex() == 0) {
|
||||
//傻瓜场景 直接计算
|
||||
moneyAll = moneyCurrent + (moneyCurrent * rate * years);
|
||||
} else {
|
||||
//真实场景 复利计算
|
||||
int count = years / year;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
moneyCurrent = moneyCurrent + (moneyCurrent * rate * year);
|
||||
}
|
||||
moneyAll = moneyCurrent;
|
||||
}
|
||||
|
||||
//计算下来3年期定期存款30年总金额翻2番到最初本金3倍 100W本金3年期自动续期30年=321W
|
||||
ui->txtMoneyAll->setText(QString::number(moneyAll));
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class Widget;
|
||||
}
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = 0);
|
||||
~Widget();
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
|
@ -0,0 +1,150 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>存款计算器</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>381</width>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="labYears">
|
||||
<property name="text">
|
||||
<string>年限</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labMoneyCurrent">
|
||||
<property name="text">
|
||||
<string>本金</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLineEdit" name="txtRate">
|
||||
<property name="text">
|
||||
<string>0.04125</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtMoneyCurrent">
|
||||
<property name="text">
|
||||
<string>1000000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="labRate">
|
||||
<property name="text">
|
||||
<string>利率</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labYear">
|
||||
<property name="text">
|
||||
<string>期限</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labType">
|
||||
<property name="text">
|
||||
<string>方式</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="cboxType">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>单利</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>复利</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cboxYear">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1年</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3年</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5年</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="txtYears">
|
||||
<property name="text">
|
||||
<string>30</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLineEdit" name="txtMoneyAll"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="labMoneyAll">
|
||||
<property name="text">
|
||||
<string>总计</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4" rowspan="3">
|
||||
<widget class="QPushButton" name="btnOk">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>计算</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -4,9 +4,7 @@
|
|||
#include "qevent.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
Widget::Widget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Widget)
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setMouseTracking(true);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
|
@ -10,11 +11,10 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Widget</string>
|
||||
<string>鼠标十字线</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -106,6 +106,12 @@ void SaveLog::save(const QString &content)
|
|||
if (toNet) {
|
||||
emit send(content);
|
||||
} else {
|
||||
//检查目录是否存在,不存在则先新建
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir(path);
|
||||
}
|
||||
|
||||
//方法改进:之前每次输出日志都打开文件,改成只有当日期改变时才新建和打开文件
|
||||
QString fileName = QString("%1/%2_log_%3.txt").arg(path).arg(name).arg(QDATE);
|
||||
if (this->fileName != fileName) {
|
||||
|
|
|
@ -44,10 +44,11 @@ private:
|
|||
//日志文件完整名称
|
||||
QString fileName;
|
||||
|
||||
signals:
|
||||
Q_SIGNALS:
|
||||
//发送内容信号
|
||||
void send(const QString &content);
|
||||
|
||||
public slots:
|
||||
public Q_SLOTS:
|
||||
//启动日志服务
|
||||
void start();
|
||||
//暂停日志服务
|
||||
|
@ -61,7 +62,6 @@ public slots:
|
|||
void setPath(const QString &path);
|
||||
//设置日志文件名称
|
||||
void setName(const QString &name);
|
||||
|
||||
};
|
||||
|
||||
class SendLog : public QObject
|
||||
|
@ -74,13 +74,17 @@ public:
|
|||
|
||||
private:
|
||||
static QScopedPointer<SendLog> self;
|
||||
|
||||
//网络通信对象
|
||||
QTcpSocket *socket;
|
||||
//网络监听服务器
|
||||
QTcpServer *server;
|
||||
|
||||
private slots:
|
||||
//新连接到来
|
||||
void newConnection();
|
||||
|
||||
public slots:
|
||||
public Q_SLOTS:
|
||||
//发送日志
|
||||
void send(const QString &content);
|
||||
};
|
||||
|
|
|
@ -42,23 +42,6 @@ SaveRunTime::SaveRunTime(QObject *parent) : QObject(parent)
|
|||
connect(timerSave, SIGNAL(timeout()), this, SLOT(saveLog()));
|
||||
}
|
||||
|
||||
void SaveRunTime::start()
|
||||
{
|
||||
//开始时间变量必须在这,在部分嵌入式系统上开机后的时间不准确比如是1970,而后会变成1999或者其他时间
|
||||
//会在getDiffValue函数执行很久很久
|
||||
startTime = QDateTime::currentDateTime();
|
||||
timerSave->start();
|
||||
|
||||
initLog();
|
||||
appendLog();
|
||||
saveLog();
|
||||
}
|
||||
|
||||
void SaveRunTime::stop()
|
||||
{
|
||||
timerSave->stop();
|
||||
}
|
||||
|
||||
void SaveRunTime::getDiffValue(const QDateTime &startTime, const QDateTime &endTime, int &day, int &hour, int &minute)
|
||||
{
|
||||
qint64 sec = startTime.secsTo(endTime);
|
||||
|
@ -86,6 +69,32 @@ void SaveRunTime::getDiffValue(const QDateTime &startTime, const QDateTime &endT
|
|||
}
|
||||
}
|
||||
|
||||
void SaveRunTime::start()
|
||||
{
|
||||
//开始时间变量必须在这,在部分嵌入式系统上开机后的时间不准确比如是1970,而后会变成1999或者其他时间
|
||||
//会在getDiffValue函数执行很久很久
|
||||
startTime = QDateTime::currentDateTime();
|
||||
timerSave->start();
|
||||
|
||||
initLog();
|
||||
appendLog();
|
||||
saveLog();
|
||||
}
|
||||
|
||||
void SaveRunTime::stop()
|
||||
{
|
||||
timerSave->stop();
|
||||
}
|
||||
|
||||
void SaveRunTime::newPath()
|
||||
{
|
||||
//检查目录是否存在,不存在则先新建
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir(path);
|
||||
}
|
||||
}
|
||||
|
||||
void SaveRunTime::initLog()
|
||||
{
|
||||
//判断当前年份的记事本文件是否存在,不存在则新建并且写入标题
|
||||
|
@ -93,6 +102,7 @@ void SaveRunTime::initLog()
|
|||
//幢号 开始时间 结束时间 已运行时间
|
||||
//1 2016-01-01 12:33:33 2016-02-05 12:12:12 day: 0 hour: 0 minute: 0
|
||||
|
||||
newPath();
|
||||
logFile = QString("%1/%2_runtime_%3.txt").arg(path).arg(name).arg(QDate::currentDate().year());
|
||||
QFile file(logFile);
|
||||
|
||||
|
@ -127,6 +137,7 @@ void SaveRunTime::initLog()
|
|||
|
||||
void SaveRunTime::appendLog()
|
||||
{
|
||||
newPath();
|
||||
logFile = QString("%1/%2_runtime_%3.txt").arg(path).arg(name).arg(QDate::currentDate().year());
|
||||
QFile file(logFile);
|
||||
|
||||
|
@ -150,6 +161,7 @@ void SaveRunTime::appendLog()
|
|||
void SaveRunTime::saveLog()
|
||||
{
|
||||
//每次保存都是将之前的所有文本读取出来,然后替换最后一行即可
|
||||
newPath();
|
||||
logFile = QString("%1/%2_runtime_%3.txt").arg(path).arg(name).arg(QDate::currentDate().year());
|
||||
QFile file(logFile);
|
||||
|
||||
|
@ -199,17 +211,13 @@ void SaveRunTime::saveLog()
|
|||
|
||||
void SaveRunTime::setPath(const QString &path)
|
||||
{
|
||||
if (this->path != path) {
|
||||
this->path = path;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveRunTime::setName(const QString &name)
|
||||
{
|
||||
if (this->name != name) {
|
||||
this->name = name;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveRunTime::setSaveInterval(int saveInterval)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
|
||||
class QTimer;
|
||||
|
||||
#ifdef quc
|
||||
|
@ -28,29 +29,47 @@ public:
|
|||
|
||||
private:
|
||||
static QScopedPointer<SaveRunTime> self;
|
||||
QString path; //日志文件路径
|
||||
QString name; //日志文件名称
|
||||
|
||||
//日志文件路径
|
||||
QString path;
|
||||
//日志文件名称
|
||||
QString name;
|
||||
|
||||
//最后的编号
|
||||
int lastID;
|
||||
//保存间隔
|
||||
int saveInterval;
|
||||
//开始时间
|
||||
QDateTime startTime;
|
||||
//日志文件
|
||||
QString logFile;
|
||||
//保存文件定时器
|
||||
QTimer *timerSave;
|
||||
|
||||
private:
|
||||
//比较两个时间差值
|
||||
void getDiffValue(const QDateTime &startTime, const QDateTime &endTime, int &day, int &hour, int &minute);
|
||||
|
||||
signals:
|
||||
public Q_SLOTS:
|
||||
//启动服务
|
||||
void start();
|
||||
//停止服务
|
||||
void stop();
|
||||
|
||||
public slots:
|
||||
void start(); //启动服务
|
||||
void stop(); //停止服务
|
||||
void initLog(); //初始化日志文件
|
||||
void appendLog(); //追加一条记录到日志文件
|
||||
void saveLog(); //保存运行时间到日志文件
|
||||
//新建目录
|
||||
void newPath();
|
||||
//初始化日志文件
|
||||
void initLog();
|
||||
//追加一条记录到日志文件
|
||||
void appendLog();
|
||||
//保存运行时间到日志文件
|
||||
void saveLog();
|
||||
|
||||
//设置文件保存目录
|
||||
void setPath(const QString &path);
|
||||
//设置文件名称
|
||||
void setName(const QString &name);
|
||||
//设置保存间隔
|
||||
void setSaveInterval(int saveInterval);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue