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 "LibraryModel.h"
18
19#include "HierarchyModelBase.h"
20
21#include "NullChannel.h"
22#include "utils.h"
23
24#include "DocumentFileAccess.h"
25#include "DocumentValidator.h"
26
27#include <IPXACTmodels/common/Document.h>
28#include <IPXACTmodels/common/TagData.h>
29
30#include <IPXACTmodels/kactusExtensions/KactusAttribute.h>
31
32#include <KactusAPI/KactusAPIGlobal.h>
33
34#include <QString>
35#include <QStringList>
36#include <QList>
37#include <QSharedPointer>
38#include <QObject>
39
40class LibraryItem;
41class MessageMediator;
42
43//-----------------------------------------------------------------------------
45//-----------------------------------------------------------------------------
46class KACTUS2_API LibraryHandler : public QObject, public LibraryInterface
47{
48 Q_OBJECT
49
50public:
51
54
56 LibraryHandler(const LibraryHandler &other) = delete;
57
59 LibraryHandler& operator=(const LibraryHandler& other) = delete;
60
62 ~LibraryHandler() final = default;
63
64 void setOutputChannel(MessageMediator* messageChannel);
65
74
82
91 QSharedPointer<Document> getModel(VLNV const& vlnv) final;
92
101 QSharedPointer<Document const> getModelReadOnly(VLNV const& vlnv) final;
102
107 QList<VLNV> getAllVLNVs() const final;
108
115 bool contains(VLNV const& vlnv) const final;
116
123 const QString getPath(VLNV const& vlnv) const final;
124
131 QString getDirectoryPath(VLNV const& vlnv) const final;
132
147 bool writeModelToFile(QString const& path, QSharedPointer<Document> model) final;
148
160 bool writeModelToFile(QSharedPointer<Document> model) final;
161
164
177 void getNeededVLNVs(VLNV const& vlnv, QList<VLNV>& list) final;
178
188 void getDependencyFiles(VLNV const& vlnv, QStringList& list) final;
189
194 LibraryItem const* getTreeRoot() const final;
195
204 VLNV::IPXactType getDocumentType(VLNV const& vlnv) final;
205
212 int referenceCount(VLNV const& vlnv) const final;
213
221 int getOwners(QList<VLNV>& list, VLNV const& vlnvToSearch) const final;
222
230 int getChildren(QList<VLNV>& list, VLNV const& vlnvToSearch) const final;
231
245 VLNV getDesignVLNV(VLNV const& hierarchyRef) final;
246
260 QSharedPointer<Design> getDesign(VLNV const& hierarchyRef) final;
261
268 bool isValid(VLNV const& vlnv) final;
269
271
273
282 QVector<QString> findErrorsInDocument(QSharedPointer<Document> document, QString const& path);
283
284public slots:
285
292
298 void onEditItem(VLNV const& vlnv) final;
299
306 void onOpenDesign(VLNV const& vlnv, QString const& viewName) final;
307
314 void onOpenMemoryDesign(VLNV const& vlnv, QString const& activeView);
315
321 void onOpenSWDesign(VLNV const& vlnv);
322
329 void onOpenSystemDesign(VLNV const& vlnv, QString const& activeView);
330
331
340 void removeObject(VLNV const& vlnv) final;
341
349 void removeObjects(const QList<VLNV>& vlnvList) final;
350
359 void beginSave();
360
365 void endSave();
366
367signals:
368
369
371
373 void openDesign(VLNV const& vlnv, const QString& viewName);
374
376 void openMemoryDesign(VLNV const& vlnv, const QString& viewName);
377
379 void openSWDesign(VLNV const& vlnv, QString const& viewName);
380
382 void openSystemDesign(VLNV const& vlnv, QString const& viewName);
383
385 void openBus(VLNV const& busDefVLNV);
386
388 void openAbsDef(VLNV const& absDefVLNV);
389
391 void openComponent(VLNV const& vlnv);
392
394 void openCatalog(VLNV const& vlnv);
395
397 void openComDefinition(VLNV const& vlnv);
398
400 void openApiDefinition(VLNV const& vlnv);
401
403 void itemSelected(VLNV const& vlnv);
404
406 void openPlatformComponent(VLNV const& vlnv);
407
409 void updatedVLNV(VLNV const& vlnv);
410
412 void addVLNV(VLNV const& vlnv);
413
415 void removeVLNV(VLNV const& vlnv);
416
419
420private slots:
421
431 void onItemSaved(VLNV const& vlnv);
432
433private:
434
436 struct DocumentInfo
437 {
438 QSharedPointer<Document> document; //<! The model for the document.
439 QString path; //<! The path to the file containing the document.
440 bool isValid; //<! Flag for well-formed content.
441
443 explicit DocumentInfo(QString const& filePath = QString(),
444 QSharedPointer<Document> doc = QSharedPointer<Document>(),
445 bool valid = false): document(doc), path(filePath), isValid(valid) {}
446 };
447
449 struct DocumentStatistics
450 {
451 int fileCount = 0;
452 int documentCount = 0;
453 };
454
455 //-----------------------------------------------------------------------------
456 // The private functions used by public class methods
457 //-----------------------------------------------------------------------------
458
464 LibraryHandler();
465
466
468 void syncronizeModels();
469
471 void showNotFoundError(VLNV const& vlnv) const;
472
474 bool addObject(QSharedPointer<Document> model, QString const& filePath);
475
477 void clearCache();
478
480 void loadAvailableVLNVs();
481
483 void resetModels();
484
486 void showIntegrityResults() const;
487
495 bool removeFile(QString const& filePath) const;
496
505 bool validateDocument(QSharedPointer<Document> document, QString const& documentPath);
506
507
514 bool validateDependentVLNVReferencences(QSharedPointer<Document> document);
515
522 void findErrorsInDependentVLNVReferencences(QSharedPointer<const Document> document, QVector<QString>& errorList);
523
532 bool validateDependentDirectories(QSharedPointer<Document> document, QString const& documentPath);
533
541 void findErrorsInDependentDirectories(QSharedPointer<const Document> document, QString const& documentPath,
542 QVector<QString>& errorList);
543
550 bool validateDependentFiles(QSharedPointer<Document> document, QString const& documentPath);
551
559 void findErrorsInDependentFiles(QSharedPointer<const Document> document, QString const& documentPath,
560 QVector<QString>& errorList);
561
562 //-----------------------------------------------------------------------------
563 // Data.
564 //-----------------------------------------------------------------------------
565
566
568 NullChannel defaultChannel;
569
571 MessageMediator* messageChannel_{ &defaultChannel };
572
574 LibraryLoader loader_{ };
575
581 QMap<VLNV, DocumentInfo> documentCache_;
582
584 QRegularExpressionValidator urlTester_{ Utils::URL_VALIDITY_REG_EXP, this };
585
587 DocumentValidator validator_{ this };
588
591 QScopedPointer<LibraryModel> treeModel_ = QScopedPointer<LibraryModel>{ new LibraryModel(this) };
592
594 QScopedPointer<HierarchyModelBase> hierarchyModel_ = QScopedPointer<HierarchyModelBase>(new HierarchyModelBase{ this, this });
595
597 bool saveInProgress_{ false };
598
600 DocumentStatistics checkResults_;
601
602};
603
604#endif // LIBRARYHANDLER_H
Contains the items to display the library component hierarchy to user.
HierarchyModelBase * getHierarchyModel()
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.
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
void onEditItem(VLNV const &vlnv) final
void openSystemDesign(VLNV const &vlnv, QString const &viewName)
Signal that user wants to open a system for editing.
LibraryModel * getTreeModel()
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 replaceHierarchyModel(HierarchyModelBase *model)
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.
void replaceModel(LibraryModel *model)
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.