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
310 void onOpenSystemDesign(VLNV const& vlnv);
311
312
321 void removeObject(VLNV const& vlnv) final;
322
330 void removeObjects(const QList<VLNV>& vlnvList) final;
331
340 void beginSave();
341
346 void endSave();
347
348signals:
349
350
352
354 void openDesign(VLNV const& vlnv, const QString& viewName);
355
357 void openMemoryDesign(VLNV const& vlnv, const QString& viewName);
358
360 void openSWDesign(VLNV const& vlnv, QString const& viewName);
361
363 void openSystemDesign(VLNV const& vlnv, QString const& viewName);
364
366 void openBus(VLNV const& busDefVLNV);
367
369 void openAbsDef(VLNV const& absDefVLNV);
370
372 void openComponent(VLNV const& vlnv);
373
375 void openCatalog(VLNV const& vlnv);
376
378 void openComDefinition(VLNV const& vlnv);
379
381 void openApiDefinition(VLNV const& vlnv);
382
384 void itemSelected(VLNV const& vlnv);
385
387 void openPlatformComponent(VLNV const& vlnv);
388
390 void updatedVLNV(VLNV const& vlnv);
391
393 void addVLNV(VLNV const& vlnv);
394
396 void removeVLNV(VLNV const& vlnv);
397
400
401private slots:
402
412 void onItemSaved(VLNV const& vlnv);
413
414private:
415
417 struct DocumentInfo
418 {
419 QSharedPointer<Document> document; //<! The model for the document.
420 QString path; //<! The path to the file containing the document.
421 bool isValid; //<! Flag for well-formed content.
422
424 explicit DocumentInfo(QString const& filePath = QString(),
425 QSharedPointer<Document> doc = QSharedPointer<Document>(),
426 bool valid = false): document(doc), path(filePath), isValid(valid) {}
427 };
428
430 struct DocumentStatistics
431 {
432 int fileCount = 0;
433 int documentCount = 0;
434 };
435
436 //-----------------------------------------------------------------------------
437 // The private functions used by public class methods
438 //-----------------------------------------------------------------------------
439
445 LibraryHandler();
446
447
449 void syncronizeModels();
450
452 void showNotFoundError(VLNV const& vlnv) const;
453
455 bool addObject(QSharedPointer<Document> model, QString const& filePath);
456
458 void clearCache();
459
461 void loadAvailableVLNVs();
462
464 void resetModels();
465
467 void showIntegrityResults() const;
468
476 bool removeFile(QString const& filePath) const;
477
486 bool validateDocument(QSharedPointer<Document> document, QString const& documentPath);
487
488
495 bool validateDependentVLNVReferencences(QSharedPointer<Document> document);
496
503 void findErrorsInDependentVLNVReferencences(QSharedPointer<const Document> document, QVector<QString>& errorList);
504
513 bool validateDependentDirectories(QSharedPointer<Document> document, QString const& documentPath);
514
522 void findErrorsInDependentDirectories(QSharedPointer<const Document> document, QString const& documentPath,
523 QVector<QString>& errorList);
524
531 bool validateDependentFiles(QSharedPointer<Document> document, QString const& documentPath);
532
540 void findErrorsInDependentFiles(QSharedPointer<const Document> document, QString const& documentPath,
541 QVector<QString>& errorList);
542
543 //-----------------------------------------------------------------------------
544 // Data.
545 //-----------------------------------------------------------------------------
546
547
549 NullChannel defaultChannel;
550
552 MessageMediator* messageChannel_{ &defaultChannel };
553
555 LibraryLoader loader_{ };
556
562 QMap<VLNV, DocumentInfo> documentCache_;
563
565 QRegularExpressionValidator urlTester_{ Utils::URL_VALIDITY_REG_EXP, this };
566
568 DocumentValidator validator_{ this };
569
571 LibraryTreeModel treeModel_{ this, this };
572
574 HierarchyModel hierarchyModel_{ this, this };
575
577 bool saveInProgress_{ false };
578
580 DocumentStatistics checkResults_;
581
582};
583
584#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
void onOpenSystemDesign(VLNV const &vlnv)
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 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.