Exemplo n.º 1
0
int MainWindow::contentOfKernel() {
    // create dialog with layout
    QDialog dialog(this);
    dialog.setWindowTitle("Kernel");
    QVBoxLayout layout;
    dialog.setLayout(&layout);

    // add label for information
    QLabel label("Configure your kernel", this);
    label.setAlignment(Qt::AlignCenter);
    layout.addWidget(&label);

    // init table with ones
    QTableView tableView(this);
    tableView.horizontalHeader()->hide();
    tableView.verticalHeader()->hide();
    QStandardItemModel model(kSize, kSize);
    for(int row = 0; row < kSize; row++) {
	for(int col = 0; col < kSize; col++) {
	    QStandardItem *item0 = new QStandardItem(QString::number(1));
	    model.setItem(row, col, item0);
	}
    }
    tableView.setModel(&model);
    tableView.resizeColumnsToContents();
    tableView.resizeRowsToContents();

    // create accept button with surroundings
    QHBoxLayout hLayout;
    hLayout.addStretch(1);
    QPushButton acceptBtn(tr("Accept"),this);
    connect(&acceptBtn,SIGNAL(clicked()), &dialog, SLOT(accept()));
    hLayout.addWidget(&acceptBtn);
    hLayout.addStretch(1);

    // fill layout with matrix
    layout.addWidget(&tableView);
    layout.addLayout(&hLayout);

    // exec modal dialog
    if(dialog.exec() == 0) {
	return -1; // user canceled the dialog
    }

    // interpret values of the table
    bool ok;
    for (int row = 0; row < kSize; row++) {
	for (int col = 0; col < kSize; col++) {
	    QModelIndex index = model.index(row, col);
	    kernel[row][col] = model.data(index).toInt(&ok);
	    if(!ok) {
		return -2; // wrong value
	    }
	}
    }
    return 0;
}
Exemplo n.º 2
0
tristate KexiQueryView::executeQuery(KDbQuerySchema *query)
{
    if (!query)
        return false;
    KexiUtils::WaitCursor wait;
    KDbCursor *oldCursor = d->cursor;
    qDebug() << query->parameters();
    bool ok;
    KDbConnection * conn = KexiMainWindowIface::global()->project()->dbConnection();
    {
        KexiUtils::WaitCursorRemover remover;
        d->currentParams = KexiQueryParameters::getParameters(this,
                 *conn->driver(), query, &ok);
    }
    if (!ok) {//input cancelled
        return cancelled;
    }
    d->cursor = conn->executeQuery(query, d->currentParams);
    if (!d->cursor) {
        window()->setStatus(
            conn,
            xi18n("Query executing failed."));
//! @todo also provide server result and sql statement
        return false;
    }
    setData(d->cursor);

//! @todo remove close() when dynamic cursors arrive
    if (!d->cursor->close()) {
        return false;
    }

    if (oldCursor)
        oldCursor->connection()->deleteCursor(oldCursor);

//! @todo maybe allow writing and inserting for single-table relations?
    tableView()->setReadOnly(true);
//! @todo maybe allow writing and inserting for single-table relations?
    //set data model itself read-only too
    tableView()->data()->setReadOnly(true);
    tableView()->setInsertingEnabled(false);
    return true;
}
Exemplo n.º 3
0
int ParameterDialog::exec() {
  parameter_model_ = new ParameterModel(int(name_parameter_map_.size()), 2, this);

  QStringList headerLabels;
  headerLabels.push_back("Variable Name");
  headerLabels.push_back("Variable Value");
  parameter_model_->setHorizontalHeaderLabels(headerLabels);

  QTableView tableView(this);
  tableView.setModel(parameter_model_);

  size_t currentRow = 0;
  for (std::map<std::string, Parameter*>::iterator it = name_parameter_map_.begin(); it != name_parameter_map_.end(); ++it) {
    QModelIndex name = parameter_model_->index(int(currentRow), 0, QModelIndex());
    parameter_model_->setData(name, QVariant(it->first.c_str()));

    QModelIndex value = parameter_model_->index(int(currentRow), 1, QModelIndex());
    std::pair<QVariant, int> model_data = it->second->toModelData();
    parameter_model_->setData(value, model_data.first, model_data.second);

    currentRow++;
  }

  tableView.setItemDelegate(new ParameterDelegate(name_parameter_map_));

  tableView.horizontalHeader()->setStretchLastSection(true);
  tableView.horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
  tableView.setShowGrid(true);
  tableView.verticalHeader()->hide();
  tableView.setSelectionBehavior(QAbstractItemView::SelectRows);
  tableView.resizeColumnsToContents();

  int totlen = tableView.columnWidth(0) + tableView.columnWidth(1) + frameSize().width();
  setMinimumWidth(totlen);

  QPushButton* pushButtonReset = new QPushButton("Reset", this);
  QPushButton* pushButtonApply = new QPushButton("Apply", this);
  QPushButton* pushButtonCancel = new QPushButton("Cancel", this);
  pushButtonApply->setDefault(true);

  connect(pushButtonReset, SIGNAL(clicked()), this, SLOT(reset()));
  connect(pushButtonApply, SIGNAL(clicked()), this, SLOT(accept()));
  connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));

  QGridLayout gridLayout(this);
  gridLayout.addWidget(&tableView, 0, 0, 1, 3);
  gridLayout.addWidget(pushButtonReset, 1, 0);
  gridLayout.addWidget(pushButtonApply, 1, 1);
  gridLayout.addWidget(pushButtonCancel, 1, 2);
  setLayout(&gridLayout);

  int result = QDialog::exec();

  return result;
}
Exemplo n.º 4
0
KexiQueryView::KexiQueryView(QWidget *parent)
        : KexiDataTableView(parent)
        , d(new Private())
{
    // setup main menu actions
    QList<QAction*> mainMenuActions;
    mainMenuActions
            << sharedAction("project_export_data_table");
    setMainMenuActions(mainMenuActions);

    tableView()->setInsertingEnabled(false); //default
}
void TableViewSpanController::updateSpan()
{
    tableView()->clearSpans();
    QAbstractItemModel * model=tableView()->model();
    for(int i=0;i<model->rowCount(tableView()->rootIndex());i++)
    {
        for(int j=0;j<model->columnCount(tableView()->rootIndex());j++)
        {
            QSize span=model->span(model->index(i,j,
                                                tableView()->rootIndex()));
            if(!span.isNull())
            {
                tableView()->setSpan(i,j,span.height(),span.width());
            }
        }
    }
}