void CubeWidget::updateData() { if (m_active) { Formula *formula = m_gm->getFormula(); if (!formula || formula->getVarsCount() > CubeGLDrawer::MAX_N) invalidateData(); else { m_stack->setCurrentIndex(0); m_termsModel->setFormula(formula); m_termsView->resizeRowsToContents(); m_termsView->setColumnWidth(0, m_termsView->width()); enableCovers(m_coversCheckBox->isChecked()); #if CUBE_TEXTURES m_tourBtn->setEnabled(true); #endif if (formula->getVarsCount() != m_varsCount) { m_varsCount = formula->getVarsCount(); deselectAll(m_termsView, m_termsModel); m_cube->deselectTerms(); } } } }
CreatorDialog::CreatorDialog(bool edit, QWidget *parent) : QDialog(parent) { setWindowTitle(edit? tr("Edit logic function..."): tr("New logic function...")); m_gm = GUIManager::instance(); Formula *formula = (edit? new Formula(*m_gm->getFormula()): 0); if (formula) m_name = formula->getName(); else m_name = Formula::DEFAULT_NAME; m_nameLine = new QLineEdit(QString(m_name)); m_nameLine->setMinimumWidth(20); m_nameLine->setMaximumWidth(40); m_nameLine->setAlignment(Qt::AlignRight); connect(m_nameLine, SIGNAL(editingFinished()), this, SLOT(setName())); QLabel *nameLabel = new QLabel(tr("Function &name: ")); nameLabel->setBuddy(m_nameLine); QHBoxLayout *nameLayout = new QHBoxLayout; nameLayout->addWidget(nameLabel); nameLayout->addWidget(m_nameLine); m_repreCombo = new QComboBox; m_repreCombo->insertItem(SOP_IDX, tr("Sum of Products")); m_repreCombo->insertItem(POS_IDX, tr("Product of Sums")); if ((formula && formula->getRepre() == Formula::REP_SOP) || m_gm->isSoP()) { setRepre(Formula::REP_SOP); m_repreCombo->setCurrentIndex(SOP_IDX); } else { setRepre(Formula::REP_POS); m_repreCombo->setCurrentIndex(POS_IDX); } connect(m_repreCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setRepre(int))); QLabel *repreLabel = new QLabel(tr("&Representation: ")); repreLabel->setBuddy(m_repreCombo); QHBoxLayout *repreLayout = new QHBoxLayout; repreLayout->addWidget(repreLabel); repreLayout->addWidget(m_repreCombo); m_vcCombo = new QComboBox; m_vcCombo->setMinimumWidth(30); m_vcCombo->addItem(QString()); for (unsigned i = 1; i <= Formula::MAX_VARS; i++) m_vcCombo->addItem(QString::number(i)); connect(m_vcCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setVarsCount(int))); QLabel *vcLabel = new QLabel(tr("Variables &count: ")); vcLabel->setBuddy(m_vcCombo); QHBoxLayout *vcLayout = new QHBoxLayout; vcLayout->addWidget(vcLabel); vcLayout->addWidget(m_vcCombo); m_varsLine = new QLineEdit; connect(m_varsLine, SIGNAL(editingFinished()), this, SLOT(setVars())); QLabel *varsLabel = new QLabel(tr("&Variables: ")); varsLabel->setBuddy(m_varsLine); QHBoxLayout *varsLayout = new QHBoxLayout; varsLayout->addWidget(varsLabel); varsLayout->addWidget(m_varsLine); m_ttModel = new TruthTableModel; m_ttView = new TruthTableView; m_ttView->setModel(m_ttModel); m_ttView->setItemDelegate(new TruthTableDelegate); m_ttView->setMinimumSize(400, 300); m_ttView->setMaximumSize(500, 400); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QGridLayout *mainLayout = new QGridLayout; mainLayout->setVerticalSpacing(5); mainLayout->setHorizontalSpacing(40); mainLayout->addLayout(nameLayout, 0, 0); mainLayout->addLayout(repreLayout, 0, 1); mainLayout->addLayout(vcLayout, 1, 0); mainLayout->addLayout(varsLayout, 1, 1); mainLayout->addWidget(m_ttView, 2, 0, 1, 2); mainLayout->addWidget(buttonBox, 3, 0, 1, 2); setLayout(mainLayout); if (formula) { m_gm->setNewFormula(formula); m_vcCombo->setCurrentIndex((m_varsCount = formula->getVarsCount())); m_vars = formula->getVars(); printVars(); m_ttModel->setFormula(formula); m_ttView->resizeColumnsToContents(); } }