void FormGestioneFerie::on_cbMatricola_currentIndexChanged(const QString &arg1)
{

    ui->cbCognome->setCurrentIndex(ui->cbMatricola->currentIndex());
    QSqlQuery query1(QString("SELECT nome FROM anagrafica where Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
    query1.next();
    ui->lNome->setText( query1.value(0).toString() );

    QSqlTableModel *model = new QSqlTableModel(this, this->db);
    model->setTable("assenze");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));

    model->sort(2,Qt::AscendingOrder);
      model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
      model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
      model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
      ui->tvPermessi->setModel(model);
      ui->tvPermessi->hideColumn(0);
      ui->tvPermessi->resizeColumnsToContents();
      ui->tvPermessi->resizeRowsToContents();
      ui->tvPermessi->selectRow(0);

}
QSqlTableModel* MainWindow::getVenueModel()
{
    ui->tableView_ven->setModel(NULL);
    QSqlTableModel *model = new QSqlTableModel;
    model->setTable("venues");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, "ID");
    model->setHeaderData(1, Qt::Horizontal, "Name");
    return model;
}
void FormGestioneFerie::on_pbAggiungiPermesso_clicked()
{
    for(QDate a=ui->dePermessiDal->date(); a.operator <=( ui->dePermessiAl->date());a= a.addDays(1) )
   {

    qDebug() << "Permesso per "+ui->cbMatricola->currentText()+" per il giorno "+a.toString("dd/MM/yyyy");


    QSqlQuery query;
    query.prepare("INSERT INTO assenze (ID, matricola, causa, data)" "VALUES (?, ?, ?, ?)");
   // query.addBindValue( ui->cbMatricola->currentText()+"_"+ui->dePermessiDal->date().toString("dd/MM/yyyy"));
    query.addBindValue( ui->cbMatricola->currentText()+"_"+a.toString("dd/MM/yyyy"));
    query.addBindValue( ui->cbMatricola->currentText());
    query.addBindValue( ui->cbTipoPermesso->currentText());
   // query.addBindValue( ui->dePermessiDal->date().toString("dd/MM/yyyy"));
    query.addBindValue( a.toString("dd/MM/yyyy"));
    if(query.exec())
    {
        QMessageBox msgBox;
        msgBox.setText("Inserzione nel database.");
        msgBox.setInformativeText(QString("Permesso per il giorno %1 inserito correttamente.").arg(a.toString("dd/MM/yyyy")));
        msgBox.setStandardButtons(QMessageBox::Ok );
        msgBox.setIcon(QMessageBox::Information);
        msgBox.exec();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setText("Inserzione nel database.");
        msgBox.setInformativeText(QString("Permesso per il giorno %1 NON inserito nel database. Probabilmente è gia stato inserito un permesso per lo stesso giorno.").arg(a.toString("dd/MM/yyyy")));
        msgBox.setStandardButtons(QMessageBox::Ok );
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.exec();
    }

    QSqlTableModel *model = new QSqlTableModel(this, this->db);
    model->setTable("assenze");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));

    model->sort(2,Qt::AscendingOrder);
      model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
      model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
      model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
      ui->tvPermessi->setModel(model);
      ui->tvPermessi->hideColumn(0);
      ui->tvPermessi->resizeColumnsToContents();
      ui->tvPermessi->resizeRowsToContents();
      ui->tvPermessi->selectRow(0);

  }
}
示例#4
0
void Control::printNeighbor()
{
    QString whichID = ui->comboBox_5->currentText();
    QSqlTableModel* model = new QSqlTableModel(this);
    model->setTable("Distance");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setFilter("CellID1="+whichID+" and distance<=2 order by distance asc");
    model->setHeaderData(1,Qt::Horizontal,tr("邻居"));
    model->setHeaderData(2,Qt::Horizontal,tr("距离(千米)"));
    model->select();
    ui->tableView->setModel(model);
    ui->tableView->show();
    ui->tableView->setColumnHidden(model->fieldIndex("CellID1"),true);
}
示例#5
0
void MainWindow::setModel(QTableView *tableViewName, QString modelName, QString tableName, QStringList *tableFields, QString filter, int orderNum)
{
    QSqlTableModel *model;
    if (modelName == "modelEdit") {
        modelEdit = new QSqlTableModel;
        model = modelEdit;
    } else if (modelName == "modelChoose") {
        modelChoose = new QSqlTableModel;
        model = modelChoose;
    } else if (modelName == "modelQ") {
        modelQ = new QSqlTableModel;
        model = modelQ;
    } else if (modelName == "modelQE") {
        modelQE = new QSqlTableModel;
        model = modelQE;
    } else if (modelName == "modelNote") {
        modelNote = new QSqlTableModel;
        model = modelNote;
    } else if (modelName== "modelNotes") {
        modelNotes = new QSqlTableModel;
        model = modelNotes;
    } else {
        return;
    }

    model= new QSqlTableModel(this);
    model->setTable(tableName);
    model->setEditStrategy(QSqlTableModel::OnFieldChange);

    model->setSort(orderNum, Qt::DescendingOrder);

    int tableFieldsNum = tableFields->length();
    for (int i = 0; i < tableFieldsNum; i++) {
        model->setHeaderData(i, Qt::Horizontal, tableFields->at(i));
    }

    tableViewName->setModel(model);
    tableViewName->alternatingRowColors();
    tableViewName->horizontalHeader()->setStretchLastSection(true);

    model->setFilter(filter);
    model->select();
    tableViewName->reset();
    qDebug() << modelName << model << model->rowCount();

    if (modelName == "modelEdit") {
        modelEdit = model;
    } else if (modelName == "modelChoose") {
        modelChoose = model;
    } else if (modelName == "modelQ") {
        modelQ = model;
    } else if (modelName == "modelQE") {
        modelQE = model;
    } else if (modelName == "modelNote") {
        modelNote = model;
    } else if (modelName == "modelNotes") {
        modelNotes = model;
    } else return;
}
示例#6
0
QSqlTableModel* SQLService::getTableModel(QString table){
    QSqlTableModel *model = new QSqlTableModel(this, this->db);
    model->setTable(table);
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    return model;
}
示例#7
0
void AdminDialog::initBorrowTableView()
{
    QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
    model->setTable("borrow");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select(); //选取整个表的所有行
    model->setFilter("isreturn=0");
    model->removeColumn(model->columnCount()-1);
    model->removeColumn(model->columnCount()-1);
    model->setHeaderData(0,Qt::Horizontal,"借阅编号");
    model->setHeaderData(1,Qt::Horizontal,"图书编号");
    model->setHeaderData(2,Qt::Horizontal,"读者编号");
    model->setHeaderData(3,Qt::Horizontal,"剩余续借次数");
    model->setHeaderData(4,Qt::Horizontal,"借阅时间");
    model->setHeaderData(5,Qt::Horizontal,"应还时间");
    ui->tv3->setModel(model);
    ui->tv3->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
示例#8
0
void Control::findCellInfo()
{
    if(!checkDurationValid())
    {
        QMessageBox::warning(this,"警告","请选择正确的时间段",QMessageBox::Yes);
        return;
    }
    if(ui->lineEdit->text().isEmpty())
    {
        QMessageBox::warning(this,"警告","请输入拥塞门限(0到1的小数)",QMessageBox::Yes);
        return;
    }
    double rate= ui->lineEdit->text().toDouble();
    QSqlQuery query;
    query.exec("exec countCongs");
    QDateTime start = ui->startDateTimeEdit->dateTime();
    QDateTime end = ui->endDateTimeEdit->dateTime();

    int year1 = start.date().year() % 10 * 10000;
    int month1 = start.date().month() * 100;
    int day1 = start.date().day();
    int hour1 = start.time().hour();
    int year2 = end.date().year() % 10 * 10000;
    int month2 = end.date().month() * 100;
    int day2 = end.date().day();
    int hour2 = end.time().hour();

    query.exec(QString("exec finder2 %1,%2,%3,%4,%5").arg(rate).arg(year1 + month1 + day1).arg(hour1)
               .arg(year2 + month2 + day2).arg(hour2));//finder2只列rate超过门限的部分数据

    QSqlTableModel* model = new QSqlTableModel(this);
    model->setTable("H_result");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setFilter("H_rate>"+QString::number(rate) +" order by CellID,bdate,btime");
    model->setHeaderData(0,Qt::Horizontal,tr("日期"));
    model->setHeaderData(1,Qt::Horizontal,tr("小时"));
    model->setHeaderData(2,Qt::Horizontal,tr("小区ID"));
    model->setHeaderData(3,Qt::Horizontal,tr("小时级话务量"));
    model->setHeaderData(4,Qt::Horizontal,tr("小时级拥塞率"));
    model->setHeaderData(5,Qt::Horizontal,tr("小时级半速率话务量比例"));
    model->select();
    ui->tableView_2->setModel(model);
    ui->tableView_2->show();
}
FormGestioneFerie::FormGestioneFerie(QSqlDatabase db, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FormGestioneFerie)
{
    ui->setupUi(this);

    QDate oggi;
    ui->dePermessiDal->setDate(oggi.currentDate());
    ui->dePermessiAl->setDate(oggi.currentDate());

    this->db= db;



    QSqlQuery query(QString("SELECT Matricola,cognome FROM anagrafica"));
    while (query.next())
    {
     ui->cbMatricola->addItem(  query.value(0).toString() );
     ui->cbCognome->addItem(  query.value(1).toString() );
     ui->lNome->setText( query.value(2).toString() );
    }
    QSqlQuery query1(QString("SELECT nome FROM anagrafica where Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
    query1.next();
    ui->lNome->setText( query1.value(0).toString() );



    QSqlTableModel *model = new QSqlTableModel(this, this->db);
    model->setTable("assenze");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
    model->sort(2,Qt::AscendingOrder);
    model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
    model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
    model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
    ui->tvPermessi->setModel(model);
    ui->tvPermessi->hideColumn(0);
    ui->tvPermessi->resizeColumnsToContents();
    ui->tvPermessi->resizeRowsToContents();
    ui->tvPermessi->selectRow(0);


}
示例#10
0
TableView::TableView()
   : QWidget()
{
   if (! this->createConnection()) {
      QString msg = "** Create Database Error";
      throw msg;
   }

   setWindowTitle(tr("Table View Model"));
   setMinimumSize(300, 350);

   //
   QSqlTableModel *model = new QSqlTableModel(this, m_db);

   QStringList tempX = m_db.tables();
   model->setTable(tempX.at(0));

   QSqlError error = model->lastError();

   if ( error.isValid() )  {
      ksMsg( this, "Table View - SQL Error", error.text() );
   }

   model->setEditStrategy(QSqlTableModel::OnManualSubmit);
   model->setSort(2, Qt::AscendingOrder);
   model->select();

   model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
   model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
   model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));

   //
   QTableView *view = new QTableView;
   view->setModel(model);
   view->resizeColumnsToContents();

   QHeaderView *temp = view->horizontalHeader();
   temp->setStretchLastSection(true);

   QHBoxLayout *mainLayout = new QHBoxLayout;
   mainLayout->addWidget(view);
   setLayout(mainLayout);  
}
示例#11
0
/*----------查询数据库全体-------------*/
void DataDialog::on_pushButton_clicked()
{
    QSqlQuery query;
    query.exec("drop view if exists temp");
    query.exec("create view temp as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata)");
    if(!query.isActive())
    {
        if(QSqlDatabase::database().open())
        {
            query.exec("drop view if exists temp");
            query.exec("create view temp as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata)");
        }
    }//重连数据库
    QSqlTableModel *m = new QSqlTableModel(this);
    m->setTable("temp");
    m->select();
    m->setHeaderData(0,Qt::Horizontal,tr("编号"));
    m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
    m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
    m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
    m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
    m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
    m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
    ui->tableView->setModel(m);

}
示例#12
0
/*------------根据节点编号筛选查询数据库------------*/
void DataDialog::on_nodeList_currentIndexChanged(const QString &arg1)
{
    QSqlTableModel *m = new QSqlTableModel(this);
    if(arg1==tr("全部"))
        {
        on_pushButton_clicked();
        return ;
    }
    else
    {
        QSqlQuery query;
        query.exec("drop view if exists temp2");
        QString sql = QString("create view temp2 as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata where gatewayNo = %1)").arg(arg1.toInt());
        qDebug() << "sql = " << sql;
        query.exec(sql);

        m->setTable("temp2");
        m->select();
        m->setHeaderData(0,Qt::Horizontal,tr("编号"));
        m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
        m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
        m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
        m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
        m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
        m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
        ui->tableView->setModel(m);
    }
}
示例#13
0
void QSqlTableModel_snippets()
{
//! [24]
    QSqlTableModel *model = new QSqlTableModel(parentObject, database);
    model->setTable("employee");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    model->setHeaderData(1, Qt::Horizontal, tr("Salary"));

    QTableView *view = new QTableView;
    view->setModel(model);
    view->hideColumn(0); // don't show the ID
    view->show();
//! [24]

    {
//! [25]
    QSqlTableModel model;
    model.setTable("employee");
    QString name = model.record(4).value("name").toString();
//! [25]
    }
}
示例#14
0
/*----------根据污染元筛选查询数据库-------------*/
void DataDialog::on_nameList_currentIndexChanged(const QString &arg1)
{
    //建立code和name的对应关系方便显示
    mapCodeName mCodeName[] =
    {{"1_voltage","电压"}, {"1_light","光照"}, {"1_a01001","温度"}, {"1_a01002","湿度"},
     {"2_a01001_e","外部温度"}, {"2_a01001_i","内部温度"}, {"2_a06003","PH"}, {"2_a06001","雨量"},
     {"2_a01007","风速"}, {"2_a01008","风向"}, {"2_voltage","电源电压"}, {"2_a06002","是否降雨"},
     {"3_a01001_30","温度(30cm)"}, {"3_a01002_30","湿度(30cm)"}, {"3_a01001_15","温度(15cm)"},
     {"3_a01002_15","湿度(15cm)"}, {"3_a01001_05","温度(5cm)"}, {"3_a01002_05","湿度(5cm)"},
     {"4_a01001","温度"}, {"4_a01002","湿度"}, {"4_w01008_v","垂直盐分"}, {"4_w01008_s","表面盐分"}};
    enum {LENGTH_M = 22};
    QMap<QString,QString>nameCode;

    for(int i = 0; i < LENGTH_M; i++)
    {
        nameCode.insert(tr(mCodeName[i].name),mCodeName[i].code);
    }

    QSqlTableModel *m = new QSqlTableModel(this);
    if(arg1==tr("全部"))
    {
        on_pushButton_clicked();
        return ;
    }

    else
    {

    QSqlQuery query;

    query.exec("drop view if exists temp1");

    QString sql = QString("create view temp1 as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata where code = '%1')").arg(nameCode[arg1]);
    qDebug() << "sql = " << sql;
    query.exec(sql);

    m->setTable("temp1");
    m->select();
    m->setHeaderData(0,Qt::Horizontal,tr("编号"));
    m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
    m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
    m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
    m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
    m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
    m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
    ui->tableView->setModel(m);
    }
}
示例#15
0
void ListPc::updateUI(){
    QSqlTableModel *model = new QSqlTableModel(this, QSqlDatabase::database());
    model->setTable("pc");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, tr("ID"));
    model->setHeaderData(1, Qt::Horizontal, tr("Processzor"));
    model->setHeaderData(2, Qt::Horizontal, tr("Memórie"));
    model->setHeaderData(3, Qt::Horizontal, tr("Merevlemez"));
    model->setHeaderData(4, Qt::Horizontal, tr("Operációs rendszer"));
    model->setHeaderData(5, Qt::Horizontal, tr("Megjegyzés"));


    ui->tableView_listpc->setModel(model);
    ui->tableView_listpc->hideColumn(0);
    ui->tableView_listpc->resizeColumnsToContents();
}
示例#16
0
void AdminDialog::initBookTableView()
{
    QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
    model->setTable("book");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select(); //选取整个表的所有行
    model->setHeaderData(0,Qt::Horizontal,"图书编号");
    model->setHeaderData(1,Qt::Horizontal,"书名");
    model->setHeaderData(2,Qt::Horizontal,"作者");
    model->setHeaderData(3,Qt::Horizontal,"出版社");
    model->setHeaderData(4,Qt::Horizontal,"出版日期");
    model->setHeaderData(5,Qt::Horizontal,"价格");
    model->setHeaderData(6,Qt::Horizontal,"类型");
    model->setHeaderData(7,Qt::Horizontal,"总数量");
    model->setHeaderData(8,Qt::Horizontal,"在馆数");
    ui->tv1->setModel(model);
    ui->tv1->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
示例#17
0
QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WindowFlags fl )
    : QDialog( parent, fl )
{
  setupUi( this );
  restorePosition();

  //
  // Create the zoomto and delete buttons and add them to the
  // toolbar
  //
  QPushButton *btnAdd    = new QPushButton( tr( "&Add" ) );
  QPushButton *btnDelete = new QPushButton( tr( "&Delete" ) );
  QPushButton *btnZoomTo = new QPushButton( tr( "&Zoom to" ) );
  QPushButton *btnImpExp = new QPushButton( tr( "&Share" ) );

  btnZoomTo->setDefault( true );
  buttonBox->addButton( btnAdd, QDialogButtonBox::ActionRole );
  buttonBox->addButton( btnDelete, QDialogButtonBox::ActionRole );
  buttonBox->addButton( btnZoomTo, QDialogButtonBox::ActionRole );
  buttonBox->addButton( btnImpExp, QDialogButtonBox::ActionRole );

  QMenu *share = new QMenu();
  QAction *btnExport = share->addAction( tr( "&Export" ) );
  QAction *btnImport = share->addAction( tr( "&Import" ) );
  connect( btnExport, SIGNAL( triggered() ), this, SLOT( exportToXML() ) );
  connect( btnImport, SIGNAL( triggered() ), this, SLOT( importFromXML() ) );
  btnImpExp->setMenu( share );

  connect( btnAdd, SIGNAL( clicked() ), this, SLOT( addClicked() ) );
  connect( btnDelete, SIGNAL( clicked() ), this, SLOT( deleteClicked() ) );
  connect( btnZoomTo, SIGNAL( clicked() ), this, SLOT( zoomToBookmark() ) );

  // open the database
  QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE", "bookmarks" );
  db.setDatabaseName( QgsApplication::qgisUserDbFilePath() );
  if ( !db.open() )
  {
    QMessageBox::warning( this, tr( "Error" ),
                          tr( "Unable to open bookmarks database.\nDatabase: %1\nDriver: %2\nDatabase: %3" )
                          .arg( QgsApplication::qgisUserDbFilePath() )
                          .arg( db.lastError().driverText() )
                          .arg( db.lastError().databaseText() )
                        );
    deleteLater();
    return;
  }

  QSqlTableModel *model = new QSqlTableModel( this, db );
  model->setTable( "tbl_bookmarks" );
  model->setSort( 0, Qt::AscendingOrder );
  model->setEditStrategy( QSqlTableModel::OnFieldChange );
  model->select();

  // set better headers then column names from table
  model->setHeaderData( 0, Qt::Horizontal, tr( "ID" ) );
  model->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) );
  model->setHeaderData( 2, Qt::Horizontal, tr( "Project" ) );
  model->setHeaderData( 3, Qt::Horizontal, tr( "xMin" ) );
  model->setHeaderData( 4, Qt::Horizontal, tr( "yMin" ) );
  model->setHeaderData( 5, Qt::Horizontal, tr( "xMax" ) );
  model->setHeaderData( 6, Qt::Horizontal, tr( "yMax" ) );
  model->setHeaderData( 7, Qt::Horizontal, tr( "SRID" ) );

  lstBookmarks->setModel( model );

  QSettings settings;
  lstBookmarks->header()->restoreState( settings.value( "/Windows/Bookmarks/headerstate" ).toByteArray() );

