#include "medicalrecordmanager.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QDebug>

MedicalRecordManager::MedicalRecordManager(QWidget * parent):QWidget(parent)
{
    init();
    initLay();
    initConnect();
    initTable();
}
MedicalRecordManager::~MedicalRecordManager()
{

}
void  MedicalRecordManager::init()
{
    //搜索条件
     m_grpSearchConditionDes.setTitle(tr("SearchCondition"));
    //检查号
    m_chCheckNum.setText(tr("CheckNum"));;
    QLineEdit m_editCheckNum;
    //姓名
     m_chName.setText(tr("Name"));;;
    //检查日期
     m_chCheckDate.setText(tr("CheckDate"));
    //搜索
    m_btnSearch.setText(tr("Search"));;;
}
void  MedicalRecordManager::initLay()
{
    QGridLayout * gridlaySearch = new QGridLayout;
    QHBoxLayout * hlaySearch = new QHBoxLayout;
    QVBoxLayout * vlaySearch = new QVBoxLayout;
    vlaySearch->addLayout(gridlaySearch);
    vlaySearch->addLayout(hlaySearch);
    m_grpSearchConditionDes.setLayout(vlaySearch);

    int col = 0;
    int row = 0;
    gridlaySearch->addWidget(&m_chCheckNum,row,col);
    gridlaySearch->addWidget(&m_editCheckNum,row,++col);
    row ++;
    col = 0;
    gridlaySearch->addWidget(&m_chName,row,col);
    gridlaySearch->addWidget(&m_editName,row,++col);
    row ++;

    col = 0;
    gridlaySearch->addWidget(&m_chCheckDate,row,col);
    gridlaySearch->addWidget(&m_editDate,row,++col);

    hlaySearch->addStretch();
    hlaySearch->addWidget(&m_btnSearch);

}
bool  MedicalRecordManager::initConnect()
{

}

void MedicalRecordManager::initTable()
{
        m_tableWidget.setFocusPolicy(Qt::NoFocus);
        m_tableWidget.setColumnCount(8);
        m_tableWidget.setRowCount(100);
        //m_tableWidget.setShowGrid(false);
        QFont font;
        font.setFamily("SimSun");
        font.setPixelSize(12);
        font.setBold(false);
        m_tableWidget.horizontalHeader()->setFont(font);
        m_tableWidget.setFont(font);
        //设置全选按钮
        connect(&m_tableWidget, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(slotCilclidItem(QTableWidgetItem *)), Qt::QueuedConnection);

        /* 设置 tableWidget */
        //m_tableWidget.verticalHeader()->setVisible(true);
        //m_tableWidget.verticalHeader()->setVisible(true);
        //设置选择一个
        m_tableWidget.setSelectionMode(QAbstractItemView::SingleSelection);
        m_tableWidget.setSelectionBehavior(QAbstractItemView::SelectItems);
        m_tableWidget.setWordWrap(false);
        /*单个选中  QAbstractItemView::ExtendedSelection);   可以选中多个*/
        m_tableWidget.horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
        m_tableWidget.horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
        //m_tableWidget.horizontalHea  der()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
        m_tableWidget.horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
        m_tableWidget.horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
        m_tableWidget.horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
        m_tableWidget.setEditTriggers(QAbstractItemView::NoEditTriggers);
        m_tableWidget.setShowGrid(true);
        for (int row = 0; row < m_tableWidget.rowCount(); row++)
        {
            QTableWidgetItem  *item_id = new QTableWidgetItem;
            QTableWidgetItem  *item_fileName = new QTableWidgetItem;
            QTableWidgetItem  *item_hash = new QTableWidgetItem;
            QTableWidgetItem  *item_butt = new QTableWidgetItem;
            QTableWidgetItem  *item_createDate = new QTableWidgetItem;
            QTableWidgetItem  *item_hash6 = new QTableWidgetItem;
            QTableWidgetItem  *item_butt7 = new QTableWidgetItem;
            QTableWidgetItem  *item_createDate8 = new QTableWidgetItem;
            item_id->setData(Qt::DisplayRole, "");
            item_fileName->setData(Qt::DisplayRole, "");

            item_hash->setData(Qt::DisplayRole, "");
            item_butt->setData(Qt::DisplayRole, "");
           item_createDate->setData(Qt::DisplayRole, "");

           item_hash6->setData(Qt::DisplayRole, "");
           item_butt7->setData(Qt::DisplayRole, "");
           item_createDate8->setData(Qt::DisplayRole, "");

            m_tableWidget.setItem(row, 0, item_id);
            m_tableWidget.setItem(row, 1, item_fileName);
            m_tableWidget.setItem(row, 2, item_hash);
            m_tableWidget.setItem(row, 3, item_butt);
            m_tableWidget.setItem(row, 4, item_createDate);

            m_tableWidget.setItem(row, 2, item_hash6);
            m_tableWidget.setItem(row, 3, item_butt7);
            m_tableWidget.setItem(row, 4, item_createDate8);

            m_tableWidget.item(row, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
        QStringList lstHHead;
            /*("序号")  "文件") << "修改日期"*/
        lstHHead << tr("序号") << tr("检查号") << tr("类别") << tr("姓名") <<tr("性别")
                 << tr("年龄") <<tr("左右利")<<tr("其他信息");
        m_tableWidget.setHorizontalHeaderLabels(lstHHead);//setWordWrap(true)
        m_tableWidget.show();
}
