Skip to content

Commit

Permalink
[PERFECTIVE] Simplify tabdocument document type.
Browse files Browse the repository at this point in the history
[CORRECTIVE] Fix mock design object for tests.
  • Loading branch information
hagantsa committed Oct 4, 2024
1 parent b846c6f commit 9263846
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 131 deletions.
51 changes: 46 additions & 5 deletions common/widgets/tabDocument/TabDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TabDocument::TabDocument(QWidget* parent, LibraryInterface* libHandler, unsigned
previouslyUnlocked_(false),
relatedVLNVs_(),
refreshRequested_(false),
docType_(DocumentTypes::EMPTY),
docType_(DocumentType::EMPTY),
libHandler_(libHandler)
{
connect(this, SIGNAL(contentChanged()), this, SLOT(setModified()));
Expand Down Expand Up @@ -275,9 +275,9 @@ void TabDocument::updateTabTitle()
{
if (isModified())
{
if (docType_!=DocumentTypes::EMPTY)
if (docType_!=DocumentType::EMPTY)
{
setTabTitle(docName_ + " [" + docType_.ToString() + "]" + "*");
setTabTitle(docName_ + " [" + documentTypetoString(docType_) + "]" + "*");
}
else
{
Expand All @@ -286,9 +286,9 @@ void TabDocument::updateTabTitle()
}
else
{
if (docType_ != DocumentTypes::EMPTY)
if (docType_ != DocumentType::EMPTY)
{
setTabTitle(docName_ + " [" + docType_.ToString() + "]");
setTabTitle(docName_ + " [" + documentTypetoString(docType_) + "]");
}
else
{
Expand Down Expand Up @@ -402,6 +402,47 @@ bool TabDocument::fileExists()
return libHandler_->getModel<Document>(getIdentifyingVLNV())!=nullptr;
}

//-----------------------------------------------------------------------------
// Function: TabDocument::documentTypetoString()
//-----------------------------------------------------------------------------
QString TabDocument::documentTypetoString(DocumentType documentType)
{
switch (documentType)
{
case DocumentType::ABSTRACTION_DEFINITION:
return QStringLiteral("Abstraction Definition");
case DocumentType::API_DEFINITION:
return QStringLiteral("API Definition");
case DocumentType::BUS_DEFINITION:
return QStringLiteral("Bus Definition");
case DocumentType::CATALOG:
return QStringLiteral("Catalog");
case DocumentType::COM_DEFINITION:
return QStringLiteral("COM Definition");
case DocumentType::HW_COMPONENT:
return QStringLiteral("HW Component");
case DocumentType::SW_COMPONENT:
return QStringLiteral("SW Component");
case DocumentType::UNMAPPED_SYSTEM:
return QStringLiteral("Unmapped System");
case DocumentType::CODE:
return QStringLiteral("Code");
case DocumentType::HW_DESIGN:
return QStringLiteral("HW Design");
case DocumentType::MEMORY_DESIGN:
return QStringLiteral("Memory Design");
case DocumentType::SW_DESIGN:
return QStringLiteral("SW Design");
case DocumentType::SYSTEM_DESIGN:
return QStringLiteral("System Design");
case DocumentType::EMPTY:
return QStringLiteral("");
default:
Q_ASSERT(false); //please handle ToString conversion for every new document type you add.
return QStringLiteral("");
}
}

//-----------------------------------------------------------------------------
// Function: TabDocument::addRelatedVLNV()
//-----------------------------------------------------------------------------
Expand Down
83 changes: 7 additions & 76 deletions common/widgets/tabDocument/TabDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class TabDocument : public QWidget
};

//-----------------------------------------------------------------------------
//! DocumentTypes enumeration.
//! DocumentType enumeration.
//-----------------------------------------------------------------------------
enum DocumentTypes {
enum class DocumentType {
ABSTRACTION_DEFINITION,
API_DEFINITION,
BUS_DEFINITION,
Expand All @@ -83,80 +83,6 @@ class TabDocument : public QWidget
EMPTY
};

//-----------------------------------------------------------------------------
//! DocumentType struct.
//-----------------------------------------------------------------------------
struct DocumentType
{
/*!
* Constructor.
*
* @param [in] type Type of the document.
*/
DocumentType(DocumentTypes type) {
this->type = type;
}

DocumentTypes type; //! Type of the document.

/*
* Comparison operator for DocumentType.
*/
bool operator==(const DocumentType& other) const
{
return this->type == other.type;
}

/*
* Inequality operator for DocumentType.
*/
bool operator!=(const DocumentType& other) const
{
return this->type != other.type;
}

/*!
* Returns a string representation of the DocumentType.
*/
QString ToString()
{
switch (type)
{
case ABSTRACTION_DEFINITION:
return QStringLiteral("Abstraction Definition");
case API_DEFINITION:
return QStringLiteral("API Definition");
case BUS_DEFINITION:
return QStringLiteral("Bus Definition");
case CATALOG:
return QStringLiteral("Catalog");
case COM_DEFINITION:
return QStringLiteral("COM Definition");
case HW_COMPONENT:
return QStringLiteral("HW Component");
case SW_COMPONENT:
return QStringLiteral("SW Component");
case UNMAPPED_SYSTEM:
return QStringLiteral("Unmapped System");
case CODE:
return QStringLiteral("Code");
case HW_DESIGN:
return QStringLiteral("HW Design");
case MEMORY_DESIGN:
return QStringLiteral("Memory Design");
case SW_DESIGN:
return QStringLiteral("SW Design");
case SYSTEM_DESIGN:
return QStringLiteral("System Design");
case EMPTY:
return QStringLiteral("");
default:
Q_ASSERT(false); //please handle ToString conversion for every new document type you add.
return QStringLiteral("");
}
}
};

/*!
* Constructor.
*
Expand Down Expand Up @@ -352,6 +278,11 @@ class TabDocument : public QWidget
*/
bool fileExists();

/*!
* Returns a string representation of the DocumentType.
*/
static QString documentTypetoString(DocumentType documentType);

public slots:

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ referenceCounter_(new AbsDefParameterReferenceCounter(absDefParameterFinder_, ab
parameterReferenceTree_(new AbsDefParameterReferenceTree(absDef, referenceCounter_, expressionFormatter_)),
referenceTreeWindow_(new ParameterReferenceTreeWindow(parameterReferenceTree_))
{
setDocumentType(DocumentType(DocumentTypes::ABSTRACTION_DEFINITION));
setDocumentType(DocumentType::ABSTRACTION_DEFINITION);

if (absDef_)
{
Expand Down
2 changes: 1 addition & 1 deletion editors/ApiDefinitionEditor/ApiDefinitionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ApiDefinitionEditor::ApiDefinitionEditor(QWidget *parent, LibraryInterface* libH
// Set the document name and type.
VLNV vlnv = apiDef_->getVlnv();
setDocumentName(vlnv.getName() + " (" + vlnv.getVersion() + ")");
setDocumentType(DocumentType(DocumentTypes::API_DEFINITION));
setDocumentType(DocumentType::API_DEFINITION);

// Open in unlocked mode by default only if the version is draft.
setProtection(vlnv.getVersion() != "draft");
Expand Down
2 changes: 1 addition & 1 deletion editors/BusDefinitionEditor/BusDefinitionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ parameterReferenceTree_(new BusDefinitionParameterReferenceTree(busDef, expressi
referenceTreeWindow_(new ParameterReferenceTreeWindow(parameterReferenceTree_, this)),
busDefGroup_(libHandler, expressionFormatter_, busDefParameterFinder_, this)
{
setDocumentType(DocumentType(DocumentTypes::BUS_DEFINITION));
setDocumentType(DocumentType::BUS_DEFINITION);

if (busDef_)
{
Expand Down
2 changes: 1 addition & 1 deletion editors/CSourceEditor/CSourceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TabDocument(parent, libHandler, DOC_PRINT_SUPPORT | DOC_EDIT_SUPPORT),
readFileContentFromDisk();

setDocumentName(QFileInfo(sourceFile).fileName());
setDocumentType(DocumentType(DocumentTypes::CODE));
setDocumentType(DocumentType::CODE);

connect(textEdit_->document(), SIGNAL(contentsChanged()),
this, SIGNAL(contentChanged()), Qt::UniqueConnection);
Expand Down
2 changes: 1 addition & 1 deletion editors/CatalogEditor/CatalogEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TabDocument(parent, libHandler, DOC_PROTECTION_SUPPORT),
// Set the document name and type.
VLNV vlnv = catalog_->getVlnv();
setDocumentName(vlnv.getName() + " (" + vlnv.getVersion() + ")");
setDocumentType(DocumentType(DocumentTypes::CATALOG));
setDocumentType(DocumentType::CATALOG);

documentNameGroupEditor_->setDocumentNameGroup(catalog_, libHandler->getPath(vlnv));
documentNameGroupEditor_->setTitle(tr("Catalog"));
Expand Down
2 changes: 1 addition & 1 deletion editors/ComDefinitionEditor/ComDefinitionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TabDocument(parent, libHandler, DOC_PROTECTION_SUPPORT),
// Set the document name and type.
VLNV const vlnv = comDef_->getVlnv();
setDocumentName(vlnv.getName() + " (" + vlnv.getVersion() + ")");
setDocumentType(DocumentType(DocumentTypes::COM_DEFINITION));
setDocumentType(DocumentType::COM_DEFINITION);

// Open in unlocked mode by default only if the version is draft.
setProtection(vlnv.getVersion() != "draft");
Expand Down
6 changes: 3 additions & 3 deletions editors/ComponentEditor/componenteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ validator_(new ComponentValidator(expressionParser_, modeConditionParserInterfac

if (component_->getImplementation() == KactusAttribute::HW)
{
setDocumentType(DocumentType(DocumentTypes::HW_COMPONENT));
setDocumentType(DocumentType::HW_COMPONENT);
}
else if (component_->getImplementation() == KactusAttribute::SW)
{
setDocumentType(DocumentType(DocumentTypes::SW_COMPONENT));
setDocumentType(DocumentType::SW_COMPONENT);
}
else if (component_->getImplementation() == KactusAttribute::SYSTEM)
{
setDocumentType(DocumentType(DocumentTypes::UNMAPPED_SYSTEM));
setDocumentType(DocumentType::UNMAPPED_SYSTEM);
}

addRelatedVLNV(component_->getVlnv());
Expand Down
2 changes: 1 addition & 1 deletion editors/HWDesign/HWDesignWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool HWDesignWidget::setDesign(VLNV const& vlnv, QString const& viewName)

setModified(false);

setDocumentType(DocumentType(DocumentTypes::HW_DESIGN));
setDocumentType(DocumentType::HW_DESIGN);
setDocumentName(QString("%1 (%2)").arg(getIdentifyingVLNV().getName()).arg(getIdentifyingVLNV().getVersion()));

emit clearItemSelection();
Expand Down
2 changes: 1 addition & 1 deletion editors/MemoryDesigner/MemoryDesignDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool MemoryDesignDocument::setDesign(VLNV const& componentVLNV, QString const& v
setDocumentName(QString("%1 (%2)").
arg(getIdentifyingVLNV().getName()).
arg(getIdentifyingVLNV().getVersion()));
setDocumentType(DocumentType(DocumentTypes::MEMORY_DESIGN));
setDocumentType(DocumentType::MEMORY_DESIGN);

QSharedPointer<const Document> libraryDocument = getLibHandler()->getModelReadOnly(componentVLNV);
QSharedPointer<const Component> component = libraryDocument.dynamicCast<const Component>();
Expand Down
4 changes: 2 additions & 2 deletions editors/SystemDesign/SystemDesignWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ bool SystemDesignWidget::setDesign(VLNV const& vlnv, QString const& viewName)
setDocumentName(QString("%1 (%2)").arg(getIdentifyingVLNV().getName()).arg(getIdentifyingVLNV().getVersion()));
if (onlySW_)
{
setDocumentType(DocumentType(DocumentTypes::SW_DESIGN));
setDocumentType(DocumentType::SW_DESIGN);
}
else
{
setDocumentType(DocumentType(DocumentTypes::SYSTEM_DESIGN));
setDocumentType(DocumentType::SYSTEM_DESIGN);
}

// Open in unlocked mode by default only if the version is draft.
Expand Down
18 changes: 9 additions & 9 deletions mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ void MainWindow::createApiDefinition(VLNV const& vlnv, Document::Revision revisi
//-----------------------------------------------------------------------------
void MainWindow::openBus(const VLNV& busDefVLNV)
{
if (isOpen(busDefVLNV, TabDocument::DocumentType(TabDocument::DocumentTypes::BUS_DEFINITION)) || !busDefVLNV.isValid())
if (isOpen(busDefVLNV, TabDocument::DocumentType::BUS_DEFINITION) || !busDefVLNV.isValid())
{
return;
}
Expand Down Expand Up @@ -2372,7 +2372,7 @@ void MainWindow::openBus(const VLNV& busDefVLNV)
//-----------------------------------------------------------------------------
void MainWindow::openAbsDef(const VLNV& absDefVLNV)
{
if (isOpen(absDefVLNV, TabDocument::DocumentType(TabDocument::DocumentTypes::ABSTRACTION_DEFINITION)) || !absDefVLNV.isValid())
if (isOpen(absDefVLNV, TabDocument::DocumentType::ABSTRACTION_DEFINITION) || !absDefVLNV.isValid())
{
return;
}
Expand Down Expand Up @@ -2417,7 +2417,7 @@ void MainWindow::openAbsDef(const VLNV& absDefVLNV)
//-----------------------------------------------------------------------------
void MainWindow::openCatalog(const VLNV& vlnv)
{
if (isOpen(vlnv, TabDocument::DocumentType(TabDocument::DocumentTypes::CATALOG)))
if (isOpen(vlnv, TabDocument::DocumentType::CATALOG))
{
return;
}
Expand Down Expand Up @@ -2465,7 +2465,7 @@ void MainWindow::openHWDesign(VLNV const& vlnv, QString const& viewName)
// Check if the design is already open.
VLNV refVLNV = comp->getHierRef(viewName);
VLNV designVLNV = libraryHandler_->getDesignVLNV(refVLNV);
if (isOpen(designVLNV, TabDocument::DocumentType(TabDocument::DocumentTypes::HW_DESIGN)) || hasInvalidReferences(comp->getHierRefs(), vlnv))
if (isOpen(designVLNV, TabDocument::DocumentType::HW_DESIGN) || hasInvalidReferences(comp->getHierRefs(), vlnv))
{
return;
}
Expand Down Expand Up @@ -2543,7 +2543,7 @@ void MainWindow::openMemoryDesign(VLNV const& vlnv, QString const& viewName)
QSharedPointer<Component> comp = libraryHandler_->getModel(vlnv).staticCast<Component>();

// check if the design is already open
if (isOpen(vlnv, TabDocument::DocumentType(TabDocument::DocumentTypes::MEMORY_DESIGN)))
if (isOpen(vlnv, TabDocument::DocumentType::MEMORY_DESIGN))
{
return;
}
Expand Down Expand Up @@ -2620,7 +2620,7 @@ void MainWindow::openSWDesign(const VLNV& vlnv, QString const& viewName)
// check if the design is already open
VLNV refVLNV = comp->getHierRef(viewName);
VLNV designVLNV = libraryHandler_->getDesignVLNV(refVLNV);
if (isOpen(designVLNV, TabDocument::DocumentType(TabDocument::DocumentTypes::SW_DESIGN)))
if (isOpen(designVLNV, TabDocument::DocumentType::SW_DESIGN))
{
return;
}
Expand Down Expand Up @@ -2683,7 +2683,7 @@ void MainWindow::openSystemDesign(VLNV const& vlnv, QString const& viewName)
// check if the design is already open
VLNV refVLNV = comp->getHierSystemRef(viewName);
VLNV designVLNV = libraryHandler_->getDesignVLNV(refVLNV);
if (isOpen(designVLNV, TabDocument::DocumentType(TabDocument::DocumentTypes::SYSTEM_DESIGN)))
if (isOpen(designVLNV, TabDocument::DocumentType::SYSTEM_DESIGN))
{
return;
}
Expand Down Expand Up @@ -2802,7 +2802,7 @@ void MainWindow::openComponent(VLNV const& vlnv)
//-----------------------------------------------------------------------------
void MainWindow::openComDefinition(VLNV const& vlnv)
{
if (isOpen(vlnv, TabDocument::DocumentType(TabDocument::DocumentTypes::COM_DEFINITION)))
if (isOpen(vlnv, TabDocument::DocumentType::COM_DEFINITION))
{
return;
}
Expand Down Expand Up @@ -2837,7 +2837,7 @@ void MainWindow::openComDefinition(VLNV const& vlnv)
//-----------------------------------------------------------------------------
void MainWindow::openApiDefinition(VLNV const& vlnv)
{
if (isOpen(vlnv, TabDocument::DocumentType(TabDocument::DocumentTypes::API_DEFINITION)))
if (isOpen(vlnv, TabDocument::DocumentType::API_DEFINITION))
{
return;
}
Expand Down
Loading

0 comments on commit 9263846

Please sign in to comment.