Skip to content

Commit

Permalink
- Renamed previous & next to Variables View & Equation View.
Browse files Browse the repository at this point in the history
- Read the file info from the XML file and show the specific line to the user.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18777 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Jan 25, 2014
1 parent 3532418 commit cf1154b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 67 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/GUI/Dialogs/SimulationDialog.cpp
Expand Up @@ -1434,7 +1434,7 @@ void SimulationOutputWidget::openTransformationBrowser(QUrl url)
mpMainWindow->getTransformationsDockWidget()->show();
/* fetch the equation data */
mpMainWindow->getTransformationsWidget()->getEquationPage()->fetchEquationData(url.queryItemValue("index").toInt());
mpMainWindow->getTransformationsWidget()->nextPage();
mpMainWindow->getTransformationsWidget()->getEquationViewToolButton()->setChecked(true);
} else {
/* TODO: Display error-message */
}
Expand Down
16 changes: 12 additions & 4 deletions OMEdit/OMEditGUI/GUI/MainWindow.cpp
Expand Up @@ -117,6 +117,17 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
addDockWidget(Qt::RightDockWidgetArea, mpDocumentationDockWidget);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
mpDocumentationDockWidget->hide();
/*// create an object of SimulationBrowserWidget
mpSimulationBrowserWidget = new SimulationBrowserWidget(this);
// Create SimulationDockWidget dock
mpSimulationDockWidget = new QDockWidget(tr("Simulation Browser"), this);
mpSimulationDockWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
mpSimulationDockWidget->setObjectName("SimulationBrowser");
mpSimulationDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
mpSimulationDockWidget->setWidget(mpSimulationBrowserWidget);
addDockWidget(Qt::RightDockWidgetArea, mpSimulationDockWidget);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
mpSimulationDockWidget->hide();*/
// Create VariablesWidget dock
mpVariablesDockWidget = new QDockWidget(tr("Variables Browser"), this);
mpVariablesDockWidget->setObjectName("Variables");
Expand All @@ -132,7 +143,6 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
mpTransformationsDockWidget->setAllowedAreas(Qt::TopDockWidgetArea);
mpTransformationsDockWidget->setWidget(mpTransformationsWidget);
addDockWidget(Qt::TopDockWidgetArea, mpTransformationsDockWidget);
mpTransformationsDockWidget->hide();
//Create Actions, Toolbar and Menus
pSplashScreen->showMessage(tr("Creating Widgets"), Qt::AlignRight, Qt::white);
setAcceptDrops(true);
Expand Down Expand Up @@ -1937,6 +1947,7 @@ void MainWindow::createMenus()
pViewWindowsMenu->addAction(pSearchClassAction);
pViewWindowsMenu->addAction(mpLibraryTreeDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpDocumentationDockWidget->toggleViewAction());
// pViewWindowsMenu->addAction(mpSimulationDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpVariablesDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpMessagesDockWidget->toggleViewAction());
pViewWindowsMenu->addAction(mpTransformationsDockWidget->toggleViewAction());
Expand Down Expand Up @@ -2017,7 +2028,6 @@ void MainWindow::switchToModelingPerspective()
mpModelSwitcherToolButton->setEnabled(true);
mpPlotWindowContainer->setVisible(false);
mpVariablesDockWidget->hide();
mpTransformationsDockWidget->hide();
mpPlotToolBar->setEnabled(false);
//mpInteractiveSimualtionTabWidget->setVisible(false);
}
Expand All @@ -2033,7 +2043,6 @@ void MainWindow::switchToPlottingPerspective()
mpPlotWindowContainer->addPlotWindow();
mpPlotWindowContainer->setVisible(true);
mpVariablesDockWidget->show();
mpTransformationsDockWidget->hide();
mpPlotToolBar->setEnabled(true);
//mpInteractiveSimualtionTabWidget->setVisible(false);
}
Expand All @@ -2046,7 +2055,6 @@ void MainWindow::switchToInteractiveSimulationPerspective()
mpModelSwitcherToolButton->setEnabled(false);
mpPlotWindowContainer->setVisible(false);
mpVariablesDockWidget->hide();
mpTransformationsDockWidget->hide();
mpPlotToolBar->setEnabled(false);
//mpInteractiveSimualtionTabWidget->setVisible(true);
}
Expand Down
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/GUI/MainWindow.h
Expand Up @@ -55,6 +55,7 @@
#include "TransformationsWidget.h"
#include "LibraryTreeWidget.h"
#include "DocumentationWidget.h"
//#include "SimulationBrowserWidget.h"
#include "SimulationDialog.h"
#include "GUI/Containers/PlotWindowContainer.h"
#include "ModelWidgetContainer.h"
Expand All @@ -68,6 +69,7 @@ class TransformationsWidget;
class SearchClassWidget;
class LibraryTreeWidget;
class DocumentationWidget;
//class SimulationBrowserWidget;
class VariablesWidget;
class SimulationDialog;
class PlotWindowContainer;
Expand All @@ -94,6 +96,7 @@ class MainWindow : public QMainWindow
LibraryTreeWidget* getLibraryTreeWidget();
DocumentationWidget* getDocumentationWidget();
QDockWidget* getDocumentationDockWidget();
// SimulationBrowserWidget* getSimulationBrowserWidget() {return mpSimulationBrowserWidget;}
VariablesWidget* getVariablesWidget();
QDockWidget* getVariablesDockWidget();
TransformationsWidget* getTransformationsWidget();
Expand Down Expand Up @@ -166,6 +169,8 @@ class MainWindow : public QMainWindow
QDockWidget *mpLibraryTreeDockWidget;
DocumentationWidget *mpDocumentationWidget;
QDockWidget *mpDocumentationDockWidget;
// SimulationBrowserWidget *mpSimulationBrowserWidget;
// QDockWidget *mpSimulationDockWidget;
VariablesWidget *mpVariablesWidget;
QDockWidget *mpVariablesDockWidget;
TransformationsWidget *mpTransformationsWidget;
Expand Down
25 changes: 17 additions & 8 deletions OMEdit/OMEditGUI/GUI/Widgets/ModelicaTextWidget.cpp
Expand Up @@ -294,6 +294,22 @@ int ModelicaTextEdit::lineNumberAreaWidth()
return space;
}

