#include <QVBoxLayout>
#include <QtPlugin>
#include "DemoPlugin.h"
#include "TreeItemMarker.h"
using namespace demoplugin;
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( DemoPlugin, DemoPlugin );
#endif
DemoPlugin::DemoPlugin()
{
}
void
DemoPlugin::version( int& major, int& minor, int& bugfix ) const
{
major = 1;
minor = 0;
bugfix = 0;
}
QString
DemoPlugin::name() const
{
return "Simple Demo";
}
QString
DemoPlugin::getHelpText() const
{
return "Just a simple demo plugin";
}
bool
{
this->service = service;
widget_ = new QWidget();
qlabel_ = new QLabel( "demo example" );
QVBoxLayout* layout = new QVBoxLayout();
widget_->setLayout( layout );
layout->addWidget( qlabel_ );
QAction* menuAction = menu->addAction( "Demo Menu Item" );
connect( menuAction, SIGNAL( triggered() ), this, SLOT( menuItemIsSelected() ) );
connect( service, SIGNAL( globalValueChanged( QString ) ),
this, SLOT( globalValueChanged( QString ) ) );
connect( service, SIGNAL( orderHasChanged( const QList<cubepluginapi::DisplayType> & ) ),
this, SLOT( orderHasChanged( const QList<cubepluginapi::DisplayType> & ) ) );
defineTreeItemMarker();
return true;
}
void
DemoPlugin::cubeClosed()
{
delete widget_;
markerList.clear();
}
QString
DemoPlugin::label() const
{
return "Demo Plugin Label";
}
QIcon
DemoPlugin::icon() const
{
return QIcon( ":/icon.png" );
}
QWidget*
DemoPlugin::widget()
{
return widget_;
}
void
DemoPlugin::setActive( bool active )
{
if ( active )
{
service->
debug() <<
"setActive: last selected metric: " << txt << endl;
}
else
{
}
}
void
DemoPlugin::valuesChanged()
{
service->
debug() <<
"valuesChanged" << endl;
}
QSize
DemoPlugin::sizeHint() const
{
return QSize( 100, 100 );
}
void
{
service->
debug() <<
"valueModusChanged " << modus << endl;
}
void
DemoPlugin::loadGlobalSettings( QSettings& settings )
{
int numCalls = settings.value( "demoPluginCalls", 0 ).toInt();
service->
debug() <<
"loadSettings: " << numCalls << endl;
}
void
DemoPlugin::saveGlobalSettings( QSettings& settings )
{
int numCalls = settings.value( "DemoPluginCalls", 0 ).toInt();
settings.setValue( "DemoPluginCalls", ++numCalls );
}
QString
DemoPlugin::settingName()
{
return "demoPlugin";
}
void
DemoPlugin::contextMenuIsShown(
TreeType type, TreeItem* item )
{
if ( !item )
{
return;
}
contextItem = item;
contextTreeType = type;
QAction* contextAction = service->
addContextMenuItem( type,
"demo context menu item (no action)" );
QString text;
QTextStream st( &text );
st << "context for tree type " << type << " label " << item->getName();
connect( contextAction, SIGNAL( triggered() ), new DemoSlot( text ), SLOT( print() ) );
for ( int idx = 0; idx < markerList.size() / 2; idx++ )
{
contextAction = service->
addContextMenuItem( type,
"add marker " + QString::number( idx ) );
contextAction->setProperty( "index", idx );
connect( contextAction, SIGNAL( triggered() ), this, SLOT( setMarker() ) );
}
for ( int idx = markerList.size() / 2; idx < markerList.size(); idx++ )
{
contextAction = service->
addContextMenuItem( type,
"add marker for current selection " + QString::number( idx ) );
contextAction->setProperty( "index", idx );
connect( contextAction, SIGNAL( triggered() ), this, SLOT( setMarkerWithDependencies() ) );
}
}
void
DemoPlugin::setMarker()
{
int index = sender()->property( "index" ).toInt();
service->
addMarker( contextItem, markerList.at( index ) );
}
void
DemoPlugin::setMarkerWithDependencies()
{
int index = sender()->property( "index" ).toInt();
}
void
DemoPlugin::defineTreeItemMarker()
{
QStringList images;
images << ":images/left_small.png" << ":images/right_small.png" << ":images/up_small.png" << ":images/down_small.png";
for ( int i = 0; i < images.size(); i++ )
{
QList<QPixmap> icons;
icons.append( QPixmap( images.at( i ) ) );
bool insignificantMarker = i == images.size() - 1 ? 1 : 0;
if ( insignificantMarker )
{
markerList.append( service->
getTreeItemMarker(
"insignificant marker", icons,
true ) );
}
else
{
markerList.append( service->
getTreeItemMarker(
"marker" + QString::number( i ), icons ) );
}
}
}
void
DemoPlugin::treeItemIsSelected(
TreeType, TreeItem* item )
{
QString txt = item->getName() +
" " + service->
formatNumber( item->getValue() );
qlabel_->setText( txt );
service->
debug() <<
"treeItemIsSelected " << txt << item->getCubeObject() << endl;
if ( item->isAggregatedLoopItem() )
{
QList<cube::Cnode*> iterations = ( static_cast<AggregatedTreeItem*> ( item ) )->getIterations();
int min = std::min( 10, iterations.size() );
if ( min > 0 )
{
service->
debug() <<
"selected loop item: cnode_ids of first 10 iterations:" << endl;
}
for ( int i = 0; i < min; i++ )
{
cube::Cnode* cnode = iterations.at( i );
service->
debug() << cnode->get_id() << endl;
}
}
if ( item->getCubeObject() == 0 )
{
service->
debug() <<
"selected aggregated item" << item->getName() << endl;
}
else
{
cube::Cnode* cnode = static_cast<cube::Cnode*> ( item->getCubeObject() );
service->
debug() <<
"selected single item: " << cnode->get_id() << endl;
}
}
void
DemoPlugin::orderHasChanged( const QList<DisplayType>& order )
{
service->
debug() <<
"orderHasChanged user has changed the dimension order" << endl;
bool enabled = order.at( 0 ) !=
SYSTEM;
}
void
DemoPlugin::globalValueChanged( const QString& name )
{
service->
debug() <<
"globalValueChanged " << name << service->
getGlobalValue(
"testVal" ).toString() << endl;
}
void
DemoPlugin::menuItemIsSelected()
{
service->
debug() <<
"menu item is selected and global value incremented" << endl;
}
void
{
{
service->
debug() <<
"user has marked tree item as loop" << endl;
}
}