#include <QVBoxLayout>
#include <QtPlugin>
#include "DemoPlugin.h"
#include "TreeItemMarker.h"
using namespace demoplugin;
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();
QVBoxLayout* layout = new QVBoxLayout();
layout->addSpacing( 20 );
qlabel_ = new QLabel( "Selected tree item:" );
layout->addWidget( qlabel_ );
layout->addWidget( new QLabel( "Text to be saved in settings:" ) );
lineEdit_ = new QLineEdit();
lineEdit_->setToolTip( "If File->Settings->Restore last state is active, the text ist persistant. The state is also saved in bookmarks." );
layout->addWidget( lineEdit_ );
layout->addStretch( 1 );
widget_->setLayout( layout );
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 Tab";
}
QIcon
DemoPlugin::icon() const
{
return QIcon( ":/icon.png" );
}
QWidget*
DemoPlugin::widget()
{
return widget_;
}
void
DemoPlugin::setActive( bool active )
{
if ( active )
{
connect( service, SIGNAL( treeItemIsSelected( cubepluginapi::TreeItem* ) ),
this, SLOT( treeItemIsSelected( cubepluginapi::TreeItem* ) ) );
service->
debug() <<
"setActive: last selected metric: " << txt << Qt::endl;
}
else
{
service->disconnect( SIGNAL( treeItemIsSelected( cubepluginapi::TreeItem* ) ) );
}
}
void
DemoPlugin::valuesChanged()
{
service->
debug() <<
"valuesChanged" << Qt::endl;
}
QSize
DemoPlugin::sizeHint() const
{
return QSize( 100, 100 );
}
void
{
service->
debug() <<
"valueModusChanged " << modus << Qt::endl;
}
void
{
if ( !item )
{
return;
}
contextItem = item;
contextType = type;
QAction* contextAction = service->
addContextMenuItem( type,
"demo context menu item (no action)" );
QString text;
QTextStream st( &text );
st << "context for tree type " << item->getDisplayType() << " 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( TreeItem* item )
{
QString txt = item->getName() +
" " + service->
formatNumber( item->getValue() );
qlabel_->setText( "Selected tree item: " + txt );
service->
debug() <<
"treeItemIsSelected " << txt << item->getCubeObject() << Qt::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:" << Qt::endl;
}
for ( int i = 0; i < min; i++ )
{
cube::Cnode* cnode = iterations.at( i );
service->
debug() << cnode->get_id() << Qt::endl;
}
}
if ( item->getCubeObject() == 0 )
{
service->
debug() <<
"selected aggregated item" << item->getName() << Qt::endl;
}
else
{
cube::Cnode* cnode = static_cast<cube::Cnode*> ( item->getCubeObject() );
service->
debug() <<
"selected single item: " << cnode->get_id() << Qt::endl;
}
}
void
DemoPlugin::orderHasChanged( const QList<DisplayType>& order )
{
service->
debug() <<
"orderHasChanged user has changed the dimension order" << Qt::endl;
bool enabled = order.at( 0 ) !=
SYSTEM;
}
void
DemoPlugin::globalValueChanged( const QString& name )
{
service->
debug() <<
"globalValueChanged " << name << service->
getGlobalValue( this->name() +
"::testVal" ).toString() << Qt::endl;
}
void
DemoPlugin::menuItemIsSelected()
{
service->
debug() <<
"menu item is selected and global value incremented" << Qt::endl;
int val = service->
getGlobalValue( this->name() +
"::testVal" ).toInt();
service->
setGlobalValue( this->name() +
"::testVal", QVariant( ++val ),
true );
}
void
{
{
service->
debug() <<
"user has marked tree item as loop" << Qt::endl;
}
}
void
DemoPlugin::loadGlobalSettings( QSettings& settings )
{
int numCalls = settings.value( "DemoPluginCalls", 0 ).toInt();
service->
debug() <<
"load global Settings: " << numCalls << Qt::endl;
}
void
DemoPlugin::saveGlobalSettings( QSettings& settings )
{
int numCalls = settings.value( "DemoPluginCalls", 0 ).toInt();
settings.setValue( "DemoPluginCalls", ++numCalls );
}
void
DemoPlugin::loadExperimentSettings( QSettings& settings )
{
lineEdit_->setText( settings.value( "Text", "Text to be saved" ).toString() );
}
void
DemoPlugin::saveExperimentSettings( QSettings& settings )
{
settings.setValue( "Text", lineEdit_->text() );
}
QString
DemoPlugin::settingName()
{
return "DemoPlugin";
}