/*!
Takes the cursor to the specific line.
\param lineNumber - the line number to go.
*/
void ModelicaTextEdit::goToLineNumber(int lineNumber)
{
const QTextBlock &block = document()->findBlockByNumber(lineNumber - 1); // -1 since text index start from 0
if (block.isValid())
{
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 0);
setTextCursor(cursor);
centerCursor();
}
}

//! Updates the width of LineNumberArea.
void ModelicaTextEdit::updateLineNumberAreaWidth(int newBlockCount)
{
Expand Down Expand Up @@ -876,14 +892,7 @@ void GotoLineDialog::show()
//! Slot activated when mpOkButton clicked signal raised.
void GotoLineDialog::goToLineNumber()
{
const QTextBlock &block = mpModelicaEditor->document()->findBlockByNumber(mpLineNumberTextBox->text().toInt() - 1); // -1 since text index start from 0
if (block.isValid())
{
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 0);
mpModelicaEditor->setTextCursor(cursor);
mpModelicaEditor->centerCursor();
}
mpModelicaEditor->goToLineNumber(mpLineNumberTextBox->text().toInt());
accept();
}

Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/GUI/Widgets/ModelicaTextWidget.h
Expand Up @@ -83,6 +83,7 @@ class ModelicaTextEdit : public QPlainTextEdit
bool validateModelicaText();
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void goToLineNumber(int lineNumber);
private:
ModelicaTextWidget *mpModelicaTextWidget;
QString mLastValidText;
Expand Down
121 changes: 75 additions & 46 deletions OMEdit/OMEditGUI/GUI/Widgets/TransformationsWidget.cpp
Expand Up @@ -42,31 +42,23 @@ TransformationsWidget::TransformationsWidget(MainWindow *pMainWindow)
{
mpMainWindow = pMainWindow;
mpInfoXMLFileHandler = 0;
// equation index
mpEquationIndexLabel = new Label(tr("Equation Index:"));
mpEquationIndexTextBox = new QLineEdit;
mpEquationIndexTextBox->setSizePolicy(QSizePolicy::Minimum, mpEquationIndexTextBox->sizePolicy().verticalPolicy());
connect(mpEquationIndexTextBox, SIGNAL(returnPressed()), SLOT(searchEquationIndex()));
mpSearchEquationIndexButton = new QPushButton(Helper::search);
connect(mpSearchEquationIndexButton, SIGNAL(clicked()), SLOT(searchEquationIndex()));
QHBoxLayout *pSearchEquationHorizontalLayout = new QHBoxLayout;
pSearchEquationHorizontalLayout->addWidget(mpEquationIndexLabel);
pSearchEquationHorizontalLayout->addWidget(mpEquationIndexTextBox);
pSearchEquationHorizontalLayout->addWidget(mpSearchEquationIndexButton);
QSpacerItem *pSpacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
pSearchEquationHorizontalLayout->addSpacerItem(pSpacerItem);
// create the previous button
mpPreviousToolButton = new QToolButton;
mpPreviousToolButton->setText(Helper::previous);
mpPreviousToolButton->setIcon(QIcon(":/Resources/icons/previous.png"));
mpPreviousToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
connect(mpPreviousToolButton, SIGNAL(clicked()), SLOT(previousPage()));
mpVariablesViewToolButton = new QToolButton;
mpVariablesViewToolButton->setText(tr("Variables View"));
mpVariablesViewToolButton->setCheckable(true);
mpVariablesViewToolButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
connect(mpVariablesViewToolButton, SIGNAL(toggled(bool)), SLOT(showVariablesView(bool)));
// create the next button
mpNextToolButton = new QToolButton;
mpNextToolButton->setText(Helper::next);
mpNextToolButton->setIcon(QIcon(":/Resources/icons/next.png"));
mpNextToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
connect(mpNextToolButton, SIGNAL(clicked()), SLOT(nextPage()));
mpEquationViewToolButton = new QToolButton;
mpEquationViewToolButton->setText(tr("Equation View"));
mpEquationViewToolButton->setCheckable(true);
mpEquationViewToolButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
connect(mpEquationViewToolButton, SIGNAL(toggled(bool)), SLOT(showEquationView(bool)));
/* buttons group */
QButtonGroup *pViewsButtonGroup = new QButtonGroup;
pViewsButtonGroup->setExclusive(true);
pViewsButtonGroup->addButton(mpVariablesViewToolButton);
pViewsButtonGroup->addButton(mpEquationViewToolButton);
/* info xml file path label */
mpInfoXMLFilePathLabel = new Label;
/* create the stacked widget object */
Expand All @@ -77,11 +69,10 @@ TransformationsWidget::TransformationsWidget(MainWindow *pMainWindow)
/* set the layout */
QGridLayout *pTopLayout = new QGridLayout;
pTopLayout->setContentsMargins(0, 0, 0, 0);
pTopLayout->addLayout(pSearchEquationHorizontalLayout, 0, 0, 1, 3);
pTopLayout->addWidget(mpPreviousToolButton, 1, 0);
pTopLayout->addWidget(mpNextToolButton, 1, 1);
pTopLayout->addWidget(mpInfoXMLFilePathLabel, 1, 2);
pTopLayout->addWidget(mpPagesWidget, 2, 0, 1, 3);
pTopLayout->addWidget(mpVariablesViewToolButton, 0, 0);
pTopLayout->addWidget(mpEquationViewToolButton, 0, 1);
pTopLayout->addWidget(mpInfoXMLFilePathLabel, 0, 2);
pTopLayout->addWidget(mpPagesWidget, 1, 0, 1, 3);
QFrame *pTopFrame = new QFrame;
pTopFrame->setLayout(pTopLayout);
/* splitter */
Expand Down Expand Up @@ -123,6 +114,7 @@ void TransformationsWidget::showTransformations(QString fileName)
mpVariablePage = new VariablePage(this);
mpVariablePage->initialize();
mpPagesWidget->addWidget(mpVariablePage);
mpVariablesViewToolButton->setChecked(true);
mpEquationPage = new EquationPage(this);
mpPagesWidget->addWidget(mpEquationPage);
}
Expand All @@ -132,30 +124,18 @@ void TransformationsWidget::showInfoText(QString message)
mpInfoTextBox->setPlainText(message);
}

