QT学习篇:入门(1)
第一个为管理界面:
(1)安全库存的设置,包括序号、物品代码、物品类型、最大库存量、最小库存量、最大库存比率、最小库存比率;
(2)计算频率设置,包括:实时,定时(单位分为:分钟、小时、天),来自globalPara表,该表增加字段;
(3)库存订单确认方式,包括:自动,人工,来自globalPara表,该表增加字段;
(4)通知设置,包括:手机号码,邮箱,来自globalPara表,该表增加字段。手机和邮箱可以设置多个。
#ifndef _REPERTORY_H
#define _REPERTORY_H
#include "ui_CStockManagerSet.h"
#include "QtGui/QDialog"
#include "QtGui/QStandardItemModel"
#include <QComboBox>
#include <QTableView>
#include <QGroupBox>
#include <QPushButton>
#include <QRadioButton>
#include <QLineEdit>
#include <QLabel>
typedef struct CStockMode
{
int index; //ID
QString strRes; //代码
int iResType; //类型
double iMaxStock; //最大库存量(新增安全库存)
double iMinStock; //最小库存量(新增安全库存)
double iMaxStockPercent; //最大库存比率,单位:% (新增安全库存)
double iMinStockPercent; //最小库存比率
}CStockMode_t;
typedef struct ItemMode
{
int iCalculatedRateType; //计算频率类型,1-实时,2-定时
int iCalculatedRateUnit; //计算频率定时单位,1-分钟,2-小时,3-天
int iCalculatedRateTime; //计算频率定时时间
bool bStockOrderConfirmation; //库存订单确认方式, true-自动, false-人工
QList<QString> strMessagePhone; //手机通知方式
QList<QString> strMessageEmail; //邮箱通知方式
}ItemMode_t;
class CStockManagerSet : public QDialog
{
Q_OBJECT
public:
CStockManagerSet(QWidget *parent = 0, Qt::WFlags flags = 0);
~CStockManagerSet();
private:
void initLayout();
void setData(const QMap<int, CStockMode_t>& mapMode,const ItemMode_t& item);
/*void setData(const QMap<int, CStockMode_t>& mapMode);*/
void setDelegate();
void setItemData();
public:
QPair<QMap<int, CStockMode_t>, ItemMode_t> getdata();
private:
Ui::Repertory_Dialog ui;
QStandardItemModel* Repertory_Model;
QMap<int, CStockMode_t> m_mapMode;
QTableView* m_pStockTableView;
ItemMode_t m_itemMode;
bool m_bFlag; //判断是否单元格数据被修改,第一次加载的数据不算修改
private slots:
void OnRealTimeClicked();
void OnSetTimeClicked();
void OnItemChanged(QStandardItem* item);
void OnTimeReturned();
void OnAutomaticClicked();
void OnArtificialClicked();
void OnPhoneNumberReturned();
void OnEmailReturned();
void OnOk();
void OnCancel();
void OnComboBoxReturned(const QString& strText);
};
#endif
源文件
#include "CStockManagerSet.h"
#include "QtGui/QGridLayout"
#include <QModelIndex>
const int RepertoryColumnCount = 7;
CStockManagerSet::CStockManagerSet(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags),
m_bFlag(false)
{
ui.setupUi(this);
m_pStockTableView = ui.StockTableView;
setWindowTitle(tr("安全库存管理界面"));
setFixedSize(700,600);
initLayout();
setData(m_mapMode, m_itemMode);
}
CStockManagerSet::~CStockManagerSet()
{
}
void CStockManagerSet::initLayout()
{
ui.SetSafestock->setTitle(tr("安全库存"));
ui.CalFrequency->setTitle(tr("计算步骤"));
ui.StockConfirm->setTitle(tr("库存订单确认"));
ui.SetNotification->setTitle(tr("通知设置"));
ui.RealTime->setText(tr("实时"));
ui.SetTime->setText(tr("定时"));
ui.Automatic->setText(tr("自动"));
ui.Artificial->setText(tr("人工手动确认"));
ui.ComboBox->insertItem(1,tr("天数"));
ui.ComboBox->insertItem(2,tr("小时"));
ui.ComboBox->insertItem(3,tr("分钟"));
ui.PhoneNumberButton->setText(tr("手机号"));
ui.EmailButton->setText(tr("邮箱"));
ui.OkButton->setText(tr("确定"));
ui.CancelButton->setText(tr("取消"));
ui.FrequencyDisplay->setText(tr("定时数量"));
ui.SetType->setText(tr("定时类型"));
ui.PhoneNumberEdit->setPlaceholderText(tr("多个输入时以;分隔"));
ui.EmailEdit->setPlaceholderText(tr("多个输入时以;分隔"));
connect(ui.RealTime, SIGNAL(clicked()), this, SLOT(OnRealTimeClicked()));
connect(ui.SetTime, SIGNAL(clicked()), this, SLOT(OnSetTimeClicked()));
connect(ui.TimeEdit, SIGNAL(editingFinished()), this, SLOT(OnTimeReturned()));
connect(ui.Automatic, SIGNAL(clicked()), this, SLOT(OnAutomaticClicked()));
connect(ui.Artificial, SIGNAL(clicked()), this, SLOT(OnArtificialClicked()));
connect(ui.PhoneNumberEdit, SIGNAL(editingFinished()), this, SLOT(OnPhoneNumberReturned()));
connect(ui.EmailEdit, SIGNAL(editingFinished()), this, SLOT(OnEmailReturned()));
connect(ui.ComboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(OnComboBoxReturned(const QString&)));
connect(ui.OkButton, SIGNAL(clicked()), this, SLOT(OnOk()));
connect(ui.CancelButton, SIGNAL(clicked()), this, SLOT(OnCancel()));
QString strProperty[RepertoryColumnCount] =
{
tr("序号"), tr("物品代码"),tr("物品类型"), tr("最大库存量"), tr("最小库存量"),
tr("最大库存比率"), tr("最小库存比率")
};
Repertory_Model = new QStandardItemModel(this);
Repertory_Model->setColumnCount(RepertoryColumnCount);
for (int i = 0; i < RepertoryColumnCount; i++)
{
Repertory_Model->setHeaderData(i, Qt::Horizontal, strProperty[i]);
}
connect(Repertory_Model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(OnItemChanged(QStandardItem*)));
m_pStockTableView->setModel(Repertory_Model);
m_pStockTableView->setSortingEnabled(true);
m_pStockTableView->resizeColumnsToContents();
m_pStockTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed);
m_pStockTableView->setAlternatingRowColors(true);
m_pStockTableView->verticalHeader()->setDefaultSectionSize(25);
}
//void CStockManagerSet::setData(const QMap<int, CStockMode_t>& mapMode)
//{
// m_mapMode = mapMode;
// CStockMode_t item;
// item.index = 1;
// item.strRes = "APS01";
// item.iResType = 0;
// item.iMaxStock = 1000;
// item.iMinStock = 100;
// item.iMaxStockPercent = 87.8;
// item.iMinStockPercent = 54.3;
// m_mapMode.insert(1, item);
//
// CStockMode_t item1;
// item1.index = 2;
// item1.strRes = "APS03";
// item1.iResType = 1;
// item1.iMaxStock = 999;
// item1.iMinStock = 90;
// item1.iMaxStockPercent = 88.8;
// item1.iMinStockPercent = 33.3;
// m_mapMode.insert(2, item1);
//
// CStockMode_t item2;
// item1.index = 3;
// item1.strRes = "APS03";
// item1.iResType = 0;
// item1.iMaxStock = 198;
// item1.iMinStock = 67;
// item1.iMaxStockPercent = 79.9;
// item1.iMinStockPercent = 55.8;
//
// m_mapMode.insert(3, item1);
//
// setDelegate();
// setItemData();
//
//}
void CStockManagerSet::setData(const QMap<int, CStockMode_t>& mapMode,const ItemMode_t& item)
{
m_mapMode = mapMode;
m_itemMode = item;
setDelegate();
setItemData();
}
QPair<QMap<int, CStockMode_t>, ItemMode_t> CStockManagerSet::getdata()
{
return qMakePair(m_mapMode, m_itemMode);
}
void CStockManagerSet::setDelegate()
{
}
void CStockManagerSet::setItemData()
{
m_bFlag = false;
//清空表
Repertory_Model->removeRows(0, Repertory_Model->rowCount());
//重新插入
int iRow = 0;
QMap<int, CStockMode_t>::const_iterator it;
for (it = m_mapMode.begin(); it != m_mapMode.end(); ++it)
{
Repertory_Model->insertRows(iRow, 1, QModelIndex());
Repertory_Model->setData(Repertory_Model->index(iRow, 0), it->index);
Repertory_Model->setData(Repertory_Model->index(iRow, 1), it->strRes);
Repertory_Model->setData(Repertory_Model->index(iRow, 2), it->iResType);
Repertory_Model->setData(Repertory_Model->index(iRow, 3), it->iMaxStock);
Repertory_Model->setData(Repertory_Model->index(iRow, 4), it->iMinStock);
Repertory_Model->setData(Repertory_Model->index(iRow, 5), it->iMaxStockPercent);
Repertory_Model->setData(Repertory_Model->index(iRow, 6), it->iMinStockPercent);
iRow++;
}
m_bFlag = true;
}
void CStockManagerSet::OnRealTimeClicked()
{
if (ui.RealTime->isChecked())
{
m_itemMode.iCalculatedRateType = 1;
}
ui.TimeEdit->setEnabled(false);
ui.ComboBox->setEnabled(false);
}
void CStockManagerSet::OnSetTimeClicked()
{
if (ui.SetTime->isChecked())
{
m_itemMode.iCalculatedRateType = 2;
}
ui.TimeEdit->setEnabled(true);
ui.ComboBox->setEnabled(true);
}
void CStockManagerSet::OnTimeReturned()
{
int iTime = ui.TimeEdit->text().toInt();
m_itemMode.iCalculatedRateTime = iTime;
}
void CStockManagerSet::OnPhoneNumberReturned()
{ //电话添加
QString iPhoneNumber = ui.PhoneNumberEdit->text();
QStringList lstPhoneNumber = iPhoneNumber.split(tr(";"));
QList<QString>::const_iterator it;
for (it = lstPhoneNumber.begin(); it != lstPhoneNumber.end(); ++it)
{
m_itemMode.strMessagePhone.append(*it);
}
}
void CStockManagerSet::OnEmailReturned()
{ //邮箱添加
QString iEmail = ui.EmailEdit->text();
QStringList lstEmail = iEmail.split(tr(";"));
QList<QString>::const_iterator it;
for (it = lstEmail.begin(); it != lstEmail.end(); ++it)
{
m_itemMode.strMessageEmail.append(*it);
}
}
void CStockManagerSet::OnAutomaticClicked()
{
if (ui.Automatic->isChecked())
{
m_itemMode.bStockOrderConfirmation = true;
}
ui.Artificial->setEnabled(false);
}
void CStockManagerSet::OnArtificialClicked()
{
if (ui.Artificial->isChecked())
{
m_itemMode.bStockOrderConfirmation = false;
}
ui.Automatic->setEnabled(false);
}
void CStockManagerSet::OnComboBoxReturned(const QString& strText)
{
//ui.ComboBox->text();
if (strText == tr("分钟"))
{
m_itemMode.iCalculatedRateUnit = 1;
}
else if (strText == tr("小时"))
{
m_itemMode.iCalculatedRateUnit = 2;
}
else if (strText == tr("天数"))
{
m_itemMode.iCalculatedRateUnit = 3;
}
}
void CStockManagerSet::OnItemChanged(QStandardItem *item)
{
if(item == NULL || !m_bFlag)
{
return;
}
int iRow = item->index().row();
int iColumn = item->index().column();
int iID = Repertory_Model->data(Repertory_Model->index(iRow, 0)).toInt();
switch(iColumn)
{
case 0:
{
m_mapMode[iID].index = Repertory_Model->data(Repertory_Model->index(iRow, 0)).toInt();
break;
}
case 1:
{
m_mapMode[iID].strRes = Repertory_Model->data(Repertory_Model->index(iRow, 1)).toString();
break;
}
case 2:
{
m_mapMode[iID].iResType = Repertory_Model->data(Repertory_Model->index(iRow, 2)).toInt();
break;
}
case 3:
{
m_mapMode[iID].iMaxStock = Repertory_Model->data(Repertory_Model->index(iRow, 3)).toInt();
break;
}
case 4:
{
m_mapMode[iID].iMinStock = Repertory_Model->data(Repertory_Model->index(iRow, 4)).toDouble();
break;
}
case 5:
{
m_mapMode[iID].iMaxStockPercent = Repertory_Model->data(Repertory_Model->index(iRow, 5)).toDouble();
break;
}
case 6:
{
m_mapMode[iID].iMinStockPercent = Repertory_Model->data(Repertory_Model->index(iRow, 6)).toDouble();
break;
}
default:
break;
}
}
void CStockManagerSet::OnOk()
{
this->accept();
}
void CStockManagerSet::OnCancel()
{
this->reject();
}
效果图
QT学习篇:入门(1)的更多相关文章
- QT学习:入门篇(三)
头文件: #ifndef CChatDisplaySet_h #define CChatDisplaySet_h #include "QtGui/QDialog" #include ...
- QT学习篇: 入门(二)
库存订单界面: (1)包括序号.订单代码.订单名称.产品代码.产品类型.计划加工数量.最晚完工日期. (2)model增加临时map,用于存储库存订单. (3)后台计算完成后,会将库存订单推送给前台, ...
- [Qt总结篇]终端远程升级client
环境: QT4.8.5 for Windows(Qt Creator+MinGW) 一.写在前面: 1.深度:鉴于C/C++的功底还远远不足,个人主要精力还是学习C/C++,所以没打算继续深入研究Qt ...
- PHP学习笔记 - 入门篇(5)
PHP学习笔记 - 入门篇(5) 语言结构语句 顺序结构 eg: <?php $shoesPrice = 49; //鞋子单价 $shoesNum = 1; //鞋子数量 $shoesMoney ...
- PHP学习笔记 - 入门篇(4)
PHP学习笔记 - 入门篇(4) 什么是运算符 PHP运算符一般分为算术运算符.赋值运算符.比较运算符.三元运算符.逻辑运算符.字符串连接运算符.错误控制运算符. PHP中的算术运算符 算术运算符主要 ...
- PHP学习笔记 - 入门篇(3)
PHP学习笔记 - 入门篇(3) 常量 什么是常量 什么是常量?常量可以理解为值不变的量(如圆周率):或者是常量值被定义后,在脚本的其他任何地方都不可以被改变.PHP中的常量分为自定义常量和系统常量 ...
- PHP学习笔记--入门篇
PHP学习笔记--入门篇 一.Echo语句 1.格式 echo是PHP中的输出语句,可以把字符串输出(字符串用双引号括起来) 如下代码 <?php echo "Hello world! ...
- netty深入学习之一: 入门篇
netty深入学习之一: 入门篇 本文代码下载: http://download.csdn.net/detail/cheungmine/8497549 1)Netty是什么 Netty是Java NI ...
- Java工程师学习指南 入门篇
Java工程师学习指南 入门篇 最近有很多小伙伴来问我,Java小白如何入门,如何安排学习路线,每一步应该怎么走比较好.原本我以为之前的几篇文章已经可以解决大家的问题了,其实不然,因为我之前写的文章都 ...
随机推荐
- 图示Servelet请求过程
静态文件的请求处理过程: 客户端浏览器向WebServer发送一个HTTP请求,WebServer解析HTTP请求,然后找到对应的静态文件,读取文件的内容,然后返回给客户端浏览器HTML文本,浏览器解 ...
- 【Maven实战】archetype的使用和eclipse的配置
1.之前在进行项目的构建时都是使用手工进行文件夹的建立,maven也给我们提供了一个参数archetype,可以用来进行项目骨架的建立.使用maven archetype:generate进行创建: ...
- EntityFramework 插件之EntityFramework.Extended (批量处理)
接手了一个用EF来做的项目,由于项目中使用的原生处理,导致很多update都是采用先select 后 update的方式来实现,同时无法批量执行逻辑如:根据订单类型统一更新状态等.所以在经过了N多查找 ...
- WebSocket 支持的浏览器
http://caniuse.com/#feat=websockets
- HBase Split
Region Split请求是在Region MemStore Flush之后被触发的: boolean shouldCompact = region.flushcache(); // We just ...
- 调侃Cookie
近期看着某些小朋友那琢急的学习心态,瞬间发文一篇,谨此以助小朋友早日有成! 闲话不扯远,实话见真言,晃悠许久觉得开头还是谈谈Cookie这只菜篮,而且是一只私家菜篮,为啥说它是一只菜篮呢,各位看官必定 ...
- C#.net实现密码加密算法
//SHA-1算法string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFil ...
- 解决多线程下simpleDateFormat的安全问题
// 日期格式化 private static final ThreadLocal<SimpleDateFormat> GMT_FORMATERS = new ThreadLocal< ...
- 在EF中执行SQL语句
你可能要问,我用EF不就为了避免写SQL吗?如果要写SQL我不如直接用ADO.NET得了.话虽然这么说没错,可有些时候使用EF操作数据还是有一些不方便,例如让你根据条件删除一组记录,如果按照正常的流程 ...
- Java中Timer的用法--转载之网络
用法很简单,new一个timer,然后写一个timertask的子类即可. import java.util.Timer; import java.util.TimerTask; public cla ...