예제 #1
0
    void finalizeCell(unsigned row, unsigned column) {
        auto &cell = cells[row][column];
        if (cell.getState() != Cell::State::Unknown) {
            throw MultipleStateChangeException();
        }
        cell.setState(Cell::State::Final);

        const auto value = cell.getValue();
        rowCounts[row][value]--;
        columnCounts[column][value]--;
        unknownCellCount--;
        
        if (columnCounts[column][value] > 0) {
            for (auto r = 0U; r < size; r++) {
                auto &cell = cells[r][column];
                if (r != row && cell.getValue() == value) {
                    switch (cell.getState()) {
                    case Cell::State::Final:
                        throw NoSolutionExistsException("multiple finalized values found in a column");

                    case Cell::State::Unknown:
                        deleteCell(r, column);
                    }
                }
            }
        }

        if (rowCounts[row][value] > 0) {
            for (auto c = 0U; c < size; c++) {
                auto &cell = cells[row][c];
                if (c != column && cell.getValue() == value) {
                    switch (cell.getState()) {
                    case Cell::State::Final:
                        throw NoSolutionExistsException("multiple finalized values found in a row");

                    case Cell::State::Unknown:
                        deleteCell(row, c);
                    }
                }
            }
        }
    }
예제 #2
0
/**
 * Class constructor.
 */
DatasetEditWidget::DatasetEditWidget(QWidget *parent):
	QWidget(parent),
    ui(new Ui::DatasetEditWidget),
	model(NULL),
	contextMenu(NULL)
{
    //autogenerated stuff
	ui->setupUi(this);

    //connects signals and slots
	connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu()));
	connect(ui->patternCountBox, SIGNAL(valueChanged(int)), this, SLOT(changePatternCount(int)));
	connect(ui->inputCountBox, SIGNAL(valueChanged(int)), this, SLOT(changeInputCount(int)));
	connect(ui->outputCountBox, SIGNAL(valueChanged(int)), this, SLOT(changeOutputCount(int)));
	connect(ui->closeButton, SIGNAL(pressed()), this, SLOT(closeBtnPressed()));

	//context menu of editor
	contextMenu = new QMenu(this);
    contextMenu->addAction(tr("Cut"), this, SLOT(cutCell()), Qt::CTRL | Qt::Key_X);
    contextMenu->addAction(tr("Copy"), this, SLOT(copyCell()), Qt::CTRL | Qt::Key_C);
    contextMenu->addAction(tr("Paste"), this, SLOT(pasteCell()), Qt::CTRL | Qt::Key_V);
    contextMenu->addAction(tr("Delete"), this, SLOT(deleteCell()), Qt::Key_Delete);
	this->addActions(contextMenu->actions());
}