1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
|
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/MessageView_Window.hxx>
#include <inspector/MessageView_VisibilityState.hxx>
#include <inspector/MessageView_ActionsTest.hxx>
#include <inspector/MessageModel_Actions.hxx>
#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_TreeModel.hxx>
#include <inspector/MessageView_MetricStatisticModel.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_PropertyView.hxx>
#include <inspector/ViewControl_TableModelValues.hxx>
#include <inspector/ViewControl_TreeView.hxx>
#include <inspector/Convert_Tools.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/View_Widget.hxx>
#include <AIS_Shape.hxx>
#include <Graphic3d_Camera.hxx>
#include <Message.hxx>
#include <TCollection_AsciiString.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <inspector/View_Displayer.hxx>
#include <inspector/View_ToolBar.hxx>
#include <inspector/View_Widget.hxx>
#include <inspector/View_Window.hxx>
#include <inspector/View_Viewer.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QAction>
#include <QDockWidget>
#include <QFile>
#include <QFileDialog>
#include <QHeaderView>
#include <QLayout>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QTextStream>
#include <QToolBar>
#include <QToolButton>
#include <QTreeView>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
const int DEFAULT_SHAPE_VIEW_WIDTH = 400;
const int DEFAULT_SHAPE_VIEW_HEIGHT = 450;
const int DEFAULT_SHAPE_VIEW_POSITION_X = 60;
const int DEFAULT_SHAPE_VIEW_POSITION_Y = 60;
const int MESSAGEVIEW_DEFAULT_TREE_VIEW_WIDTH = 950;
const int MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT = 500;
const int MESSAGEVIEW_DEFAULT_VIEW_WIDTH = 200;
const int MESSAGEVIEW_DEFAULT_VIEW_HEIGHT = 300;
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
MessageView_Window::MessageView_Window(QWidget* theParent)
: QObject(theParent)
{
myMainWindow = new QMainWindow(theParent);
myTreeView = new ViewControl_TreeView(myMainWindow);
((ViewControl_TreeView*)myTreeView)
->SetPredefinedSize(
QSize(MESSAGEVIEW_DEFAULT_TREE_VIEW_WIDTH, MESSAGEVIEW_DEFAULT_TREE_VIEW_HEIGHT));
MessageModel_TreeModel* aModel = new MessageModel_TreeModel(myTreeView);
aModel->InitColumns();
connect(myTreeView->header(),
SIGNAL(sectionResized(int, int, int)),
this,
SLOT(onHeaderResized(int, int, int)));
myTreeView->setModel(aModel);
MessageView_VisibilityState* aVisibilityState = new MessageView_VisibilityState(aModel);
aModel->SetVisibilityState(aVisibilityState);
connect(aVisibilityState,
SIGNAL(itemClicked(const QModelIndex&)),
this,
SLOT(onTreeViewVisibilityClicked(const QModelIndex&)));
TreeModel_Tools::UseVisibilityColumn(myTreeView);
TreeModel_Tools::SetDefaultHeaderSections(myTreeView);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel(aModel);
myTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
myTreeView->setSelectionModel(aSelectionModel);
connect(aSelectionModel,
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this,
SLOT(onTreeViewSelectionChanged(const QItemSelection&, const QItemSelection&)));
myTreeViewActions = new MessageModel_Actions(myMainWindow, aModel, aSelectionModel);
myTestViewActions = new MessageView_ActionsTest(myMainWindow, aModel, aSelectionModel);
myTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(myTreeView,
SIGNAL(customContextMenuRequested(const QPoint&)),
this,
SLOT(onTreeViewContextMenuRequested(const QPoint&)));
connect(myTreeView->header(),
SIGNAL(sectionResized(int, int, int)),
this,
SLOT(onHeaderResized(int, int, int)));
QModelIndex aParentIndex = myTreeView->model()->index(0, 0);
myTreeView->setExpanded(aParentIndex, true);
myMainWindow->setCentralWidget(myTreeView);
// property view
myPropertyView = new ViewControl_PropertyView(myMainWindow);
myPropertyPanelWidget = new QDockWidget(tr("PropertyPanel"), myMainWindow);
myPropertyPanelWidget->setObjectName(myPropertyPanelWidget->windowTitle());
myPropertyPanelWidget->setTitleBarWidget(new QWidget(myMainWindow));
myPropertyPanelWidget->setWidget(myPropertyView->GetControl());
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, myPropertyPanelWidget);
connect(myPropertyPanelWidget->toggleViewAction(),
SIGNAL(toggled(bool)),
this,
SLOT(onPropertyPanelShown(bool)));
connect(myPropertyView,
SIGNAL(propertyViewDataChanged()),
this,
SLOT(onPropertyViewDataChanged()));
myCustomView = new QTableView(myMainWindow);
myCustomPanelWidget = new QDockWidget(tr("PropertyPanel (custom)"), myMainWindow);
myCustomPanelWidget->setObjectName(myCustomPanelWidget->windowTitle());
myCustomPanelWidget->setTitleBarWidget(new QWidget(myMainWindow));
myCustomPanelWidget->setWidget(myCustomView);
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, myCustomPanelWidget);
// view
myViewWindow = new View_Window(myMainWindow, NULL, false);
connect(myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed()));
aVisibilityState->SetDisplayer(myViewWindow->Displayer());
aVisibilityState->SetPresentationType(View_PresentationType_Main);
myViewWindow->ViewWidget()->SetPredefinedSize(MESSAGEVIEW_DEFAULT_VIEW_WIDTH,
MESSAGEVIEW_DEFAULT_VIEW_HEIGHT);
myViewDockWidget = new QDockWidget(tr("View"), myMainWindow);
myViewDockWidget->setObjectName(myViewDockWidget->windowTitle());
myViewDockWidget->setWidget(myViewWindow);
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, myViewDockWidget);
myMainWindow->tabifyDockWidget(myCustomPanelWidget, myViewDockWidget);
myMainWindow->resize(DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT);
myMainWindow->move(DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y);
updateVisibleColumns();
}
// =======================================================================
// function : SetParent
// purpose :
// =======================================================================
void MessageView_Window::SetParent(void* theParent)
{
QWidget* aParent = (QWidget*)theParent;
if (aParent)
{
QLayout* aLayout = aParent->layout();
if (aLayout)
aLayout->addWidget(GetMainWindow());
}
else
{
GetMainWindow()->setParent(0);
GetMainWindow()->setVisible(true);
}
}
// =======================================================================
// function : FillActionsMenu
// purpose :
// =======================================================================
void MessageView_Window::FillActionsMenu(void* theMenu)
{
QMenu* aMenu = (QMenu*)theMenu;
QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
{
QDockWidget* aDockWidget = *it;
if (aDockWidget->parentWidget() == myMainWindow)
aMenu->addAction(aDockWidget->toggleViewAction());
}
}
// =======================================================================
// function : GetPreferences
// purpose :
// =======================================================================
void MessageView_Window::GetPreferences(TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Clear();
theItem.Bind("geometry",
TreeModel_Tools::ToString(myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
TreeModel_Tools::SaveState(myTreeView, anItems);
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin();
anItemsIt != anItems.end();
anItemsIt++)
{
theItem.Bind(anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
}
anItems.clear();
View_Window::SaveState(myViewWindow, anItems);
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin();
anItemsIt != anItems.end();
anItemsIt++)
{
theItem.Bind(anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
}
}
// =======================================================================
// function : SetPreferences
// purpose :
// =======================================================================
void MessageView_Window::SetPreferences(const TInspectorAPI_PreferencesDataMap& theItem)
{
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt(theItem); anItemIt.More();
anItemIt.Next())
{
if (anItemIt.Key().IsEqual("geometry"))
myMainWindow->restoreState(TreeModel_Tools::ToByteArray(anItemIt.Value().ToCString()));
else if (TreeModel_Tools::RestoreState(myTreeView,
anItemIt.Key().ToCString(),
anItemIt.Value().ToCString()))
continue;
else if (myViewWindow
&& View_Window::RestoreState(myViewWindow,
anItemIt.Key().ToCString(),
anItemIt.Value().ToCString()))
continue;
}
}
// =======================================================================
// function : UpdateContent
// purpose :
// =======================================================================
void MessageView_Window::UpdateContent()
{
TCollection_AsciiString aName = "TKMessageView";
if (myParameters->FindParameters(aName))
{
NCollection_List<Handle(Standard_Transient)> aParameters = myParameters->Parameters(aName);
// Init will remove from parameters those, that are processed only one time (TShape)
Init(aParameters);
myParameters->SetParameters(aName, aParameters);
}
Handle(Message_Report) aDefaultReport = Message::DefaultReport();
MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
if (!aDefaultReport.IsNull() && !aViewModel->HasReport(aDefaultReport))
{
addReport(aDefaultReport);
}
updateTreeModel();
updateVisibleColumns();
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void MessageView_Window::Init(NCollection_List<Handle(Standard_Transient)>& theParameters)
{
Handle(AIS_InteractiveContext) aContext;
NCollection_List<Handle(Standard_Transient)> aParameters;
Handle(Graphic3d_Camera) aViewCamera;
for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt(theParameters);
aParamsIt.More();
aParamsIt.Next())
{
Handle(Standard_Transient) anObject = aParamsIt.Value();
Handle(Message_Report) aMessageReport = Handle(Message_Report)::DownCast(anObject);
if (!aMessageReport.IsNull())
{
addReport(aMessageReport);
}
else if (!Handle(AIS_InteractiveContext)::DownCast(anObject).IsNull())
{
aParameters.Append(anObject);
if (aContext.IsNull())
aContext = Handle(AIS_InteractiveContext)::DownCast(anObject);
}
else if (!Handle(Graphic3d_Camera)::DownCast(anObject).IsNull())
{
aViewCamera = Handle(Graphic3d_Camera)::DownCast(anObject);
}
}
MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
if (!aTreeModel)
return;
aTreeModel->EmitLayoutChanged();
if (!aContext.IsNull())
{
myViewWindow->SetContext(View_ContextType_External, aContext);
}
theParameters = aParameters;
}
// =======================================================================
// function : updateTreeModel
// purpose :
// =======================================================================
void MessageView_Window::updateTreeModel()
{
MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
if (!aViewModel)
return;
aViewModel->UpdateTreeModel();
}
// =======================================================================
// function : addReport
// purpose :
// =======================================================================
void MessageView_Window::addReport(const Handle(Message_Report)& theReport,
const TCollection_AsciiString& theReportDescription)
{
MessageModel_TreeModel* aModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
aModel->AddReport(theReport, theReportDescription);
}
// =======================================================================
// function : onTreeViewVisibilityClicked
// purpose :
// =======================================================================
void MessageView_Window::onTreeViewVisibilityClicked(const QModelIndex& theIndex)
{
MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
TreeModel_VisibilityState* aVisibilityState = aTreeModel->GetVisibilityState();
if (!aVisibilityState->IsVisible(theIndex))
myPropertyView->ClearActiveTablesSelection();
}
// =======================================================================
// function : onTreeViewSelectionChanged
// purpose :
// =======================================================================
void MessageView_Window::onTreeViewSelectionChanged(const QItemSelection&, const QItemSelection&)
{
if (!myPropertyPanelWidget->toggleViewAction()->isChecked())
return;
updatePropertyPanelBySelection();
updatePreviewPresentation();
}
// =======================================================================
// function : onTreeViewContextMenuRequested
// purpose :
// =======================================================================
void MessageView_Window::onTreeViewContextMenuRequested(const QPoint& thePosition)
{
QMenu* aMenu = new QMenu(GetMainWindow());
MessageModel_ItemRootPtr aRootItem;
MessageModel_ItemReportPtr aReportItem;
QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin();
aSelIt != aSelectedIndices.end();
aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
continue;
aRootItem = itemDynamicCast<MessageModel_ItemRoot>(anItemBase);
if (aRootItem)
break;
aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
if (aReportItem)
break;
}
if (aRootItem)
{
aMenu->addAction(ViewControl_Tools::CreateAction(tr("Create Default Report"),
SLOT(onCreateDefaultReport()),
myMainWindow,
this));
}
else if (aReportItem)
{
aMenu->addAction(ViewControl_Tools::CreateAction(tr("Export Report"),
SLOT(onExportReport()),
myMainWindow,
this));
QAction* anAction = ViewControl_Tools::CreateAction(tr("WallClock Metric statistic"),
SLOT(onMetricStatistic()),
myMainWindow,
this);
anAction->setCheckable(true);
aMenu->addAction(anAction);
}
aMenu->addSeparator();
aMenu->addAction(ViewControl_Tools::CreateAction(tr("Preview children presentations"),
SLOT(onPreviewChildren()),
myMainWindow,
this));
aMenu->addSeparator();
myTreeViewActions->AddMenuActions(aSelectedIndices, aMenu);
addActivateMetricActions(aMenu);
aMenu->addSeparator();
myTestViewActions->AddMenuActions(aSelectedIndices, aMenu);
QPoint aPoint = myTreeView->mapToGlobal(thePosition);
aMenu->exec(aPoint);
}
// =======================================================================
// function : onPropertyPanelShown
// purpose :
// =======================================================================
void MessageView_Window::onPropertyPanelShown(bool isToggled)
{
if (!isToggled)
return;
updatePropertyPanelBySelection();
}
// =======================================================================
// function : onPropertyViewDataChanged
// purpose :
// =======================================================================
void MessageView_Window::onPropertyViewDataChanged()
{
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
return;
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
return;
updatePropertyPanelBySelection();
updatePreviewPresentation();
}
// =======================================================================
// function : onHeaderResized
// purpose :
// =======================================================================
void MessageView_Window::onHeaderResized(int theSectionId, int, int)
{
TreeModel_ModelBase* aViewModel = dynamic_cast<TreeModel_ModelBase*>(myTreeView->model());
TreeModel_HeaderSection* aSection = aViewModel->ChangeHeaderItem(theSectionId);
aSection->SetWidth(myTreeView->columnWidth(theSectionId));
}
// =======================================================================
// function : onEraseAllPerformed
// purpose :
// =======================================================================
void MessageView_Window::onEraseAllPerformed()
{
MessageModel_TreeModel* aTreeModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
aTreeModel->Reset();
aTreeModel->EmitLayoutChanged();
}
// =======================================================================
// function : onExportReport
// purpose :
// =======================================================================
void MessageView_Window::onExportReport()
{
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
return;
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
return;
MessageModel_ItemReportPtr aReportItem = itemDynamicCast<MessageModel_ItemReport>(anItemBase);
if (!aReportItem)
return;
QString aFilter(tr("Document file (*.json *)"));
QString aSelectedFilter;
QString aFileName = QFileDialog::getSaveFileName(0,
tr("Export report to file"),
QString(),
aFilter,
&aSelectedFilter);
Handle(Message_Report) aReport = aReportItem->GetReport();
Standard_SStream aStream;
aReport->DumpJson(aStream);
QFile aLogFile(aFileName);
if (!aLogFile.open(QFile::WriteOnly | QFile::Text))
{
return;
}
QTextStream anOut(&aLogFile);
anOut << Standard_Dump::FormatJson(aStream).ToCString();
aLogFile.close();
}
// =======================================================================
// function : onCreateDefaultReport
// purpose :
// =======================================================================
void MessageView_Window::onCreateDefaultReport()
{
if (!Message::DefaultReport().IsNull())
{
return;
}
addReport(Message::DefaultReport(Standard_True));
}
// =======================================================================
// function : onPreviewChildren
// purpose :
// =======================================================================
void MessageView_Window::onPreviewChildren()
{
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
return;
QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
NCollection_List<Handle(Standard_Transient)> aPresentations;
TreeModel_ModelBase::SubItemsPresentations(aSelectedIndices, aPresentations);
displayer()->UpdatePreview(View_DisplayActionType_DisplayId, aPresentations);
}
// =======================================================================
// function : onMetricStatistic
// purpose :
// =======================================================================
void MessageView_Window::onMetricStatistic()
{
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
{
return;
}
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
{
return;
}
MessageView_MetricStatisticModel* aUnitByNameModel =
new MessageView_MetricStatisticModel(Message_MetricType_WallClock, myCustomView);
aUnitByNameModel->Init(anItemBase);
myCustomView->setModel(aUnitByNameModel);
}
// =======================================================================
// function : addActivateMetricActions
// purpose :
// =======================================================================
void MessageView_Window::addActivateMetricActions(QMenu* theMenu)
{
Handle(Message_Report) aReport = Message::DefaultReport();
if (aReport.IsNull())
{
return;
}
QMenu* aSubMenu = new QMenu("Activate metric");
for (int aMetricId = (int)Message_MetricType_None + 1;
aMetricId <= (int)Message_MetricType_MemHeapUsage;
aMetricId++)
{
Message_MetricType aMetricType = (Message_MetricType)aMetricId;
QAction* anAction = ViewControl_Tools::CreateAction(Message::MetricToString(aMetricType),
SLOT(OnActivateMetric()),
parent(),
this);
anAction->setCheckable(true);
anAction->setChecked(aReport->ActiveMetrics().Contains(aMetricType));
aSubMenu->addAction(anAction);
}
aSubMenu->addSeparator();
aSubMenu->addAction(ViewControl_Tools::CreateAction("Deactivate all",
SLOT(OnDeactivateAllMetrics()),
parent(),
this));
theMenu->addMenu(aSubMenu);
}
// =======================================================================
// function : OnActivateMetric
// purpose :
// =======================================================================
void MessageView_Window::OnActivateMetric()
{
QAction* anAction = (QAction*)(sender());
Message_MetricType aMetricType;
if (!Message::MetricFromString(anAction->text().toStdString().c_str(), aMetricType))
return;
Handle(Message_Report) aReport = Message::DefaultReport();
const NCollection_IndexedMap<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
aReport->SetActiveMetric(aMetricType, !anActiveMetrics.Contains(aMetricType));
updateVisibleColumns();
}
// =======================================================================
// function : OnDeactivateAllMetrics
// purpose :
// =======================================================================
void MessageView_Window::OnDeactivateAllMetrics()
{
Handle(Message_Report) aReport = Message::DefaultReport();
if (aReport.IsNull())
return;
aReport->ClearMetrics();
updateVisibleColumns();
}
// =======================================================================
// function : displayer
// purpose :
// =======================================================================
View_Displayer* MessageView_Window::displayer()
{
return myViewWindow->Displayer();
}
// =======================================================================
// function : updatePropertyPanelBySelection
// purpose :
// =======================================================================
void MessageView_Window::updatePropertyPanelBySelection()
{
ViewControl_TableModelValues* aTableValues = 0;
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
return;
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (anItemBase)
{
Handle(TreeModel_ItemProperties) anItemProperties = anItemBase->Properties();
if (!anItemProperties.IsNull())
{
aTableValues = new ViewControl_TableModelValues();
aTableValues->SetProperties(anItemProperties);
}
}
myPropertyView->Init(aTableValues);
}
// =======================================================================
// function : updatePreviewPresentation
// purpose :
// =======================================================================
void MessageView_Window::updatePreviewPresentation()
{
Handle(AIS_InteractiveContext) aContext = myViewWindow->ViewToolBar()->CurrentContext();
if (aContext.IsNull())
return;
NCollection_List<Handle(Standard_Transient)> aPresentations;
QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes();
for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin();
aSelIt != aSelectedIndices.end();
aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
continue;
anItemBase->Presentations(aPresentations);
}
displayer()->UpdatePreview(View_DisplayActionType_DisplayId, aPresentations);
}
// =======================================================================
// function : updateVisibleColumns
// purpose :
// =======================================================================
void MessageView_Window::updateVisibleColumns()
{
MessageModel_TreeModel* aViewModel = dynamic_cast<MessageModel_TreeModel*>(myTreeView->model());
NCollection_IndexedMap<Message_MetricType> anActiveMetrics;
for (NCollection_List<MessageModel_ReportInformation>::Iterator anIterator(aViewModel->Reports());
anIterator.More();
anIterator.Next())
{
Handle(Message_Report) aReport = anIterator.Value().myReport;
for (NCollection_IndexedMap<Message_MetricType>::Iterator aMetricsIterator(
aReport->ActiveMetrics());
aMetricsIterator.More();
aMetricsIterator.Next())
{
if (anActiveMetrics.Contains(aMetricsIterator.Value()))
continue;
anActiveMetrics.Add(aMetricsIterator.Value());
}
}
for (int aMetricId = (int)Message_MetricType_None + 1;
aMetricId <= (int)Message_MetricType_MemHeapUsage;
aMetricId++)
{
Message_MetricType aMetricType = (Message_MetricType)aMetricId;
QList<int> aMetricColumns;
aViewModel->GetMetricColumns(aMetricType, aMetricColumns);
bool isColumnHidden = !anActiveMetrics.Contains(aMetricType);
for (int i = 0; i < aMetricColumns.size(); i++)
{
int aColumnId = aMetricColumns[i];
myTreeView->setColumnHidden(aColumnId, isColumnHidden);
TreeModel_HeaderSection* aSection = aViewModel->ChangeHeaderItem(aColumnId);
aSection->SetIsHidden(isColumnHidden);
}
}
}
|