Added a "General" and "Teams" page to the main window.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30412 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-04-25 20:51:37 +00:00
parent 31391fed6b
commit ca98712224
8 changed files with 287 additions and 4 deletions
@@ -0,0 +1,62 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "main_window/GeneralPage.h"
#include <stdio.h>
MainWindow::GeneralPage::GeneralPage()
:
AbstractGeneralPage(),
fModel(NULL),
fDataSourceView(NULL),
fRunTimeView(NULL),
fTeamCountView(NULL),
fThreadCountView(NULL)
{
fDataSourceView = AddDataView("Data Source:");
fRunTimeView = AddDataView("Run Time:");
fTeamCountView = AddDataView("Teams:");
fThreadCountView = AddDataView("Threads:");
}
MainWindow::GeneralPage::~GeneralPage()
{
}
void
MainWindow::GeneralPage::SetModel(Model* model)
{
if (model == fModel)
return;
fModel = model;
if (fModel != NULL) {
// data source
fDataSourceView->SetText(fModel->DataSourceName());
// run time
char buffer[128];
snprintf(buffer, sizeof(buffer), "%lld μs", fModel->LastEventTime());
fRunTimeView->SetText(buffer);
// team count
snprintf(buffer, sizeof(buffer), "%ld", fModel->CountTeams());
fTeamCountView->SetText(buffer);
// threads
snprintf(buffer, sizeof(buffer), "%ld", fModel->CountThreads());
fThreadCountView->SetText(buffer);
} else {
fDataSourceView->SetText("");
fRunTimeView->SetText("");
fTeamCountView->SetText("");
fThreadCountView->SetText("");
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef MAIN_GENERAL_PAGE_H
#define MAIN_GENERAL_PAGE_H
#include "AbstractGeneralPage.h"
#include "main_window/MainWindow.h"
class TextDataView;
class MainWindow::GeneralPage : public AbstractGeneralPage {
public:
GeneralPage();
virtual ~GeneralPage();
void SetModel(Model* model);
private:
Model* fModel;
TextDataView* fDataSourceView;
TextDataView* fRunTimeView;
TextDataView* fTeamCountView;
TextDataView* fThreadCountView;
};
#endif // MAIN_GENERAL_PAGE_H
@@ -8,6 +8,8 @@ UseHeaders $(HAIKU_DEBUG_ANALYZER_HEADERS) ;
MergeObject DebugAnalyzer_gui_main_window.o
:
GeneralPage.cpp
MainWindow.cpp
TeamsPage.cpp
ThreadsPage.cpp
;
@@ -21,7 +21,10 @@
#include "ModelLoader.h"
#include "SubWindowManager.h"
#include "main_window/GeneralPage.h"
#include "main_window/TeamsPage.h"
#include "main_window/ThreadsPage.h"
#include "thread_window/ThreadWindow.h"
@@ -30,6 +33,8 @@ MainWindow::MainWindow(DataSource* dataSource)
BWindow(BRect(50, 50, 599, 499), "DebugAnalyzer", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS),
fMainTabView(NULL),
fGeneralPage(NULL),
fTeamsPage(NULL),
fThreadsPage(NULL),
fModel(NULL),
fModelLoader(NULL),
@@ -45,7 +50,8 @@ MainWindow::MainWindow(DataSource* dataSource)
BGroupLayoutBuilder(rootLayout)
.Add(fMainTabView);
fMainTabView->AddTab(new BView("Teams", 0));
fMainTabView->AddTab(fGeneralPage = new GeneralPage);
fMainTabView->AddTab(fTeamsPage = new TeamsPage(this));
fMainTabView->AddTab(fThreadsPage = new ThreadsPage(this));
// create a model loader, if we have a data source
@@ -126,6 +132,13 @@ MainWindow::Show()
}
void
MainWindow::OpenTeamWindow(Model::Team* team)
{
// TODO:...
}
void
MainWindow::OpenThreadWindow(Model::Thread* thread)
{
@@ -179,5 +192,7 @@ MainWindow::_SetModel(Model* model)
if (fModel != NULL)
fModel->AddReference();
fGeneralPage->SetModel(fModel);
fTeamsPage->SetModel(fModel);
fThreadsPage->SetModel(fModel);
}
@@ -27,9 +27,12 @@ public:
virtual void Show();
void OpenTeamWindow(Model::Team* team);
void OpenThreadWindow(Model::Thread* thread);
private:
class GeneralPage;
class TeamsPage;
class ThreadsPage;
private:
@@ -37,6 +40,8 @@ private:
private:
BTabView* fMainTabView;
GeneralPage* fGeneralPage;
TeamsPage* fTeamsPage;
ThreadsPage* fThreadsPage;
Model* fModel;
ModelLoader* fModelLoader;
@@ -0,0 +1,129 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "main_window/TeamsPage.h"
#include <stdio.h>
#include <new>
#include "table/TableColumns.h"
// #pragma mark - TeamsTableModel
class MainWindow::TeamsPage::TeamsTableModel : public TableModel {
public:
TeamsTableModel(Model* model)
:
fModel(model)
{
}
virtual int32 CountColumns() const
{
return 4;
}
virtual int32 CountRows() const
{
return fModel->CountTeams();
}
virtual bool GetValueAt(int32 rowIndex, int32 columnIndex, Variant& value)
{
Model::Team* team = fModel->TeamAt(rowIndex);
if (team == NULL)
return false;
switch (columnIndex) {
case 0:
value.SetTo(team->ID());
return true;
case 1:
value.SetTo(team->Name(), VARIANT_DONT_COPY_DATA);
return true;
case 2:
value.SetTo(team->CreationTime());
return true;
case 3:
value.SetTo(team->DeletionTime());
return true;
default:
return false;
}
}
private:
Model* fModel;
};
// #pragma mark - TeamsPage
MainWindow::TeamsPage::TeamsPage(MainWindow* parent)
:
BGroupView(B_VERTICAL),
fParent(parent),
fTeamsTable(NULL),
fTeamsTableModel(NULL),
fModel(NULL)
{
SetName("Teams");
fTeamsTable = new Table("teams list", 0);
AddChild(fTeamsTable->ToView());
fTeamsTable->AddColumn(new Int32TableColumn(0, "ID", 40, 20, 1000,
B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT));
fTeamsTable->AddColumn(new StringTableColumn(1, "Name", 80, 40, 1000,
B_TRUNCATE_END, B_ALIGN_LEFT));
fTeamsTable->AddColumn(new BigtimeTableColumn(2, "Creation", 80, 40, 1000,
true, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT));
fTeamsTable->AddColumn(new BigtimeTableColumn(3, "Deletion", 80, 40, 1000,
false, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT));
fTeamsTable->AddTableListener(this);
}
MainWindow::TeamsPage::~TeamsPage()
{
fTeamsTable->SetTableModel(NULL);
delete fTeamsTableModel;
}
void
MainWindow::TeamsPage::SetModel(Model* model)
{
if (model == fModel)
return;
if (fModel != NULL) {
fTeamsTable->SetTableModel(NULL);
delete fTeamsTableModel;
fTeamsTableModel = NULL;
}
fModel = model;
if (fModel != NULL) {
fTeamsTableModel = new(std::nothrow) TeamsTableModel(fModel);
fTeamsTable->SetTableModel(fTeamsTableModel);
}
}
void
MainWindow::TeamsPage::TableRowInvoked(Table* table, int32 rowIndex)
{
Model::Team* team = fModel->TeamAt(rowIndex);
if (team != NULL)
fParent->OpenTeamWindow(team);
}
@@ -0,0 +1,38 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef MAIN_TEAMS_PAGE_H
#define MAIN_TEAMS_PAGE_H
#include <GroupView.h>
#include "table/Table.h"
#include "main_window/MainWindow.h"
class MainWindow::TeamsPage : public BGroupView, private TableListener {
public:
TeamsPage(MainWindow* parent);
virtual ~TeamsPage();
void SetModel(Model* model);
private:
class TeamsTableModel;
private:
// TableListener
virtual void TableRowInvoked(Table* table, int32 rowIndex);
private:
MainWindow* fParent;
Table* fTeamsTable;
TeamsTableModel* fTeamsTableModel;
Model* fModel;
};
#endif // MAIN_TEAMS_PAGE_H
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef THREADS_PAGE_H
#define THREADS_PAGE_H
#ifndef MAIN_THREADS_PAGE_H
#define MAIN_THREADS_PAGE_H
#include <GroupView.h>
@@ -35,4 +35,4 @@ private:
#endif // THREADS_PAGE_H
#endif // MAIN_THREADS_PAGE_H