void TransformationsWidget::searchEquationIndex()
{
if (!mpInfoXMLFileHandler || mpEquationIndexTextBox->text().isEmpty())
return;

bool ok = false;
int index = mpEquationIndexTextBox->text().toInt(&ok);
if (!ok)
return;

mpEquationPage->fetchEquationData(index);
nextPage();
}

void TransformationsWidget::previousPage()
void TransformationsWidget::showVariablesView(bool checked)
{
if (!checked) return;
int index = mpPagesWidget->currentIndex();
if (index <= 0)
return;
mpPagesWidget->setCurrentIndex(--index);
}

void TransformationsWidget::nextPage()
void TransformationsWidget::showEquationView(bool checked)
{
if (!checked) return;
int index = mpPagesWidget->currentIndex();
if (index >= mpPagesWidget->count())
return;
Expand Down Expand Up @@ -479,13 +459,26 @@ void VariablePage::showEquation(QTreeWidgetItem *pVariableTreeItem, int column)
if (!pVariableTreeItem)
return;
mpTransformationsWidget->getEquationPage()->fetchEquationData(pVariableTreeItem->text(0).toInt());
mpTransformationsWidget->nextPage();
mpTransformationsWidget->getEquationViewToolButton()->setChecked(true);
}

EquationPage::EquationPage(TransformationsWidget *pTransformationsWidget)
: QWidget(pTransformationsWidget)
{
mpTransformationsWidget = pTransformationsWidget;
// equation index
mpEquationIndexLabel = new Label(tr("Equation Index:"));
mpEquationIndexTextBox = new QLineEdit;
mpEquationIndexTextBox->setSizePolicy(QSizePolicy::Minimum, mpEquationIndexTextBox->sizePolicy().verticalPolicy());
connect(mpEquationIndexTextBox, SIGNAL(returnPressed()), SLOT(searchEquationIndex()));
mpSearchEquationIndexButton = new QPushButton(Helper::search);
connect(mpSearchEquationIndexButton, SIGNAL(clicked()), SLOT(searchEquationIndex()));
QHBoxLayout *pSearchEquationHorizontalLayout = new QHBoxLayout;
pSearchEquationHorizontalLayout->addWidget(mpEquationIndexLabel);
pSearchEquationHorizontalLayout->addWidget(mpEquationIndexTextBox);
pSearchEquationHorizontalLayout->addWidget(mpSearchEquationIndexButton);
QSpacerItem *pSpacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
pSearchEquationHorizontalLayout->addSpacerItem(pSpacerItem);
/* defines tree widget */
Label *pDefinesLabel = new Label(tr("Defines"));
mpDefinesTreeWidget = new QTreeWidget;
Expand Down Expand Up @@ -557,7 +550,8 @@ EquationPage::EquationPage(TransformationsWidget *pTransformationsWidget)
/* set the layout */
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setContentsMargins(0, 0, 0, 0);
pMainLayout->addWidget(pSplitter, 0, 0);
pMainLayout->addLayout(pSearchEquationHorizontalLayout, 0, 0);
pMainLayout->addWidget(pSplitter, 1, 0);
setLayout(pMainLayout);
}

