Skip to content

Commit

Permalink
More speed up for OMEdit. Only read the from class file if really nee…
Browse files Browse the repository at this point in the history
…ded.
  • Loading branch information
adeas31 committed Nov 27, 2015
1 parent d5935a5 commit cfb2a0c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
38 changes: 24 additions & 14 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -409,6 +409,21 @@ bool LibraryTreeItem::isDocumentationClass()
return mpParentLibraryTreeItem->isDocumentationClass();
}

/*!
* \brief LibraryTreeItem::getClassText
* Returns the class text. If the class text is empty then first read it.
* \param pLibraryTreeModel
* \return
*/
QString LibraryTreeItem::getClassText(LibraryTreeModel *pLibraryTreeModel)
{
qDebug() << "getClassText() called";
if (mClassText.isEmpty()) {
pLibraryTreeModel->readLibraryTreeItemClassText(this);
}
return mClassText;
}

/*!
* \brief LibraryTreeItem::updateAttributes
* Updates the LibraryTreeItem icon, text and tooltip.
Expand Down Expand Up @@ -1119,8 +1134,6 @@ LibraryTreeItem* LibraryTreeModel::createLibraryTreeItem(QString name, LibraryTr
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem == mpRootLibraryTreeItem ? isSystemLibrary : pParentLibraryTreeItem->isSystemLibrary());
createNonExistingLibraryTreeItem(pLibraryTreeItem, pParentLibraryTreeItem, isSaved);
if (load) {
// read the LibraryTreeItem text
readLibraryTreeItemClassText(pLibraryTreeItem);
// create library tree items
createLibraryTreeItems(pLibraryTreeItem);
// load the LibraryTreeItem pixmap
Expand All @@ -1139,8 +1152,6 @@ LibraryTreeItem* LibraryTreeModel::createLibraryTreeItem(QString name, LibraryTr
pParentLibraryTreeItem->insertChild(row, pLibraryTreeItem);
endInsertRows();
if (load) {
// read the LibraryTreeItem text
readLibraryTreeItemClassText(pLibraryTreeItem);
// create library tree items
createLibraryTreeItems(pLibraryTreeItem);
// load the LibraryTreeItem pixmap
Expand Down Expand Up @@ -1303,10 +1314,7 @@ 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()));
pLibraryTreeItem->setClassText(readLibraryTreeItemClassTextFromText(pLibraryTreeItem, pParentLibraryTreeItem->getClassText(this)));
}
} else {
pLibraryTreeItem->setClassText(readLibraryTreeItemClassTextFromFile(pLibraryTreeItem));
Expand Down Expand Up @@ -1335,7 +1343,7 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT
pParentLibraryTreeItem->setIsSaved(false);
updateLibraryTreeItem(pParentLibraryTreeItem);
OMCProxy *pOMCProxy = mpLibraryWidget->getMainWindow()->getOMCProxy();
QString before = pParentLibraryTreeItem->getClassText();
QString before = pParentLibraryTreeItem->getClassText(this);
QString after = pOMCProxy->listFile(pParentLibraryTreeItem->getNameStructure());
QString contents = pOMCProxy->diffModelicaFileListings(before, after);
pParentLibraryTreeItem->setClassText(contents);
Expand All @@ -1348,7 +1356,7 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT
}
// if we first updated the parent class then the child classes needs to be updated as well.
if (pParentLibraryTreeItem != pLibraryTreeItem) {
pOMCProxy->loadString(pParentLibraryTreeItem->getClassText(), pParentLibraryTreeItem->getFileName(), Helper::utf8, false);
pOMCProxy->loadString(pParentLibraryTreeItem->getClassText(this), pParentLibraryTreeItem->getFileName(), Helper::utf8, false);
updateChildLibraryTreeItemClassText(pParentLibraryTreeItem, contents, pParentLibraryTreeItem->getFileName());
pParentLibraryTreeItem->setClassInformation(pOMCProxy->getClassInformation(pParentLibraryTreeItem->getNameStructure()));
}
Expand All @@ -1371,7 +1379,7 @@ void LibraryTreeModel::updateChildLibraryTreeItemClassText(LibraryTreeItem *pLib
if (pChildLibraryTreeItem->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pChildLibraryTreeItem->getModelWidget()->getEditor());
if (pModelicaTextEditor) {
pModelicaTextEditor->setPlainText(pChildLibraryTreeItem->getClassText());
pModelicaTextEditor->setPlainText(pChildLibraryTreeItem->getClassText(this));
}
}
if (pChildLibraryTreeItem->getChildren().size() > 0) {
Expand Down Expand Up @@ -2098,7 +2106,6 @@ void LibraryTreeView::libraryTreeItemExpanded(LibraryTreeItem *pLibraryTreeItem)
for (int i = 0; i < pLibraryTreeItem->getChildren().size(); i++) {
LibraryTreeItem *pChildLibraryTreeItem = pLibraryTreeItem->child(i);
mpLibraryWidget->getMainWindow()->getStatusBar()->showMessage(QString(Helper::loading).append(": ").append(pChildLibraryTreeItem->getNameStructure()));
mpLibraryWidget->getLibraryTreeModel()->readLibraryTreeItemClassText(pChildLibraryTreeItem);
mpLibraryWidget->getLibraryTreeModel()->loadLibraryTreeItemPixmap(pChildLibraryTreeItem);
mpLibraryWidget->getMainWindow()->getStatusBar()->clearMessage();
mpLibraryWidget->getMainWindow()->getProgressBar()->setValue(++progressValue);
Expand All @@ -2114,6 +2121,8 @@ void LibraryTreeView::libraryTreeItemExpanded(LibraryTreeItem *pLibraryTreeItem)
*/
void LibraryTreeView::libraryTreeItemExpanded(QModelIndex index)
{
// QTime commandTime;
// commandTime.start();
// since expanded SIGNAL is triggered when tree has expanded the index so we must collapse it first and then load data and expand it back.
collapse(index);
QModelIndex sourceIndex = mpLibraryWidget->getLibraryTreeProxyModel()->mapToSource(index);
Expand All @@ -2122,6 +2131,7 @@ void LibraryTreeView::libraryTreeItemExpanded(QModelIndex index)
bool state = blockSignals(true);
expand(index);
blockSignals(state);
// qDebug() << "Time taken to expand " << pLibraryTreeItem->getNameStructure() << " is " << QString::number((double)commandTime.elapsed() / 1000).append(" secs");
}