#ifndef QGISDEBUG
  lstBookmarks->setColumnHidden( 0, true );
#endif
}
示例#18
0
QSqlTableModel *EmployeeDataModel::initializeTableModel() {
    QSqlTableModel *model = new QSqlTableModel(this);
    model->setTable(QLatin1String("employee"));
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);

    model->setHeaderData(POS_EMPLOYEE_ID, Qt::Horizontal, QObject::tr("ID"));
    model->setHeaderData(POS_EMPLOYEE_NR, Qt::Horizontal, QObject::tr("Emp.Number"));
    model->setHeaderData(POS_EMPLOYEE_GENDER, Qt::Horizontal, QObject::tr("Gender"));
    model->setHeaderData(POS_EMPLOYEE_TITLE_ID, Qt::Horizontal, QObject::tr("Title"));
    model->setHeaderData(POS_EMPLOYEE_FIRSTNAME, Qt::Horizontal, QObject::tr("Firstname"));
    model->setHeaderData(POS_EMPLOYEE_LASTNAME, Qt::Horizontal, QObject::tr("Lastname"));
    model->setHeaderData(POS_EMPLOYEE_ADDRESS_ID, Qt::Horizontal, QObject::tr("address"));
    model->setHeaderData(POS_EMPLOYEE_BIRTHDAY, Qt::Horizontal, QObject::tr("Birthday"));
    model->setHeaderData(POS_EMPLOYEE_EMAIL, Qt::Horizontal, QObject::tr("EMail"));
    model->setHeaderData(POS_EMPLOYEE_DATACARE, Qt::Horizontal, QObject::tr("Datacare"));
    model->setHeaderData(POS_EMPLOYEE_ACTIVE, Qt::Horizontal, QObject::tr("Active"));
    model->setHeaderData(POS_EMPLOYEE_STARTDATE, Qt::Horizontal, QObject::tr("StartDate"));
    model->setHeaderData(POS_EMPLOYEE_ENDDATE, Qt::Horizontal, QObject::tr("EndDate"));
    model->setHeaderData(POS_EMPLOYEE_DEPARTMENT_ID, Qt::Horizontal, QObject::tr("Department"));
    model->setHeaderData(POS_EMPLOYEE_FUNCTION_ID, Qt::Horizontal, QObject::tr("Function"));
    model->setHeaderData(POS_EMPLOYEE_COMPUTER_ID, Qt::Horizontal, QObject::tr("Computer"));
    model->setHeaderData(POS_EMPLOYEE_PRINTER_ID, Qt::Horizontal, QObject::tr("Printer"));
    model->setHeaderData(POS_EMPLOYEE_PHONE_ID, Qt::Horizontal, QObject::tr("Phone"));
    model->setHeaderData(POS_EMPLOYEE_MOBILE_ID, Qt::Horizontal, QObject::tr("Mobile"));
    model->setHeaderData(POS_EMPLOYEE_FAX_ID, Qt::Horizontal, QObject::tr("Fax"));
    model->setHeaderData(POS_EMPLOYEE_EMPLOYEE_ACCOUNT_ID, Qt::Horizontal, QObject::tr("Accounts"));
    model->setHeaderData(POS_EMPLOYEE_EMPLOYEE_DOCUMENT_ID, Qt::Horizontal, QObject::tr("Documents"));
    model->setHeaderData(POS_EMPLOYEE_LAST_UPDATE, Qt::Horizontal, QObject::tr("Last Update"));

    model->select();

    return model;
}
示例#19
0
QgsBookmarks::QgsBookmarks( QWidget *parent ) : QDockWidget( parent )
{
    setupUi( this );
    restorePosition();

    QToolButton* btnImpExp = new QToolButton;
    btnImpExp->setAutoRaise( true );
    btnImpExp->setToolTip( tr( "Import/Export Bookmarks" ) );
    btnImpExp->setIcon( QgsApplication::getThemeIcon( "/mActionSharing.svg" ) );
    btnImpExp->setPopupMode( QToolButton::InstantPopup );

    QMenu *share = new QMenu( this );
    QAction *btnExport = share->addAction( tr( "&Export" ) );
    QAction *btnImport = share->addAction( tr( "&Import" ) );
    btnExport->setIcon( QgsApplication::getThemeIcon( "/mActionSharingExport.svg" ) );
    btnImport->setIcon( QgsApplication::getThemeIcon( "/mActionSharingImport.svg" ) );
    connect( btnExport, SIGNAL( triggered() ), this, SLOT( exportToXML() ) );
    connect( btnImport, SIGNAL( triggered() ), this, SLOT( importFromXML() ) );
    btnImpExp->setMenu( share );

    connect( actionAdd, SIGNAL( triggered() ), this, SLOT( addClicked() ) );
    connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteClicked() ) );
    connect( actionZoomTo, SIGNAL( triggered() ), this, SLOT( zoomToBookmark() ) );

    mBookmarkToolbar->addWidget( btnImpExp );
    mBookmarkToolbar->addAction( actionHelp );

    // open the database
    QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE", "bookmarks" );
    db.setDatabaseName( QgsApplication::qgisUserDbFilePath() );
    if ( !db.open() )
    {
        QMessageBox::warning( this, tr( "Error" ),
                              tr( "Unable to open bookmarks database.\nDatabase: %1\nDriver: %2\nDatabase: %3" )
                              .arg( QgsApplication::qgisUserDbFilePath() )
                              .arg( db.lastError().driverText() )
                              .arg( db.lastError().databaseText() )
                            );
        deleteLater();
        return;
    }

    QSqlTableModel *model = new QSqlTableModel( this, db );
    model->setTable( "tbl_bookmarks" );
    model->setSort( 0, Qt::AscendingOrder );
    model->setEditStrategy( QSqlTableModel::OnFieldChange );
    model->select();

    // set better headers then column names from table
    model->setHeaderData( 0, Qt::Horizontal, tr( "ID" ) );
    model->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) );
    model->setHeaderData( 2, Qt::Horizontal, tr( "Project" ) );
    model->setHeaderData( 3, Qt::Horizontal, tr( "xMin" ) );
    model->setHeaderData( 4, Qt::Horizontal, tr( "yMin" ) );
    model->setHeaderData( 5, Qt::Horizontal, tr( "xMax" ) );
    model->setHeaderData( 6, Qt::Horizontal, tr( "yMax" ) );
    model->setHeaderData( 7, Qt::Horizontal, tr( "SRID" ) );

    lstBookmarks->setModel( model );

    QSettings settings;
    lstBookmarks->header()->restoreState( settings.value( "/Windows/Bookmarks/headerstate" ).toByteArray() );

