MsgPartNetworkReply::MsgPartNetworkReply(MsgPartNetAccessManager *parent, const QPersistentModelIndex &part, bool requireFormatting): QNetworkReply(parent), part(part), formattedBufferContent(0), requireFormatting(requireFormatting) { QUrl url; url.setScheme(QLatin1String("trojita-imap")); url.setHost(QLatin1String("msg")); url.setPath(part.data(Imap::Mailbox::RolePartPathToPart).toString()); setUrl(url); setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered); Q_ASSERT(part.isValid()); const Mailbox::Model *model = 0; Mailbox::Model::realTreeItem(part, &model); Q_ASSERT(model); connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotModelDataChanged(QModelIndex,QModelIndex))); //TODO: fileDownloadProgress signal in model signal the process of the current download. // This reply might not be the current download, but now we assume that because the only use case here // is just see the download progress of attachments that is usually the only downloading event. // Should match message UID and partId and then emit downloadProgress. connect(model, SIGNAL(fileDownloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64,qint64))); Mailbox::TreeItemPart *partPtr = dynamic_cast<Mailbox::TreeItemPart *>(static_cast<Mailbox::TreeItem *>(part.internalPointer())); Q_ASSERT(partPtr); // We have to ask for contents before we check whether it's already fetched partPtr->fetch(const_cast<Mailbox::Model *>(model)); // The part data might be already unavailable or already fetched QTimer::singleShot(0, this, SLOT(slotMyDataChanged())); buffer.setBuffer(partPtr->dataPtr()); buffer.open(QIODevice::ReadOnly); }
void CStudentManage::InitStudentManage() { m_Model = new MySqlTableModel; m_View = new QTableView(this); connect(m_Model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), this, SLOT(slotModelDataChanged(QModelIndex, QModelIndex, QVector<int>))); //设置表 m_Model->setTable("Student"); //检索 if (!m_Model->select()) { QMessageBox::critical(this, "错误", m_Model->lastError().text()); exit(0); } //设置为手动提交 m_Model->setEditStrategy(QSqlTableModel::OnManualSubmit); //设置表头名 m_Model->setHeaderData(0, Qt::Horizontal, "学号"); m_Model->setHeaderData(1, Qt::Horizontal, "姓名"); m_Model->setHeaderData(2, Qt::Horizontal, "性别"); m_Model->setHeaderData(3, Qt::Horizontal, "出生年月"); m_Model->setHeaderData(4, Qt::Horizontal, "民族"); m_Model->setHeaderData(5, Qt::Horizontal, "班级号"); m_Model->setHeaderData(6, Qt::Horizontal, "入学时间"); m_Model->setHeaderData(7, Qt::Horizontal, "家庭地址"); m_Model->setHeaderData(8, Qt::Horizontal, "政治面貌"); m_Model->setHeaderData(9, Qt::Horizontal, "身份证号"); m_Model->setHeaderData(10, Qt::Horizontal, "职位"); m_Model->setHeaderData(11, Qt::Horizontal, "所学专业"); //设置表格视图的表结构 m_View->setModel(m_Model); //设置性别控件代理 m_View->setItemDelegateForColumn(2, new SexDelegate); //设置班级号控件代理 m_View->setItemDelegateForColumn(5, new ClassIDDelegate); QVBoxLayout *gridlay1; QHBoxLayout *HBoxlay2; QGroupBox *groupbox1; QGroupBox *groupbox2; QGridLayout *layout = new QGridLayout(this); //创建窗体及控件 layout->addWidget(groupbox1 = new QGroupBox("现有学生信息"), 0, 0); layout->addWidget(groupbox2 = new QGroupBox("操作"), 1, 0); groupbox1->setLayout(gridlay1 = new QVBoxLayout); gridlay1->addWidget(m_View); groupbox2->setLayout(HBoxlay2 = new QHBoxLayout); HBoxlay2->addWidget(m_Edit = new QLineEdit); HBoxlay2->addWidget(m_AddStudent = new QPushButton("增加学生")); HBoxlay2->addWidget(m_DelStudent = new QPushButton("删除学生")); HBoxlay2->addWidget(m_ChgStudent = new QPushButton("保存修改")); HBoxlay2->addWidget(m_ExitManage = new QPushButton("退出")); //连接槽函数 connect(m_AddStudent, SIGNAL(clicked()), this, SLOT(slotAddStudentClicked())); connect(m_DelStudent, SIGNAL(clicked()), this, SLOT(slotDelStudentClicked())); connect(m_ChgStudent, SIGNAL(clicked()), this, SLOT(slotChgStudentClicked())); connect(m_ExitManage, SIGNAL(clicked()), this, SLOT(slotExitManageClicked())); connect(m_Edit, SIGNAL(textChanged(QString)), this, SLOT(slotEditTextChanged(QString))); slotModelDataChanged(QModelIndex(), QModelIndex(), QVector<int>()); }