QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) : QgsRendererV2Widget( layer, style ) { // try to recognize the previous renderer // (null renderer means "no previous renderer") if ( !renderer || renderer->type() != "RuleRenderer" ) { // we're not going to use it - so let's delete the renderer delete renderer; // some default options QgsSymbolV2* symbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() ); mRenderer = new QgsRuleBasedRendererV2( symbol ); } else { mRenderer = static_cast<QgsRuleBasedRendererV2*>( renderer ); } setupUi( this ); mModel = new QgsRuleBasedRendererV2Model( mRenderer ); //new ModelTest( mModel, this ); // for model validity checking viewRules->setModel( mModel ); mRefineMenu = new QMenu( "Refine current rule", btnRefineRule ); mRefineMenu->addAction( tr( "Add scales to rule" ), this, SLOT( refineRuleScales() ) ); mRefineMenu->addAction( tr( "Add categories to rule" ), this, SLOT( refineRuleCategories() ) ); mRefineMenu->addAction( tr( "Add ranges to rule" ), this, SLOT( refineRuleRanges() ) ); btnRefineRule->setMenu( mRefineMenu ); contextMenu->addMenu( mRefineMenu ); btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) ); btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) ); btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) ); connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) ); // support for context menu (now handled generically) connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) ); connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) ); connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) ); connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) ); connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) ); connect( btnCountFeatures, SIGNAL( clicked() ), this, SLOT( countFeatures() ) ); connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) ); currentRuleChanged(); // store/restore header section widths connect( viewRules->header(), SIGNAL( sectionResized( int, int, int ) ), this, SLOT( saveSectionWidth( int, int, int ) ) ); restoreSectionWidths(); }
DataSet::DataSet(ContextVector const &contexts) : d_contexts(contexts), d_nFeatures(0) { countFeatures(); removeStaticFeatures(); normalize(); buildFeatureMap(); d_expFeatureValues = fsqueeze::expFeatureValues(d_features, d_nFeatures); }
/*------------------------------------------------------------------*/ void AzSvDataS::readData_Large(const char *data_fn, int expected_f_num, /*--- output ---*/ AzSmat *m_feat, int max_data_num) { const char *eyec = "AzSvDataS::readData_Large"; /*--- find the number of lines and the maximum line length ---*/ AzIntArr ia_line_len; AzFile::scan(data_fn, 1024*1024, &ia_line_len, max_data_num+1); /* +1 for sparse indicator */ int data_num = ia_line_len.size(); int max_line_len = ia_line_len.max(); if (data_num <= 0) { throw new AzException(AzInputNotValid, eyec, "Empty data"); } AzBytArr ba_buff; AzByte *buff = ba_buff.reset(max_line_len+256, 0); /* +256 just in case */ /*--- 1st line indicates sparse/dense ---*/ AzFile file(data_fn); file.open("rb"); int line0_len = file.gets(buff, max_line_len); AzBytArr s_line0(buff, line0_len); int line_no = 0; bool isSparse = false; int f_num = if_sparse(s_line0, expected_f_num); if (f_num > 0) { isSparse = true; --data_num; /* b/c 1st line is information */ if (data_num <= 0) { throw new AzException(AzInputNotValid, eyec, "Empty sparse data file"); } line_no = 1; /* first data line */ } else { f_num = expected_f_num; if (f_num <= 0) { const AzByte *line0 = s_line0.point(); f_num = countFeatures(line0, line0+line0_len); } if (f_num <= 0) { throw new AzException(AzInputNotValid, eyec, "No feature in the first line"); } file.seek(0); /* rewind to the beginning */ } /*--- read features ---*/ if (max_data_num > 0) { data_num = MIN(data_num, max_data_num); } m_feat->reform(f_num, data_num); int dx; for (dx = 0; dx < data_num; ++dx, ++line_no) { int len = ia_line_len.get(line_no); file.readBytes(buff, len); buff[len] = '\0'; /* to make it a C string */ if (isSparse) { parseDataLine_Sparse(buff, len, f_num, data_fn, line_no+1, m_feat, dx); } else { parseDataLine(buff, len, f_num, data_fn, line_no+1, m_feat, dx); } } file.close(); }
QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) : QgsRendererV2Widget( layer, style ) { mRenderer = 0; // try to recognize the previous renderer // (null renderer means "no previous renderer") if ( renderer ) { mRenderer = QgsRuleBasedRendererV2::convertFromRenderer( renderer ); } if ( !mRenderer ) { // some default options QgsSymbolV2* symbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() ); mRenderer = new QgsRuleBasedRendererV2( symbol ); } setupUi( this ); mModel = new QgsRuleBasedRendererV2Model( mRenderer ); #ifdef ENABLE_MODELTEST new ModelTest( mModel, this ); // for model validity checking #endif viewRules->setModel( mModel ); mDeleteAction = new QAction( tr( "Remove Rule" ), this ); mDeleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) ); viewRules->addAction( mDeleteAction ); viewRules->addAction( mCopyAction ); viewRules->addAction( mPasteAction ); mRefineMenu = new QMenu( tr( "Refine current rule" ), btnRefineRule ); mRefineMenu->addAction( tr( "Add scales to rule" ), this, SLOT( refineRuleScales() ) ); mRefineMenu->addAction( tr( "Add categories to rule" ), this, SLOT( refineRuleCategories() ) ); mRefineMenu->addAction( tr( "Add ranges to rule" ), this, SLOT( refineRuleRanges() ) ); btnRefineRule->setMenu( mRefineMenu ); contextMenu->addMenu( mRefineMenu ); btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) ); btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) ); btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) ); connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) ); // support for context menu (now handled generically) connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) ); connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) ); connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) ); connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) ); connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) ); connect( mDeleteAction, SIGNAL( triggered() ), this, SLOT( removeRule() ) ); connect( btnCountFeatures, SIGNAL( clicked() ), this, SLOT( countFeatures() ) ); connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) ); currentRuleChanged(); // store/restore header section widths connect( viewRules->header(), SIGNAL( sectionResized( int, int, int ) ), this, SLOT( saveSectionWidth( int, int, int ) ) ); restoreSectionWidths(); }
/*------------------------------------------------------------------*/ void AzSvDataS::readData_Small(const char *data_fn, int expected_f_num, /*--- output ---*/ AzSmat *m_feat) { const char *eyec = "AzSvDataS::readData_Small"; AzFile file(data_fn); file.open("rb"); int file_size = file.size(); AzBytArr bq_data; AzByte *data = bq_data.reset(file_size+1, 0); file.seekReadBytes(0, file_size, data); file.close(); const char *data_end = (char *)data + file_size; const char *wp = (char *)data; AzIIarr iia_begin_end; for ( ; ; ) { if (wp >= data_end) break; const char *next_wp = strchr(wp, '\n'); if (next_wp == NULL) next_wp = data_end; iia_begin_end.put(Az64::ptr_diff(wp-(char *)data), Az64::ptr_diff(next_wp-(char *)data)); wp = next_wp+1; } int data_num = iia_begin_end.size(); if (data_num <= 0) { throw new AzException(AzInputNotValid, eyec, "Empty data"); } bool isSparse = false; int offs0, offs1; iia_begin_end.get(0, &offs0, &offs1); AzBytArr s_first_line(data+offs0, offs1-offs0); int f_num = if_sparse(s_first_line, expected_f_num); if (f_num > 0) { isSparse = true; --data_num; /* b/c 1st line is information */ if (data_num <= 0) { throw new AzException(AzInputNotValid, eyec, "Empty sparse data file"); } } else { f_num = expected_f_num; if (f_num <= 0) { f_num = countFeatures(data+offs0, data+offs1); } if (f_num <= 0) { throw new AzException(AzInputNotValid, eyec, "No feature in the first line"); } } m_feat->reform(f_num, data_num); /*--- read features ---*/ int dx; for (dx = 0; dx < data_num; ++dx) { int line_no = dx + 1; if (isSparse) { int offs0, offs1; iia_begin_end.get(dx+1, &offs0, &offs1); /* +1 for 1st line */ parseDataLine_Sparse(data+offs0, offs1-offs0, f_num, data_fn, line_no+1, /* "+1" for the header */ m_feat, dx); } else { int offs0, offs1; iia_begin_end.get(dx, &offs0, &offs1); parseDataLine(data+offs0, offs1-offs0, f_num, data_fn, line_no, m_feat, dx); } } }