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();

}
/*!
  Sets the validation rule for the key \a key and sets the error
  message of it to \a errorMessage.
 */
void TFormValidator::setRule(const QString &key, Tf::ValidationRule rule, double val, const QString &errorMessage)
{
    // arg check
    switch ((int)rule) {
    case Tf::Required:
    case Tf::MaxLength:
    case Tf::MinLength:
    case Tf::IntMax:
    case Tf::IntMin:
    case Tf::EmailAddress:
    case Tf::Url:
    case Tf::Date:
    case Tf::Time:
    case Tf::DateTime:
        tWarn("Validation: Bad rule spedified [key:%s  rule:%d]. Use another setRule method.", qPrintable(key), rule);
        return;

    case Tf::Pattern:
        tWarn("Validation: Bad rule spedified [key:%s  rule:%d]. Use setPatternRule method.", qPrintable(key), rule);
        return;
    }

    removeRule(key, rule);
    rules.prepend(RuleEntry(key, (int)rule, val, (errorMessage.isEmpty() ? Tf::app()->validationErrorMessage(rule) : errorMessage)));
}
Beispiel #3
0
QaView::QaView(QWidget* parent)
 : QDockWidget ( i18nc("@title:window","Quality Assurance"), parent)
 , m_browser(new QTreeView(this))
{
    if (!QaModel::isInstantiated())
        QaModel::instance()->loadRules(Project::instance()->qaPath());
    m_qaModel=QaModel::instance();

    setWidget(m_browser);
    m_browser->setModel(m_qaModel);
    m_browser->setRootIsDecorated(false);
    m_browser->setContextMenuPolicy(Qt::ActionsContextMenu);

    QAction* action=new QAction(i18nc("@action:inmenu", "Add"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(addRule()));
    m_browser->addAction(action);

    action=new QAction(i18nc("@action:inmenu", "Remove"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(removeRule()));
    m_browser->addAction(action);
    
    m_browser->setAlternatingRowColors(true);
    
    connect(m_qaModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(rulesChanged()));
}
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 );

  treeRules->setRenderer( mRenderer );
  mRefineMenu = new QMenu( btnRefineRule );
  mRefineMenu->addAction( tr( "Add scales" ), this, SLOT( refineRuleScales() ) );
  mRefineMenu->addAction( tr( "Add categories" ), this, SLOT( refineRuleCategories() ) );
  mRefineMenu->addAction( tr( "Add ranges" ), this, SLOT( refineRuleRanges() ) );
  btnRefineRule->setMenu( mRefineMenu );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
  btnIncreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
  btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );

  connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
  connect( btnIncreasePriority, SIGNAL( clicked() ), this, SLOT( increasePriority() ) );
  connect( btnDecreasePriority, SIGNAL( clicked() ), this, SLOT( decreasePriority() ) );

  connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );

  // Make sure buttons are always in the correct state
  chkUsingFirstRule->setChecked( mRenderer->usingFirstRule() );
  chkEnableSymbolLevels->setChecked( mRenderer->usingSymbolLevels() );
  // If symbol levels are used, forcefully check and gray-out the chkUsingFirstRule checkbox
  if (mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); }
  connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() ));
  connect( chkEnableSymbolLevels, SIGNAL( clicked() ), this, SLOT( symbolLevelsEnabledChanged() ) );
  connect( this, SIGNAL( forceChkUsingFirstRule() ), this, SLOT( forceUsingFirstRule() ) );

  treeRules->populateRules();
}
Beispiel #5
0
int CategoryManager::removeRules(const RuleSet& ruleSet)
{
    int count = 0;
    for (int i = 0; i < ruleSet.maxNumRules(); ++i) {
        const Rule *rule = ruleSet.getRuleById(i);
        if (rule) {
            count += removeRule(*rule);
        }
    }
    return count;
}
Beispiel #6
0
bool RuleList::removeDomain(QString appName, QString domainName, unsigned int port)
{
	bool ret=true;

	QList<QString> ips=dnsRequest(domainName);
	for(int i=0;i<ips.size();i++)
		if(!removeRule(appName, ips[i], port))
			ret=false;

	return ret;
}
Beispiel #7
0
void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event)
{
    if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) {
        copyFilter();
    }

    if (event->key() == Qt::Key_Delete) {
        removeRule();
    }

    TreeWidget::keyPressEvent(event);
}
void QgsRuleBasedLabelingWidget::rejectRule()
{
  if ( mRuleProps->currentMode() == QgsLabelingRulePropsDialog::Adding )
    removeRule();

  mStackedWidget->setCurrentIndex( 0 );

  if ( mRuleProps )
    mStackedWidget->removeWidget( mRuleProps );

  delete mRuleProps;
  mRuleProps = nullptr;
  emit widgetChanged();
}
QgsRuleBasedLabelingWidget::QgsRuleBasedLabelingWidget( QgsVectorLayer* layer, QgsMapCanvas* canvas, QWidget* parent )
    : QgsPanelWidget( parent )
    , mLayer( layer )
    , mCanvas( canvas )
    , mRootRule( nullptr )
    , mModel( nullptr )
{
  setupUi( this );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );

  mCopyAction = new QAction( tr( "Copy" ), this );
  mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
  mPasteAction = new QAction( tr( "Paste" ), this );
  mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
  mDeleteAction = new QAction( tr( "Remove Rule" ), this );
  mDeleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) );

  viewRules->addAction( mDeleteAction );
  viewRules->addAction( mCopyAction );
  viewRules->addAction( mPasteAction );

  connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
  connect( mCopyAction, SIGNAL( triggered( bool ) ), this, SLOT( copy() ) );
  connect( mPasteAction, SIGNAL( triggered( bool ) ), this, SLOT( paste() ) );
  connect( mDeleteAction, SIGNAL( triggered( bool ) ), this, SLOT( removeRule() ) );

  if ( mLayer->labeling() && mLayer->labeling()->type() == "rule-based" )
  {
    const QgsRuleBasedLabeling* rl = static_cast<const QgsRuleBasedLabeling*>( mLayer->labeling() );
    mRootRule = rl->rootRule()->clone();
  }
  else
  {
    mRootRule = new QgsRuleBasedLabeling::Rule( nullptr );
  }

  mModel = new QgsRuleBasedLabelingModel( mRootRule );
  viewRules->setModel( mModel );

  connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SIGNAL( widgetChanged() ) );
  connect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SIGNAL( widgetChanged() ) );
  connect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SIGNAL( widgetChanged() ) );
}
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 );

  treeRules->setRenderer( mRenderer );

  mRefineMenu = new QMenu( btnRefineRule );
  mRefineMenu->addAction( tr( "Add scales" ), this, SLOT( refineRuleScales() ) );
  mRefineMenu->addAction( tr( "Add categories" ), this, SLOT( refineRuleCategories() ) );
  mRefineMenu->addAction( tr( "Add ranges" ), this, SLOT( refineRuleRanges() ) );
  btnRefineRule->setMenu( mRefineMenu );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );

  connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );

  connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );

  treeRules->populateRules();
}
Beispiel #11
0
void AdBlockTreeWidget::contextMenuRequested(const QPoint &pos)
{
    if (!m_subscription->canEditRules()) {
        return;
    }

    QTreeWidgetItem* item = itemAt(pos);
    if (!item) {
        return;
    }

    QMenu menu;
    menu.addAction(tr("Add Rule"), this, SLOT(addRule()));
    menu.addSeparator();
    QAction* deleteAction = menu.addAction(tr("Remove Rule"), this, SLOT(removeRule()));

    if (!item->parent()) {
        deleteAction->setDisabled(true);
    }

    menu.exec(viewport()->mapToGlobal(pos));
}
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();

}
/*!
  Sets the user-defined validaton rule for the key \a key and sets
  the error message of it to \a errorMessage.
 */
void TFormValidator::setPatternRule(const QString &key, const QRegExp &rx, const QString &errorMessage)
{
    removeRule(key, Tf::Pattern);
    rules.prepend(RuleEntry(key, Tf::Pattern, rx, (errorMessage.isEmpty() ? Tf::app()->validationErrorMessage(Tf::Pattern) : errorMessage)));
}