Kactus2
Kactus2 reference guide
Loading...
Searching...
No Matches
LibraryHandler.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// File: libraryhandler.h
3//-----------------------------------------------------------------------------
4// Project: Kactus 2
5// Author: Antti Kamppi
6// Date: 20.12.2010
7//
8// Description:
9// LibraryHandler is the class that implements the services to manage the IP-XACT library.
10//-----------------------------------------------------------------------------
11
12#ifndef LIBRARYHANDLER_H
13#define LIBRARYHANDLER_H
14
15#include "LibraryInterface.h"
16#include "LibraryLoader.h"
17#include "LibraryTreeModel.h"
18#include "hierarchymodel.h"
19
20#include "NullChannel.h"
21#include "utils.h"
22
23#include "DocumentFileAccess.h"
24#include "DocumentValidator.h"
25
26#include <IPXACTmodels/common/Document.h>
27#include <IPXACTmodels/common/TagData.h>
28
29#include <IPXACTmodels/kactusExtensions/KactusAttribute.h>
30
31#include <KactusAPI/KactusAPIGlobal.h>
32
33#include <QString>
34#include <QStringList>
35#include <QList>
36#include <QSharedPointer>
37#include <QObject>
38
39class LibraryItem;
40class MessageMediator;
41
42//-----------------------------------------------------------------------------
44//-----------------------------------------------------------------------------
45class KACTUS2_API LibraryHandler : public QObject, public LibraryInterface
46{
47 Q_OBJECT
48
49public:
50
53
55 LibraryHandler(const LibraryHandler &other) = delete;
56
58 LibraryHandler& operator=(const LibraryHandler& other) = delete;
59
61 ~LibraryHandler() final = default;
62
63 void setOutputChannel(MessageMediator* messageChannel);
64
73 QSharedPointer<Document> getModel(VLNV const& vlnv) final;
74
83 QSharedPointer<Document const> getModelReadOnly(VLNV const& vlnv) final;
84
89 QList<VLNV> getAllVLNVs() const final;
90
97 bool contains(VLNV const& vlnv) const final;
98
105 const QString getPath(VLNV const& vlnv) const final;
106
113 QString getDirectoryPath(VLNV const& vlnv) const final;
114
129 bool writeModelToFile(QString const& path, QSharedPointer<Document> model) final;
130
142 bool writeModelToFile(QSharedPointer<Document> model) final;
143
146
159 void getNeededVLNVs(VLNV const& vlnv, QList<VLNV>& list) final;
160
170 void getDependencyFiles(VLNV const& vlnv, QStringList& list) final;
171
176 LibraryItem const* getTreeRoot() const final;
177
186 VLNV::IPXactType getDocumentType(VLNV const& vlnv) final;
187
194 int referenceCount(VLNV const& vlnv) const final;
195
203 int getOwners(QList<VLNV>& list, VLNV const& vlnvToSearch) const final;
204
212 int getChildren(QList<VLNV>& list, VLNV const& vlnvToSearch) const final;
213
227 VLNV getDesignVLNV(VLNV const& hierarchyRef) final;
228
242 QSharedPointer<Design> getDesign(VLNV const& hierarchyRef) final;
243
250 bool isValid(VLNV const& vlnv) final;
251
253
255
264 QVector<QString> findErrorsInDocument(QSharedPointer<Document> document, QString const& path);
265
266public slots:
267
274
280 void onEditItem(VLNV const& vlnv) final;
281
288 void onOpenDesign(VLNV const& vlnv, QString const& viewName) final;
289
296 void onOpenMemoryDesign(VLNV const& vlnv, QString const& activeView);
297
303 void onOpenSWDesign(VLNV const& vlnv);
304
311 void onOpenSystemDesign(VLNV const& vlnv, QString const& activeView);
312
313
322 void removeObject(VLNV const& vlnv) final;
323
331 void removeObjects(const QList<VLNV>& vlnvList) final;
332
341 void beginSave();
342
347 void endSave();
348
349signals:
350
351
353
355 void openDesign(VLNV const& vlnv, const QString& viewName);
356
358 void openMemoryDesign(VLNV const& vlnv, const QString& viewName);
359
361 void openSWDesign(VLNV const& vlnv, QString const& viewName);
362
364 void openSystemDesign(VLNV const& vlnv, QString const& viewName);
365
367 void openBus(VLNV const& busDefVLNV);
368
370 void openAbsDef(VLNV const& absDefVLNV);
371
373 void openComponent(VLNV const& vlnv);
374
376 void openCatalog(VLNV const& vlnv);
377
379 void openComDefinition(VLNV const& vlnv);
380
382 void openApiDefinition(VLNV const& vlnv);
383
385 void itemSelected(VLNV const& vlnv);
386
388 void openPlatformComponent(VLNV const& vlnv);
389
391 void updatedVLNV(VLNV const& vlnv);
392
394 void addVLNV(VLNV const& vlnv);
395
397 void removeVLNV(VLNV const& vlnv);
398
401
402private slots:
403
413 void onItemSaved(VLNV const& vlnv);
414
415private:
416
418 struct DocumentInfo
419 {
420 QSharedPointer<Document> document; //<! The model for the document.
421 QString path; //<! The path to the file containing the document.
422 bool isValid; //<! Flag for well-formed content.
423
425 explicit DocumentInfo(QString const& filePath = QString(),
426 QSharedPointer<Document> doc = QSharedPointer<Document>(),
427 bool valid = false): document(doc), path(filePath), isValid(valid) {}
428 };
429
431 struct DocumentStatistics
432 {
433 int fileCount = 0;
434 int documentCount = 0;
435 };
436
437 //-----------------------------------------------------------------------------
438 // The private functions used by public class methods
439 //-----------------------------------------------------------------------------
440
446 LibraryHandler();
447
448
450 void syncronizeModels();
451
453 void showNotFoundError(VLNV const& vlnv) const;
454
456 bool addObject(QSharedPointer<Document> model, QString const& filePath);
457
459 void clearCache();
460
462 void loadAvailableVLNVs();
463
465 void resetModels();
466
468 void showIntegrityResults() const;
469
477 bool removeFile(QString const& filePath) const;
478
487 bool validateDocument(QSharedPointer<Document> document, QString const& documentPath);
488
489
496 bool validateDependentVLNVReferencences(QSharedPointer<Document> document);
497
504 void findErrorsInDependentVLNVReferencences(QSharedPointer<const Document> document, QVector<QString>& errorList);
505
514 bool validateDependentDirectories(QSharedPointer<Document> document, QString const& documentPath);
515
523 void findErrorsInDependentDirectories(QSharedPointer<const Document> document, QString const& documentPath,
524 QVector<QString>& errorList);
525
532 bool validateDependentFiles(QSharedPointer<Document> document, QString const& documentPath);
533
541 void findErrorsInDependentFiles(QSharedPointer<const Document> document, QString const& documentPath,
542 QVector<QString>& errorList);
543
544 //-----------------------------------------------------------------------------
545 // Data.
546 //-----------------------------------------------------------------------------
547
548
550 NullChannel defaultChannel;
551
553 MessageMediator* messageChannel_{ &defaultChannel };
554
556 LibraryLoader loader_{ };
557
563 QMap<VLNV, DocumentInfo> documentCache_;
564
566 QRegularExpressionValidator urlTester_{ Utils::URL_VALIDITY_REG_EXP, this };
567
569 DocumentValidator validator_{ this };
570
572 LibraryTreeModel treeModel_{ this, this };
573
575 HierarchyModel hierarchyModel_{ this, this };
576
578 bool saveInProgress_{ false };
579
581 DocumentStatistics checkResults_;
582
583};
584
585#endif // LIBRARYHANDLER_H
Contains the items to display the library component hierarchy to user.
void openComDefinition(VLNV const &vlnv)
Signal that user wants to open specified COM definition for editing.
static LibraryHandler & getInstance()
The the instance of the library.
void removeObjects(const QList< VLNV > &vlnvList) final
void updatedVLNV(VLNV const &vlnv)
Inform that object has been updated.
HierarchyModel * getHierarchyModel()
void onOpenDesign(VLNV const &vlnv, QString const &viewName) final
VLNV getDesignVLNV(VLNV const &hierarchyRef) final
void searchForIPXactFiles() final
Search for IP-Xact files in the file system and add them to library.
void openCatalog(VLNV const &vlnv)
Signal that user wants to open specified catalog for editing.
void removeObject(VLNV const &vlnv) final
const QString getPath(VLNV const &vlnv) const final
LibraryHandler(const LibraryHandler &other)=delete
No copying.
void progressStatus()
void openComponent(VLNV const &vlnv)
Signal that user wants to open specified component for editing.
void openDesign(VLNV const &vlnv, const QString &viewName)
Signal that user wants to open the specified component for editing.
LibraryItem const * getTreeRoot() const final
QVector< QString > findErrorsInDocument(QSharedPointer< Document > document, QString const &path)
void openAbsDef(VLNV const &absDefVLNV)
Signal that user wants to open specified abstraction for editing.
void removeVLNV(VLNV const &vlnv)
Inform tree model that a vlnv is to be removed from the tree.
bool writeModelToFile(QString const &path, QSharedPointer< Document > model) final
QSharedPointer< Document > getModel(VLNV const &vlnv) final
void getDependencyFiles(VLNV const &vlnv, QStringList &list) final
LibraryTreeModel * getTreeModel()
void onEditItem(VLNV const &vlnv) final
void openSystemDesign(VLNV const &vlnv, QString const &viewName)
Signal that user wants to open a system for editing.
QSharedPointer< Design > getDesign(VLNV const &hierarchyRef) final
void addVLNV(VLNV const &vlnv)
Inform tree model that a vlnv is to be added to the tree.
void onOpenSystemDesign(VLNV const &vlnv, QString const &activeView)
void setOutputChannel(MessageMediator *messageChannel)
LibraryHandler & operator=(const LibraryHandler &other)=delete
No assignment.
void openPlatformComponent(VLNV const &vlnv)
Signal that user wants to open a platform component.
void onOpenMemoryDesign(VLNV const &vlnv, QString const &activeView)
void getNeededVLNVs(VLNV const &vlnv, QList< VLNV > &list) final
bool contains(VLNV const &vlnv) const final
int referenceCount(VLNV const &vlnv) const final
void openBus(VLNV const &busDefVLNV)
Signal that user wants to open specified bus for editing.
void openApiDefinition(VLNV const &vlnv)
Signal that user wants to open specified API definition for editing.
QString getDirectoryPath(VLNV const &vlnv) const final
void onOpenSWDesign(VLNV const &vlnv)
void onCheckLibraryIntegrity() final
int getOwners(QList< VLNV > &list, VLNV const &vlnvToSearch) const final
int getChildren(QList< VLNV > &list, VLNV const &vlnvToSearch) const final
void openMemoryDesign(VLNV const &vlnv, const QString &viewName)
Signal that user wants to open the memory design of the specified component for editing.
~LibraryHandler() final=default
The destructor.
bool isValid(VLNV const &vlnv) final
void openSWDesign(VLNV const &vlnv, QString const &viewName)
Signal that user wants to open the specified software design for editing.
VLNV::IPXactType getDocumentType(VLNV const &vlnv) final
QSharedPointer< Document const > getModelReadOnly(VLNV const &vlnv) final
void resetModel()
Inform both models that the content must be reset.
void itemSelected(VLNV const &vlnv)
Signal that the library item specified by vlnv is selected in one of the views.
QList< VLNV > getAllVLNVs() const final
LibraryInterface defines an interface to operate the IP-XACT-library.
virtual bool isValid(VLNV const &vlnv)=0
LibraryItem class is used to create the hierarchical structure of IP library.
Definition LibraryItem.h:27
The model that contains the LibraryItems to display library hierarchically.
Interface for outputting messages to the user.
const QRegularExpression URL_VALIDITY_REG_EXP("^[a-z]{3,9}[:][/]{2}[a-z0-9]+([-.][a-z0-9]+)*([/][-a-z0-9_.;,?=&%#~+]*)*$", QRegularExpression::CaseInsensitiveOption)
Regular expression to validate URLs.