Exemple #1
0
    void  FenPrincipale::afficherTable()
    {
    //    database = FenPrincipale::newdatabase;
    //     createConnection();

        //QMessageBox::information(0,QObject::tr("debug"),
          //              "debug "+database);

        QSqlTableModel  *model = new QSqlTableModel ();
        model->setTable( "stationStationnee" );
        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
        model->setSort(0,Qt::AscendingOrder);
        model->select();
        QSqlTableModel  *model1 = new QSqlTableModel ();
        model1->setTable("mesures");
        model1->setEditStrategy(QSqlTableModel::OnManualSubmit);
        model1->setSort(0,Qt::AscendingOrder);
        model1->select();


        tabless->setModel( model );
        tabless->show();
    //    tabless->setColumnHidden(0,true);

        tabless->setColumnHidden(5,true);
        tabless->setColumnHidden(6,true);
        tabless->setColumnHidden(7,true);
        tabless->resizeColumnToContents(1);
        tablemesures->setModel( model1 );
       // tablemesures->setColumnHidden(0,true);
        tablemesures->setColumnHidden(19,true);
        tablemesures->resizeColumnsToContents();
         QSqlQuery query;
         QModelIndex index;

    //     query.exec("select id from mesures where classe = 30");
    //     int id=0;
    //     while (query.next()) {
    //            id  = query.value(0).toInt();
    //       }

    //    if (index.row() == id)
    //       {
    //           tablemesures->setBackgroundRole(QPalette::Text);
    //       }tmpAreteList->count()
        tablemesures->show();


    //    QString date = "";
    //    QFileInfo file(database);

    //    QDateTime lastModified = file.lastModified();
    //    date = lastModified.toString();
    //    bool valid  = QFile::copy (database, database+"."+date);


    }
Exemple #2
0
    void FenPrincipale::deleteRow()
    {
        QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tablemesures->model());
        if (!model)
            return;

          model->setEditStrategy(QSqlTableModel::OnManualSubmit);

        QModelIndexList currentSelection = tablemesures->selectionModel()->selectedIndexes();
        for (int i = 0; i < currentSelection.count(); ++i) {
            if (currentSelection.at(i).column() != 0)
                continue;
            model->removeRow(currentSelection.at(i).row());

           }
            model->submitAll();
            model->setEditStrategy(QSqlTableModel ::OnManualSubmit);
       }
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 DataViewer::onDatabaseItemActivated(const DatabaseItem &item)
{
    if ((DatabaseItem::Table != item.m_type) &&
            (DatabaseItem::View != item.m_type))
    {
        return;
    }

    d_ptr->database = item.m_database;

    // for table tableShema
    QSqlRecord record = item.m_database.record(item.m_value);

    d_ptr->m_shemaModel->removeRows(0, d_ptr->m_shemaModel->rowCount());
    d_ptr->m_shemaModel->insertRows(0, record.count());

    for (int i = 0; i < record.count(); ++i)
    {
        QSqlField field = record.field(i);

        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 0), field.name());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 1),
                              field.type() == QVariant::Invalid ? "???" : QString(QVariant::typeToName(field.type())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 2),
                              (field.length() < 0) ? QVariant("???") : field.length());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 3),
                              (field.precision() < 0) ? QVariant("???") : field.precision());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 4),
                              field.requiredStatus() == QSqlField::Unknown ? "???" : QVariant(bool(field.requiredStatus())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 5), field.isAutoValue());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 6), field.defaultValue());
    }

    d_ptr->m_tableShema->setModel(d_ptr->m_shemaModel.data());
    d_ptr->m_tableShema->setEditTriggers(QAbstractItemView::NoEditTriggers);
    d_ptr->m_tableShema->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Scheme, tr(::c_schemeTable).arg(item.m_value));

    // for table tableData
    QSqlTableModel *modelData = new QSqlTableModel(0, item.m_database);
    modelData->setEditStrategy(QSqlTableModel::OnRowChange);
    modelData->setTable(item.m_value);
    modelData->select();

    d_ptr->m_tableData->setModel(modelData);
    d_ptr->m_tableData->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
    d_ptr->m_tableData->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Data, tr(::c_dataTable).arg(item.m_value));

    d_ptr->m_sqlDataModel.reset(modelData);
}
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);

  }
}
Exemple #6
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);
}
Exemple #7
0
void Browser::showTable(const QString &t)
{
    QSqlTableModel *model = new QSqlTableModel(table, connectionWidget->currentDatabase());
    model->setEditStrategy(QSqlTableModel::OnRowChange);
    model->setTable(t);
    model->select();
    if (model->lastError().type() != QSqlError::NoError)
        emit statusMessage(model->lastError().text());
    table->setModel(model);
    table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);

    connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
            this, SLOT(currentChanged()));
    updateActions();
}
Exemple #8
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();
}
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);
}
Exemple #10
0
void MainWindow::viewTable()
{
    QString table;
    //table = "SELECT * FROM '";
    table.append(ui->viewEdit->text());
    //table.append("'");
    
    //dbQuery.exec(table);
    
    QSqlTableModel * tmodel = new QSqlTableModel;
    tmodel->setTable(table);
    tmodel->select();
    tmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    
    tview = new QTableView;
    tview->setModel(tmodel);
    tview->show();
}
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);
}
Exemple #12
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);


}
Exemple #14
0
    void FenPrincipale::insertRow()
    {
        QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tablemesures->model());

        if (!model)
            return;

        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
        QModelIndex insertIndex = tablemesures->currentIndex();

        int row = insertIndex.row() == -1 ? 0 : insertIndex.row();

        model->insertRow(row);
        insertIndex = model->index(row, 0);
        tablemesures->setCurrentIndex(insertIndex);
        tablemesures->edit(insertIndex);


    }