Expand All @@ -570,6 +564,28 @@ void EquationPage::fetchEquationData(int equationIndex)
fetchDepends(equation);
/* fetch operations */
fetchOperations(equation);
/* open the model with and go to the line */
qDebug() << equation.info.toString();
MainWindow *pMainWindow = mpTransformationsWidget->getMainWindow();
QFileInfo fileInfo(equation.info.file);
foreach (LibraryTreeNode* pLibraryTreeNode, pMainWindow->getLibraryTreeWidget()->getLibraryTreeNodesList())
{
QFileInfo libraryTreeNodeFileInfo(pLibraryTreeNode->getFileName());
if (fileInfo.absoluteFilePath().compare(libraryTreeNodeFileInfo.absoluteFilePath()) == 0)
{
/* find the root library tree node. */
LibraryTreeNode *pParentLibraryTreeNode = pMainWindow->getLibraryTreeWidget()->getLibraryTreeNode(StringHandler::getFirstWordBeforeDot(pLibraryTreeNode->getNameStructure()));
if (pParentLibraryTreeNode)
{
pMainWindow->getLibraryTreeWidget()->showModelWidget(pParentLibraryTreeNode);
if (pParentLibraryTreeNode->getModelWidget())
{
pParentLibraryTreeNode->getModelWidget()->showModelicaTextView(true);
pParentLibraryTreeNode->getModelWidget()->getModelicaTextWidget()->getModelicaTextEdit()->goToLineNumber(equation.info.lineStart);
}
}
}
}
}

