Skip to content

Commit

Permalink
implemented validation rules for General Information wizard page and …
Browse files Browse the repository at this point in the history
…Pins wizard page
  • Loading branch information
neoneela committed Aug 11, 2024
1 parent e4e604c commit 90b6d21
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace hal {

const GateLibrary* mGateLibrary;
QString mNameInit;
QValidator* mValidator;

QString mDisabledIconStyle;
QString mEnabledIconStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ namespace hal {
PinsWizardPage(QWidget* parent = nullptr);
void setGateType(GateType* gate);
void initializePage() override;
bool validatePage() override;
bool isComplete() const override;
QList<PinItem*> getPingroups();

public Q_SLOTS:
void handleDeleteClicked();
void handlePinModelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
private:
GateLibraryWizard* mWizard;
PinModel* mPinModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ namespace hal
connect(mDelBtn, &QPushButton::clicked, this, &GeneralInfoWizardPage::deleteProperty);
connect(mName, &QLineEdit::textChanged, this, &GeneralInfoWizardPage::handleNameChanged);


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

void GeneralInfoWizardPage::setData(QString name, const std::vector<GateTypeProperty>& properties)
Expand Down Expand Up @@ -177,10 +179,15 @@ namespace hal
if (getProperties().isEmpty() || mName->text().isEmpty()) return false;

if (mName->text() == mNameInit) return true; // name of existing type unchanged

for (auto it : mGateLibrary->get_gate_types())
{
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 @@ -13,20 +13,18 @@ namespace hal

mPinTab = new GateLibraryTabPin(this, true);
mDelBtn = new QPushButton("Delete", this);

mPinModel = mPinTab->getPinModel();

layout->addWidget(mDelBtn, 1, 0);
layout->addWidget(mPinTab, 0, 0, 1, 2);

connect(mDelBtn, &QPushButton::clicked, this, &PinsWizardPage::handleDeleteClicked);

connect(mPinModel, &PinModel::dataChanged, this, &PinsWizardPage::handlePinModelChanged);
}

void PinsWizardPage::initializePage()
{

mWizard = static_cast<GateLibraryWizard*>(wizard());
mPinModel = mPinTab->getPinModel();
mWizard->mPinModel = mPinModel;

mPinTab->update(mWizard->mGateType);
Expand All @@ -35,21 +33,35 @@ namespace hal
void PinsWizardPage::handleDeleteClicked()
{
auto treeView = mPinTab->getTreeView();
auto pinModel = mPinTab->getPinModel();

pinModel->handleDeleteItem(treeView->currentIndex());
mPinModel->handleDeleteItem(treeView->currentIndex());
Q_EMIT completeChanged();
}

QList<PinItem*> PinsWizardPage::getPingroups(){
return mPinModel->getPinGroups();
}

bool PinsWizardPage::validatePage()
void PinsWizardPage::handlePinModelChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_EMIT completeChanged();
}

bool PinsWizardPage::isComplete() const
{
if(mPinModel->getRootItem()->getChildren().isEmpty()) return false;
bool hasPingroup = false;
for(auto ch : mPinModel->getRootItem()->getChildren()) //check pin direction of groups
{
PinItem* pg = static_cast<PinItem*>(ch);
if(pg->getItemType() != PinItem::TreeItemType::GroupCreator && pg->getDirection() == PinDirection::none) return false;
if(pg->getItemType() == PinItem::TreeItemType::InvalidPinGroup) return false;
if(!pg->getChildren().isEmpty())
{
for (auto it : pg->getChildren()) {
PinItem* p = static_cast<PinItem*>(it);
if(pg->getItemType() == PinItem::TreeItemType::InvalidPin) return false;
}
}
}
return true;
}
Expand Down
14 changes: 13 additions & 1 deletion plugins/gui/src/pin_model/pin_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,14 @@ namespace hal
bool PinModel::renamePin(PinItem* pinItem, const QString& newName)
{
//TODO change pinItems name within function and not after its call
//Check if name is already in use

QString name = newName;
QRegExp rx("[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*");
QValidator* val = new QRegExpValidator(rx, this);
int pos = 0;
if(val->validate(name, pos) != QValidator::Acceptable) return false;

//Check if name is already in use
if(isNameAvailable(newName, pinItem)){
//delete old name from being assigned and add new name
mAssignedPinNames.remove(pinItem->getName());
Expand Down Expand Up @@ -424,6 +430,12 @@ namespace hal
bool PinModel::renamePinGroup(PinItem* groupItem, const QString& newName)
{
//TODO change pinItems name within function and not after its call

QString name = newName;
QRegExp rx("[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*");
QValidator* val = new QRegExpValidator(rx, this);
int pos = 0;
if(val->validate(name, pos) != QValidator::Acceptable) return false;
//Check if name is already in use
if(isNameAvailable(newName, groupItem)){
//delete old name from being assigned and add new name
Expand Down

0 comments on commit 90b6d21

Please sign in to comment.