Exemple #15
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);  
}
Exemple #16
0
QString CacheDatabase::getField(const QString &what, const QString &where, const QString &value)
{
    // If same return
    if(what == where)
        return QString::null;
    // Create model
    QSqlTableModel* model = new QSqlTableModel;
    // Set table
    model->setTable(CacheTableName);
    // Edit stategy
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    // Set filter
    model->setFilter(QString("%1='%2'").arg(where, value));
    // Run selection
    model->select();
    // Get record
    QSqlRecord record = model->record(0);
    // If not empty
    if(!record.isEmpty())
        // Get value
        return record.value(record.indexOf(what)).toString();
    // Return result
    return QString::null;
}
Exemple #17
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]
    }
}
Exemple #18
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
}
Exemple #19
0
void DocumentSaverDB::saveDocumentPositions( KraftDoc *doc )
{
    DocPositionList posList = doc->positions();

    // invert all pos numbers to avoid a unique violation
    // FIXME: We need non-numeric ids
    QSqlQuery upq;
    QString queryStr = "UPDATE docposition SET ordNumber = -1 * ordNumber WHERE docID=";
    queryStr +=  doc->docID().toString();
    queryStr += " AND ordNumber > 0";
    upq.prepare( queryStr );
    upq.exec();

    int ordNumber = 1;

    QSqlTableModel model;
    model.setTable("docposition");
    model.setEditStrategy(QSqlTableModel::OnManualSubmit);

    QVector<int> deleteIds;

    DocPositionListIterator it( posList );
    while( it.hasNext() ) {
        DocPositionBase *dpb = it.next();

        DocPosition *dp = static_cast<DocPosition*>(dpb);
        QSqlRecord record ;
        bool doInsert = true;

        int posDbID = dp->dbId().toInt();
        kDebug() << "Saving Position DB-Id: " << posDbID << endl;

        if( dp->toDelete() ) {
            kDebug() << "Delete item " << dp->dbId().toString() << endl;

            // store the id to delete, rather than killing the model index.
            // did that before here, which removed wrong items.
            deleteIds << posDbID;

            // delete all existing attributes no, which will not disturb the model index
            dp->attributes().dbDeleteAll( dp->dbId() );
            continue;
        }

        if( posDbID > -1 ) {
            const QString selStr = QString("docID=%1 AND positionID=%2").arg( doc->docID().toInt() ).arg( posDbID );
            // kDebug() << "Selecting with " << selStr << endl;
            model.setFilter( selStr );
            model.select();
            if ( model.rowCount() > 0 ) {
                if( ! dp->toDelete() )
                    record = model.record(0);
                doInsert = false;
            } else {
                kError() << "ERR: Could not select document position record" << endl;
                return;
            }
        } else {
            // The record is new
            record = model.record();
        }

        if( record.count() > 0 ) {
            // kDebug() << "Updating position " << dp->position() << " is " << dp->text() << endl;
            QString typeStr = PosTypePosition;
            double price = dp->unitPrice().toDouble();

            if ( dp->type() == DocPositionBase::ExtraDiscount ) {
                typeStr = PosTypeExtraDiscount;
            }

            record.setValue( "docID",     QVariant(doc->docID().toInt()));
            record.setValue( "ordNumber", QVariant(ordNumber));
            record.setValue( "text",      QVariant(dp->text()));
            record.setValue( "postype",   QVariant(typeStr));
            record.setValue( "amount",    QVariant(dp->amount()));
            int unitId = dp->unit().id();
            record.setValue( "unit",      QVariant(unitId));
            record.setValue( "price",     QVariant(price));
            record.setValue( "taxType",   QVariant(dp->taxType()));

            ordNumber++; // FIXME

            if( doInsert ) {
                kDebug() << "Inserting!" << endl;
                model.insertRecord(-1, record);
                model.submitAll();
                dp->setDbId( KraftDB::self()->getLastInsertID().toInt() );
            } else {
                kDebug() << "Updating!" << endl;
                model.setRecord(0, record);
                model.submitAll();
            }
        } else {
            kDebug() << "ERR: No record object found!" << endl;
        }

        dp->attributes().save( dp->dbId() );

        QSqlError err = model.lastError();
        if( err.type() != QSqlError::NoError ) {
            kDebug() << "SQL-ERR: " << err.text() << " in " << model.tableName() << endl;
        }

    }
    model.submitAll();

    /*  remove the docpositions that were marked to be deleted */
    if( deleteIds.count() ) {
        QSqlQuery delQuery;
        delQuery.prepare( "DELETE FROM docposition WHERE positionID=:id" );
        foreach( int id, deleteIds ) {
            kDebug() << "Deleting attribute id " << id;
            delQuery.bindValue( ":id", id );
            delQuery.exec();
        }
Exemple #20
0
void Browser::on_rowStrategyAction_triggered()
{
    QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
    if (tm)
        tm->setEditStrategy(QSqlTableModel::OnRowChange);
}
Exemple #21
0
void Browser::on_manualStrategyAction_triggered()
{
    QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
    if (tm)
        tm->setEditStrategy(QSqlTableModel::OnManualSubmit);
}
Exemple #22
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);
        }
    }

}