void EquationPage::fetchDefines(OMEquation &equation)
Expand Down Expand Up @@ -651,6 +667,19 @@ void EquationPage::fetchOperations(OMEquation &equation)
}
}

void EquationPage::searchEquationIndex()
{
if (!mpTransformationsWidget->getInfoXMLFileHandler() || mpEquationIndexTextBox->text().isEmpty())
return;

bool ok = false;
int index = mpEquationIndexTextBox->text().toInt(&ok);
if (!ok)
return;

fetchEquationData(index);
}

void EquationPage::definesItemChanged(QTreeWidgetItem *current)
{
if (!current) return;
Expand Down
17 changes: 9 additions & 8 deletions OMEdit/OMEditGUI/GUI/Widgets/TransformationsWidget.h
Expand Up @@ -51,26 +51,23 @@ class TransformationsWidget : public QWidget
TransformationsWidget(MainWindow *pMainWindow);
MainWindow* getMainWindow() {return mpMainWindow;}
MyHandler* getInfoXMLFileHandler() {return mpInfoXMLFileHandler;}
QToolButton* getEquationViewToolButton() {return mpEquationViewToolButton;}
EquationPage* getEquationPage() {return mpEquationPage;}
void showTransformations(QString fileName);
void showInfoText(QString message);
private:
MainWindow *mpMainWindow;
MyHandler *mpInfoXMLFileHandler;
Label *mpEquationIndexLabel;
QLineEdit *mpEquationIndexTextBox;
QPushButton *mpSearchEquationIndexButton;
QToolButton *mpPreviousToolButton;
QToolButton *mpNextToolButton;
QToolButton *mpVariablesViewToolButton;
QToolButton *mpEquationViewToolButton;
Label *mpInfoXMLFilePathLabel;
QStackedWidget *mpPagesWidget;
VariablePage *mpVariablePage;
EquationPage *mpEquationPage;
QPlainTextEdit *mpInfoTextBox;
public slots:
void searchEquationIndex();
void previousPage();
void nextPage();
void showVariablesView(bool checked);
void showEquationView(bool checked);
};

class VariablePage : public QWidget
Expand Down Expand Up @@ -111,10 +108,14 @@ class EquationPage : public QWidget
void fetchOperations(OMEquation &equation);
private:
TransformationsWidget *mpTransformationsWidget;
Label *mpEquationIndexLabel;
QLineEdit *mpEquationIndexTextBox;
QPushButton *mpSearchEquationIndexButton;
QTreeWidget *mpDefinesTreeWidget;
QTreeWidget *mpDependsTreeWidget;
QTreeWidget *mpOperationsTreeWidget;
public slots:
void searchEquationIndex();
void definesItemChanged(QTreeWidgetItem *current);
void dependsItemChanged(QTreeWidgetItem *current);
void operationsItemChanged(QTreeWidgetItem *current);
Expand Down

0 comments on commit cf1154b

Please sign in to comment.