Code Search for Developers
 
 
  

OutputWindow.cpp from Make Controller at Krugle


Show OutputWindow.cpp syntax highlighted

/*********************************************************************************

 Copyright 2006 MakingThings

 Licensed under the Apache License, 
 Version 2.0 (the "License"); you may not use this file except in compliance 
 with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0 
 
 Unless required by applicable law or agreed to in writing, software distributed
 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 CONDITIONS OF ANY KIND, either express or implied. See the License for
 the specific language governing permissions and limitations under the License.

*********************************************************************************/

#include "OutputWindow.h"
#include <QColor>

OutputWindow::OutputWindow(QObject *parent) : QAbstractTableModel( parent )
{ 

}

Qt::ItemFlags OutputWindow::flags( const QModelIndex index )
{
	(void) index;
	return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}

QVariant OutputWindow::data( const QModelIndex & index, int role ) const
{
	if (!index.isValid() || index.row() > tableEntries.count( ) )
		return QVariant();
		
	if( role == Qt::DisplayRole ) // the text that should be written
	{
		switch( index.column( ) )
		{
			case 0:
				return tableEntries.at( index.row() )->column0;
			case 1:
				return tableEntries.at( index.row() )->column1;
			case 2:
				return tableEntries.at( index.row() )->column2;
		}
	}
	
	if( role == Qt::BackgroundRole ) // the background color
	{
		switch( tableEntries.at( index.row() )->type )
		{
			case MessageEvent::Info:
			case MessageEvent::Notice:
				return QColor(235, 235, 235, 235); // light-light grey
			case MessageEvent::Response:
				return QColor( Qt::white );
			case MessageEvent::Error:
				return QColor(255, 221, 221, 255); // Red
			case MessageEvent::Warning:
				return QColor(255, 228, 118, 255); // Orange
			case MessageEvent::Command:
				return QColor(229, 237, 247, 255); // Blue
			case MessageEvent::XMLMessage:
				return QColor(219, 250, 224, 255); // Green
		}
	}
	
	if( role == Qt::ForegroundRole ) // the text color
	{
		if( index.column( ) == 2 ) // timestamp column
			return Qt::gray;
	}
	
	return QVariant( );
}

void OutputWindow::newRows( QList<TableEntry*> entries )
{
	int newRows = entries.count( );
	int currentRows = tableEntries.count( );
	beginInsertRows( QModelIndex(), currentRows, currentRows + newRows - 1 );
	for( int i = 0; i < newRows; i++ )
		tableEntries.append( entries.at(i) );
	endInsertRows( );
}

void OutputWindow::clear( )
{
	beginRemoveRows( QModelIndex(), 0, tableEntries.count( ) - 1 );
	qDeleteAll( tableEntries );
	tableEntries.clear( );
	endRemoveRows( );
}

QVariant OutputWindow::headerData( int section, Qt::Orientation orientation, int role ) const
{
	(void) section;
	(void) orientation;
	(void) role;
	return QVariant( );
}

int OutputWindow::rowCount( const QModelIndex & parent ) const
{
	(void) parent;
	return tableEntries.count( );
}

int OutputWindow::columnCount( const QModelIndex & parent ) const
{
	(void) parent;
	return 3;
}











See more files for this project here

Make Controller

The Make Controller is an open microcontroller platform for Makers of all kinds, by MakingThings. This project maintains the official firmware for the board and source for the software tools used with the board.

Project homepage: http://sourceforge.net/projects/makingthings
Programming language(s): C,C#,C++
License: other

  layouts/
    mchelper.ui
    mchelperPrefs.ui
  linux_driver/
    Makefile
    at91.c
    at91.mod.c
  Board.cpp
  Board.h
  BoardArrivalEvent.h
  IconPackageOSX.icns
  McHelperWindow.cpp
  McHelperWindow.h
  MessageEvent.cpp
  MessageEvent.h
  MessageInterface.h
  MonitorInterface.h
  NetworkMonitor.cpp
  NetworkMonitor.h
  Osc.cpp
  Osc.h
  OscXmlServer.cpp
  OscXmlServer.h
  OutputWindow.cpp
  OutputWindow.h
  PacketInterface.h
  PacketReadyInterface.h
  PacketUdp.cpp
  PacketUdp.h
  PacketUsbCdc.cpp
  PacketUsbCdc.h
  ReadMe.rtf
  Samba.cpp
  Samba.h
  SambaMonitor.cpp
  SambaMonitor.h
  UploaderThread.cpp
  UploaderThread.h
  UsbMonitor.cpp
  UsbMonitor.h
  UsbSerial.cpp
  UsbSerial.h
  guid829.h
  loader256_data.h
  main.cpp
  mchelper.pro
  mchelper.qrc
  mchelper.rc
  mchelper_icon.ico
  mticon128.png