Skip to content

Commit

Permalink
implemented validation rules for State wizard page
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Aug 14, 2024
1 parent 90b6d21 commit d62cdb0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once
#include "gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h"
#include "gui/pin_model/pin_item.h"


#include <QWizardPage>
Expand All @@ -35,13 +36,19 @@
#include <QLabel>

namespace hal {
class GateLibraryWizard;
class StateWizardPage:public QWizardPage{
friend class GateLibraryWizard;
friend class BoolWizardPage;
public:
Q_OBJECT
StateWizardPage(QWidget* parent = nullptr);
void setData(GateType* gate);

void initializePage() override;
bool isComplete() const override;
private Q_SLOTS:
void handleTextChanged(const QString &text);
void handleNegTextChanged(const QString &text);
private:
QGridLayout* mLayout;

Expand All @@ -50,5 +57,9 @@ namespace hal {

QLabel* mLabStateIdentifier;
QLabel* mLabNegStateIdentifier;

GateLibraryWizard* mWizard;
QList<PinItem*> mPinGroups;
QValidator* mValidator;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace hal
{
friend class RAMPortWizardPage;
friend class PinsWizardPage;
friend class StateWizardPage;
friend class BoolWizardPage;
public:
enum PAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ namespace hal
{
if (QString::fromStdString(it.first) == mName->text())
return false;
int pos=0;
QString name = mName->text();
if(mValidator->validate(name, pos) != QValidator::Acceptable)
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace hal
for(auto ch : mPinModel->getRootItem()->getChildren()) //check pin direction of groups
{
PinItem* pg = static_cast<PinItem*>(ch);
if(pg->getItemType() != PinItem::TreeItemType::GroupCreator) hasPingroup = true;
if(pg->getItemType() == PinItem::TreeItemType::InvalidPinGroup) return false;
if(!pg->getChildren().isEmpty())
{
Expand All @@ -63,6 +64,6 @@ namespace hal
}
}
}
return true;
return hasPingroup;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ namespace hal
mLayout->addWidget(mNegStateIdentifier, 1, 1);

setLayout(mLayout);

connect(mStateIdentifier, &QLineEdit::textChanged, this, &StateWizardPage::handleTextChanged);
connect(mNegStateIdentifier, &QLineEdit::textChanged, this, &StateWizardPage::handleNegTextChanged);

QRegExp rx("[A-Z]([A-Z]|\\d|_)*");
mValidator = new QRegExpValidator(rx, this);
mStateIdentifier->setValidator(mValidator);
mNegStateIdentifier->setValidator(mValidator);
}

void StateWizardPage::initializePage()
{
mWizard = static_cast<GateLibraryWizard*>(wizard());
mPinGroups = mWizard->getPingroups();
}

void StateWizardPage::setData(GateType *gate){
Expand All @@ -36,4 +50,33 @@ namespace hal
}
}
}

void StateWizardPage::handleTextChanged(const QString &text)
{
mNegStateIdentifier->setText(QString("%1N").arg(mStateIdentifier->text()));
Q_UNUSED(text);
Q_EMIT completeChanged();
}

void StateWizardPage::handleNegTextChanged(const QString &text)
{
Q_UNUSED(text);
Q_EMIT completeChanged();
}

bool StateWizardPage::isComplete() const
{
if(mStateIdentifier->text().isEmpty() || mNegStateIdentifier->text().isEmpty()) return false;
for (auto pingroup : mPinGroups) { //check if pins name is used as a state identifier name
QString groupName = pingroup->getName();
if(mStateIdentifier->text() == groupName || mNegStateIdentifier->text() == groupName) return false;
for(auto it : pingroup->getChildren())
{
PinItem* pin = static_cast<PinItem*>(it);
QString pinName = pin->getName();
if(mStateIdentifier->text() == pinName || mNegStateIdentifier->text() == pinName) return false;
}
}
return true;
}
}
26 changes: 11 additions & 15 deletions plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ namespace hal
}
}

/*
void GateLibraryWizard::setData(GateLibrary *gateLibrary, GateType* gateType)
{
mGateLibrary = gateLibrary;
mGateType = gateType;
}
*/

void GateLibraryWizard::accept()
{
//Convert QStringList to std::set
Expand Down Expand Up @@ -265,20 +257,27 @@ namespace hal
case GeneralInfo:
return Pin;
case Pin:
if(properties.contains(GateTypeProperty::ff)) return FlipFlop;
else if(properties.contains(GateTypeProperty::latch)) return Latch;
if(properties.contains(GateTypeProperty::ff) || properties.contains(GateTypeProperty::latch)) return State;
/*if(properties.contains(GateTypeProperty::ff)) return FlipFlop;
else if(properties.contains(GateTypeProperty::latch)) return Latch;*/
else if(properties.contains(GateTypeProperty::c_lut)) return LUT;
else if(properties.contains(GateTypeProperty::ram)) return RAM;
return BoolFunc;
case State:
if(properties.contains(GateTypeProperty::ff)) return FlipFlop;
else if (properties.contains(GateTypeProperty::latch)) return Latch;
else if (properties.contains(GateTypeProperty::c_lut)) return LUT;
else if (properties.contains(GateTypeProperty::ram)) return Init;
return BoolFunc;
case FlipFlop:
if(properties.contains(GateTypeProperty::latch)) return Latch;
else if(properties.contains(GateTypeProperty::c_lut)) return LUT;
else if(properties.contains(GateTypeProperty::ram)) return RAM;
return State;
return BoolFunc;
case Latch:
if(properties.contains(GateTypeProperty::c_lut)) return LUT;
else if(properties.contains(GateTypeProperty::ram)) return RAM;
return State;
return BoolFunc;
case LUT:
if(properties.contains(GateTypeProperty::ram)) return RAM;
return Init;
Expand All @@ -287,9 +286,6 @@ namespace hal
case RAMPort:
if(properties.contains(GateTypeProperty::ff) || properties.contains(GateTypeProperty::latch)) return State;
return Init;
case State:
if(properties.contains(GateTypeProperty::ff) || properties.contains(GateTypeProperty::latch) || properties.contains(GateTypeProperty::c_lut) || properties.contains(GateTypeProperty::ram)) return Init;
return BoolFunc;
case Init:
if(properties.contains(GateTypeProperty::c_lut)) return -1;
return BoolFunc;
Expand Down

0 comments on commit d62cdb0

Please sign in to comment.