/*!
Expand Down Expand Up @@ -2988,7 +2998,7 @@ bool LibraryWidget::saveModelicaLibraryTreeItemOneFile(LibraryTreeItem *pLibrary
if (pLibraryTreeItem->getModelWidget()->getEditor()) {
contents = pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText();
} else {
contents = pLibraryTreeItem->getClassText();
contents = pLibraryTreeItem->getClassText(mpLibraryTreeModel);
}
if (saveFile(fileName, contents)) {
/* mark the file as saved and update the labels. */
Expand Down Expand Up @@ -3073,7 +3083,7 @@ bool LibraryWidget::saveModelicaLibraryTreeItemFolder(LibraryTreeItem *pLibraryT
if (pLibraryTreeItem->getModelWidget()->getEditor()) {
contents = pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText();
} else {
contents = pLibraryTreeItem->getClassText();
contents = pLibraryTreeItem->getClassText(mpLibraryTreeModel);
}
if (saveFile(fileName, contents)) {
/* mark the file as saved and update the labels. */
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -67,6 +67,7 @@ class ModelWidget;
class ShapeAnnotation;
class Component;
class LineAnnotation;
class LibraryTreeModel;
class LibraryTreeItem : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -118,7 +119,7 @@ class LibraryTreeItem : public QObject
void setDragPixmap(QPixmap dragPixmap) {mDragPixmap = dragPixmap;}
QPixmap getDragPixmap() {return mDragPixmap;}
void setClassText(QString classText) {mClassText = classText;}
QString getClassText() {return mClassText;}
QString getClassText(LibraryTreeModel *pLibraryTreeModel);
void setExpanded(bool expanded) {mExpanded = expanded;}
bool isExpanded() const {return mExpanded;}
void setNonExisting(bool nonExisting) {mNonExisting = nonExisting;}
Expand Down
12 changes: 4 additions & 8 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -2521,6 +2521,7 @@ void ModelWidget::createModelWidgetComponents()
pMainLayout->setSpacing(4);
pMainLayout->addWidget(mpModelStatusBar);
setLayout(pMainLayout);
MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();
// show hide widgets based on library type
if (mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica) {
connect(mpIconViewToolButton, SIGNAL(toggled(bool)), SLOT(showIconView(bool)));
Expand All @@ -2535,14 +2536,10 @@ void ModelWidget::createModelWidgetComponents()
mpViewTypeLabel->setText(StringHandler::getViewType(StringHandler::Diagram));
// modelica text editor
mpEditor = new ModelicaTextEditor(this);
MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();
mpModelicaTextHighlighter = new ModelicaTextHighlighter(pMainWindow->getOptionsDialog()->getModelicaTextEditorPage(),
mpEditor->getPlainTextEdit());
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(mpEditor);
if (mpLibraryTreeItem->getClassText().isEmpty()) {
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->readLibraryTreeItemClassText(mpLibraryTreeItem);
}
pModelicaTextEditor->setPlainText(mpLibraryTreeItem->getClassText());
pModelicaTextEditor->setPlainText(mpLibraryTreeItem->getClassText(pMainWindow->getLibraryWidget()->getLibraryTreeModel()));
mpEditor->hide(); // set it hidden so that Find/Replace action can get correct value.
connect(pMainWindow->getOptionsDialog(), SIGNAL(modelicaTextSettingsChanged()), mpModelicaTextHighlighter, SLOT(settingsChanged()));
mpModelStatusBar->addPermanentWidget(mpReadOnlyLabel, 0);
Expand All @@ -2562,7 +2559,7 @@ void ModelWidget::createModelWidgetComponents()
pViewButtonsHorizontalLayout->addWidget(mpTextViewToolButton);
mpEditor = new TextEditor(this);
TextEditor *pTextEditor = dynamic_cast<TextEditor*>(mpEditor);
pTextEditor->setPlainText(mpLibraryTreeItem->getClassText());
pTextEditor->setPlainText(mpLibraryTreeItem->getClassText(pMainWindow->getLibraryWidget()->getLibraryTreeModel()));
mpModelStatusBar->addPermanentWidget(mpReadOnlyLabel, 0);
mpModelStatusBar->addPermanentWidget(mpModelFilePathLabel, 1);
mpModelStatusBar->addPermanentWidget(mpCursorPositionLabel, 0);
Expand Down Expand Up @@ -2610,9 +2607,8 @@ void ModelWidget::createModelWidgetComponents()
pTLMEditor->setPlainText(defaultMetaModelText);
mpLibraryTreeItem->setClassText(defaultMetaModelText);
} else {
pTLMEditor->setPlainText(mpLibraryTreeItem->getClassText());
pTLMEditor->setPlainText(mpLibraryTreeItem->getClassText(pMainWindow->getLibraryWidget()->getLibraryTreeModel()));
}
MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();
mpTLMHighlighter = new TLMHighlighter(pMainWindow->getOptionsDialog()->getTLMEditorPage(), mpEditor->getPlainTextEdit());
mpEditor->hide(); // set it hidden so that Find/Replace action can get correct value.
connect(pMainWindow->getOptionsDialog(), SIGNAL(TLMEditorSettingsChanged()), mpTLMHighlighter, SLOT(settingsChanged()));
Expand Down

0 comments on commit cfb2a0c

Please sign in to comment.