#ifndef QGISDEBUG
    lstBookmarks->setColumnHidden( 0, true );
#endif
}
void FormGestioneFerie::on_tvPermessi_doubleClicked(const QModelIndex &index)
{

    if(index.column()==2)
    {
        QMessageBox msgBox;
        msgBox.setText("Cancella assenza programmata.");
        msgBox.setInformativeText(QString("Cancellare l'assenza programmata di %2 per il giorno %1 ?").arg(index.data().toString()).arg(ui->cbCognome->currentText()));
        msgBox.setStandardButtons(QMessageBox::Apply |QMessageBox::Discard  );
        msgBox.setIcon(QMessageBox::Question);
        int ret = msgBox.exec();
        if (ret==QMessageBox::Apply )
        {
            QSqlQuery query(QString("DELETE FROM assenze where id=\"%1\"").arg(ui->cbMatricola->currentText()+"_"+index.data().toString()));
            query.exec();
            qDebug() << query.lastError();

            QSqlTableModel *model = new QSqlTableModel(this, this->db);
            model->setTable("assenze");
            model->setEditStrategy(QSqlTableModel::OnFieldChange);
            model->select();
            model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));

            model->sort(2,Qt::AscendingOrder);
            model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
            model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
            model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
            ui->tvPermessi->setModel(model);
            ui->tvPermessi->hideColumn(0);
            ui->tvPermessi->resizeColumnsToContents();
            ui->tvPermessi->resizeRowsToContents();
            ui->tvPermessi->selectRow(0);
        }
    }

}