Skip to content

Commit

Permalink
Only load the Diagram components and connections when really needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 26, 2015
1 parent 1978c95 commit ac53ae4
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 175 deletions.
8 changes: 5 additions & 3 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -970,9 +970,11 @@ void Component::createClassShapes()
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(mpLibraryTreeItem, "", false);
}
GraphicsView *pGraphicsView = mpLibraryTreeItem->getModelWidget()->getIconGraphicsView();
if (mpLibraryTreeItem->isConnector() && mpGraphicsView->getViewType() == StringHandler::Diagram &&
mComponentType == Component::Root && mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->hasAnnotation()) {
pGraphicsView = mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
if (mpLibraryTreeItem->isConnector() && mpGraphicsView->getViewType() == StringHandler::Diagram && mComponentType == Component::Root) {
mpLibraryTreeItem->getModelWidget()->loadDiagramView();
if (mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->hasAnnotation()) {
pGraphicsView = mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
}
}
foreach (ShapeAnnotation *pShapeAnnotation, pGraphicsView->getShapesList()) {
if (dynamic_cast<LineAnnotation*>(pShapeAnnotation)) {
Expand Down
101 changes: 52 additions & 49 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1312,6 +1312,9 @@ void LibraryTreeModel::readLibraryTreeItemClassText(LibraryTreeItem *pLibraryTre
if (pLibraryTreeItem->isInPackageOneFile()) {
LibraryTreeItem *pParentLibraryTreeItem = getContainingFileParentLibraryTreeItem(pLibraryTreeItem);
if (pParentLibraryTreeItem) {
if (pParentLibraryTreeItem->getClassText().isEmpty()) {
readLibraryTreeItemClassText(pParentLibraryTreeItem);
}
pLibraryTreeItem->setClassText(readLibraryTreeItemClassTextFromText(pLibraryTreeItem, pParentLibraryTreeItem->getClassText()));
}
} else {
Expand All @@ -1321,55 +1324,6 @@ void LibraryTreeModel::readLibraryTreeItemClassText(LibraryTreeItem *pLibraryTre
}
}

/*!
* \brief LibraryTreeModel::readLibraryTreeItemClassTextFromText
* Reads the contents of the Modelica class nested in another class.
* Removes the trailing spaces to make it look nice.
* \param contents
* \return
*/
QString LibraryTreeModel::readLibraryTreeItemClassTextFromText(LibraryTreeItem *pLibraryTreeItem, QString contents)
{
QString text;
int trailingSpaces = 0;
QTextStream textStream(&contents);
int lineNumber = 1;
while (!textStream.atEnd()) {
QString currentLine = textStream.readLine();
if (pLibraryTreeItem->inRange(lineNumber)) {
// if reading the first line then determine the trailing spaces size.
if (pLibraryTreeItem->mClassInformation.lineNumberStart == lineNumber) {
trailingSpaces = StringHandler::getTrailingSpacesSize(currentLine);
} else {
trailingSpaces = qMin(trailingSpaces, StringHandler::getTrailingSpacesSize(currentLine));
}
text += currentLine.mid(trailingSpaces) + "\n";
}
lineNumber++;
}
return text;
}

/*!
* \brief LibraryTreeModel::readLibraryTreeItemClassTextFromFile
* Reads the contents of the Modelica file.
* \return
*/
QString LibraryTreeModel::readLibraryTreeItemClassTextFromFile(LibraryTreeItem *pLibraryTreeItem)
{
QString contents = "";
QFile file(pLibraryTreeItem->getFileName());
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(mpLibraryWidget->getMainWindow(), QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(pLibraryTreeItem->getFileName())
.arg(file.errorString()), Helper::ok);
} else {
contents = QString(file.readAll());
file.close();
}
return contents;
}

/*!
* \brief LibraryTreeModel::updateLibraryTreeItemClassText
* Updates the class text of LibraryTreeItem
Expand Down Expand Up @@ -1865,6 +1819,55 @@ LibraryTreeItem* LibraryTreeModel::getLibraryTreeItemFromFileHelper(LibraryTreeI
return 0;
}

/*!
* \brief LibraryTreeModel::readLibraryTreeItemClassTextFromText
* Reads the contents of the Modelica class nested in another class.
* Removes the trailing spaces to make it look nice.
* \param contents
* \return
*/
QString LibraryTreeModel::readLibraryTreeItemClassTextFromText(LibraryTreeItem *pLibraryTreeItem, QString contents)
{
QString text;
int trailingSpaces = 0;
QTextStream textStream(&contents);
int lineNumber = 1;
while (!textStream.atEnd()) {
QString currentLine = textStream.readLine();
if (pLibraryTreeItem->inRange(lineNumber)) {
// if reading the first line then determine the trailing spaces size.
if (pLibraryTreeItem->mClassInformation.lineNumberStart == lineNumber) {
trailingSpaces = StringHandler::getTrailingSpacesSize(currentLine);
} else {
trailingSpaces = qMin(trailingSpaces, StringHandler::getTrailingSpacesSize(currentLine));
}
text += currentLine.mid(trailingSpaces) + "\n";
}
lineNumber++;
}
return text;
}

/*!
* \brief LibraryTreeModel::readLibraryTreeItemClassTextFromFile
* Reads the contents of the Modelica file.
* \return
*/
QString LibraryTreeModel::readLibraryTreeItemClassTextFromFile(LibraryTreeItem *pLibraryTreeItem)
{
QString contents = "";
QFile file(pLibraryTreeItem->getFileName());
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(mpLibraryWidget->getMainWindow(), QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(pLibraryTreeItem->getFileName())
.arg(file.errorString()), Helper::ok);
} else {
contents = QString(file.readAll());
file.close();
}
return contents;
}

/*!
* \brief LibraryTreeModel::unloadClassHelper
* Helper function for unloading/deleting the LibraryTreeItem.
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -231,8 +231,6 @@ class LibraryTreeModel : public QAbstractItemModel
void removeNonExistingLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) {mNonExistingLibraryTreeItemsList.removeOne(pLibraryTreeItem);}
void updateLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
void readLibraryTreeItemClassText(LibraryTreeItem *pLibraryTreeItem);
QString readLibraryTreeItemClassTextFromText(LibraryTreeItem *pLibraryTreeItem, QString contents);
QString readLibraryTreeItemClassTextFromFile(LibraryTreeItem *pLibraryTreeItem);
void updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryTreeItem);
void updateChildLibraryTreeItemClassText(LibraryTreeItem *pLibraryTreeItem, QString contents, QString fileName);
LibraryTreeItem* getContainingFileParentLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
Expand All @@ -254,6 +252,8 @@ class LibraryTreeModel : public QAbstractItemModel
QModelIndex libraryTreeItemIndexHelper(const LibraryTreeItem *pLibraryTreeItem, const LibraryTreeItem *pParentLibraryTreeItem,
const QModelIndex &parentIndex) const;
LibraryTreeItem* getLibraryTreeItemFromFileHelper(LibraryTreeItem *pLibraryTreeItem, QString fileName, int lineNumber);
QString readLibraryTreeItemClassTextFromText(LibraryTreeItem *pLibraryTreeItem, QString contents);
QString readLibraryTreeItemClassTextFromFile(LibraryTreeItem *pLibraryTreeItem);
void unloadClassHelper(LibraryTreeItem *pLibraryTreeItem, LibraryTreeItem *pParentLibraryTreeItem);
void unloadClassChildren(LibraryTreeItem *pLibraryTreeItem);
protected:
Expand Down

0 comments on commit ac53ae4

Please sign in to comment.