Skip to content

Commit

Permalink
WIP: Read directories from file
Browse files Browse the repository at this point in the history
  • Loading branch information
ailujezi committed Feb 19, 2024
1 parent d024b5b commit 72840b8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ namespace hal
private:
u32 mId;
QString mName;
u32 mMinDirectoryId;
u32 mParentId;

public:
ContextDirectory(QString name, u32 parentId):mName(name), mMinDirectoryId(std::numeric_limits<u32>::max()){
mId = --mMinDirectoryId;
ContextDirectory(QString name, u32 parentId, u32 id):mName(name){
mId = id;
mParentId = parentId;
}

Expand All @@ -55,6 +54,7 @@ namespace hal
*/
void writeToFile(QJsonObject& json);


QString name() const { return mName; }
u32 id() const { return mId; }
void setId(u32 id_) { mId = id_; }
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace hal
* @param name - The name to the directory.
* @param parent - The Parent of the directory.
*/
ContextDirectory* addDirectory(QString name, BaseTreeItem* parent = nullptr);
ContextDirectory* addDirectory(QString name, BaseTreeItem* parent = nullptr, u32 id = 0);

BaseTreeItem* getDirectory(u32 directoryId) const;

Expand Down Expand Up @@ -186,6 +186,21 @@ namespace hal
*/
void setCurrentDirectory(ContextTreeItem* currentItem);

/**
* Sets the MinDirectoryId.
*
* @param u32 - id to set MinDirectoryId to.
*/
void setMinDirectoryId(u32 id_) { mMinDirectoryId = id_; }

/**
* Get MinDirectoryId.
*
* @return MinDIrectoryId.
*/
u32 minDirectoryId() const { return mMinDirectoryId; }


Q_SIGNALS:
void directoryCreatedSignal(ContextTreeItem* item);

Expand All @@ -195,6 +210,7 @@ namespace hal
std::map<GraphContext *, ContextTreeItem *> mContextMap;
QVector<GraphContext*> mContextList;
QVector<ContextDirectory*> mDirectoryList;
u32 mMinDirectoryId;

};
} // namespace hal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace hal
{
void ContextDirectory::writeToFile(QJsonObject &json)
{
json["patrentId"] = (int) mParentId;
json["parentId"] = (int) mParentId;
json["id"] = (int) mId;
json["name"] = mName;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace hal
return mContext != nullptr;
}

ContextTreeModel::ContextTreeModel(QObject* parent) : BaseTreeModel(parent), mCurrentDirectory(nullptr)
ContextTreeModel::ContextTreeModel(QObject* parent) : BaseTreeModel(parent), mCurrentDirectory(nullptr), mMinDirectoryId(std::numeric_limits<u32>::max())
{
setHeaderLabels(QStringList() << "View Name" << "Timestamp");
}
Expand Down Expand Up @@ -184,17 +184,22 @@ namespace hal
return nullptr;
}

ContextDirectory* ContextTreeModel::addDirectory(QString name, BaseTreeItem *parent)
ContextDirectory* ContextTreeModel::addDirectory(QString name, BaseTreeItem *parent, u32 id)
{

if(id == 0)
id = --mMinDirectoryId;
else if (id < mMinDirectoryId)
mMinDirectoryId = id;

BaseTreeItem* parentItem = parent;

if (!parentItem)
parentItem = mCurrentDirectory;
if (!parentItem)
parentItem = mRootItem;

ContextDirectory* directory = new ContextDirectory(name, (parentItem != mRootItem) ? static_cast<ContextTreeItem*>(parentItem)->directory()->id() : 0);
ContextDirectory* directory = new ContextDirectory(name, (parentItem != mRootItem) ? static_cast<ContextTreeItem*>(parentItem)->directory()->id() : 0, id);

ContextTreeItem* item = new ContextTreeItem(directory);

Expand Down
38 changes: 37 additions & 1 deletion plugins/gui/src/graph_widget/graph_context_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,32 @@ namespace hal
GraphContext* firstContext = nullptr;
GraphContext* selectedContext = nullptr;

if (json.contains("directories") && json["directories"].isArray())
{
QJsonArray jsonDirectories = json["directories"].toArray();
int ndir = jsonDirectories.size();
for (int idir = 0; idir < ndir; idir++)
{
QJsonObject jsondir = jsonDirectories.at(idir).toObject();
if (!jsondir.contains("id") || !jsondir["id"].isDouble())
continue;
u32 dirId = jsondir["id"].toInt();
if (!jsondir.contains("name") || !jsondir["name"].isString())
continue;
QString dirName = jsondir["name"].toString();
if (!jsondir.contains("parentId"))
continue;
u32 dirParentId = jsondir["parentId"].toInt();

BaseTreeItem* dirParent = nullptr;

if (dirParentId != 0) {
mContextTreeModel->getDirectory(dirParentId);
}

mContextTreeModel->addDirectory(dirName, dirParent, dirId);
}
}
if (json.contains("views") && json["views"].isArray())
{
QJsonArray jsonViews = json["views"].toArray();
Expand All @@ -600,6 +626,16 @@ namespace hal
int visibleFlag = 1; // default to visible before flag was invented
if (jsonView.contains("visible"))
visibleFlag = jsonView["visible"].toInt();
if (!jsonView.contains("parentId"))
continue;
u32 viewParentId = jsonView["parentId"].toInt();
BaseTreeItem* viewParent = nullptr;

if (viewParentId != 0) {
mContextTreeModel->getDirectory(viewParentId);
}


GraphContext* context = gGraphContextManager->getContextById(viewId);
if (context)
{
Expand Down Expand Up @@ -630,7 +666,7 @@ namespace hal
continue;
}

mContextTreeModel->addContext(context);
mContextTreeModel->addContext(context, viewParent);
if (visibleFlag)
Q_EMIT contextCreated(context);
}
Expand Down

0 comments on commit 72840b8

Please sign in to comment.