Some code cleanup and style fixing
svn path=/trunk/KDE/kdebase/workspace/; revision=961920icc-effect-5.14.5
parent
e4a80093b3
commit
07ada33d96
|
@ -33,23 +33,14 @@ KCMRulesList::KCMRulesList( QWidget* parent)
|
|||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
// connect both current/selected, so that current==selected (stupid QListBox :( )
|
||||
connect( rules_listbox, SIGNAL(itemChanged(QListWidgetItem*)),
|
||||
SLOT(activeChanged()));
|
||||
connect( rules_listbox, SIGNAL(itemSelectionChanged()),
|
||||
SLOT( activeChanged()));
|
||||
connect( new_button, SIGNAL( clicked()),
|
||||
SLOT( newClicked()));
|
||||
connect( modify_button, SIGNAL( clicked()),
|
||||
SLOT( modifyClicked()));
|
||||
connect( delete_button, SIGNAL( clicked()),
|
||||
SLOT( deleteClicked()));
|
||||
connect( moveup_button, SIGNAL( clicked()),
|
||||
SLOT( moveupClicked()));
|
||||
connect( movedown_button, SIGNAL( clicked()),
|
||||
SLOT( movedownClicked()));
|
||||
connect( rules_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem*) ),
|
||||
SLOT( modifyClicked()));
|
||||
connect(rules_listbox, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(activeChanged()));
|
||||
connect(rules_listbox, SIGNAL(itemSelectionChanged()), SLOT(activeChanged()));
|
||||
connect(new_button, SIGNAL(clicked()), SLOT(newClicked()));
|
||||
connect(modify_button, SIGNAL(clicked()), SLOT(modifyClicked()));
|
||||
connect(delete_button, SIGNAL(clicked()), SLOT(deleteClicked()));
|
||||
connect(moveup_button, SIGNAL(clicked()), SLOT(moveUpClicked()));
|
||||
connect(movedown_button, SIGNAL(clicked()), SLOT(moveDownClicked()));
|
||||
connect(rules_listbox, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(modifyClicked()));
|
||||
load();
|
||||
}
|
||||
|
||||
|
@ -67,8 +58,9 @@ void KCMRulesList::activeChanged()
|
|||
QListWidgetItem *item = rules_listbox->currentItem();
|
||||
int itemRow = rules_listbox->row(item);
|
||||
|
||||
if( item != NULL ) // make current==selected
|
||||
if (item != NULL) {
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
modify_button->setEnabled(item != NULL);
|
||||
delete_button->setEnabled(item != NULL);
|
||||
moveup_button->setEnabled(item != NULL && itemRow > 0);
|
||||
|
@ -79,8 +71,9 @@ void KCMRulesList::newClicked()
|
|||
{
|
||||
RulesDialog dlg(this);
|
||||
Rules* rule = dlg.edit(NULL, 0, false);
|
||||
if( rule == NULL )
|
||||
if (rule == NULL) {
|
||||
return;
|
||||
}
|
||||
int pos = rules_listbox->currentRow() + 1;
|
||||
rules_listbox->insertItem(pos , rule->description);
|
||||
rules_listbox->setCurrentRow(pos, QItemSelectionModel::ClearAndSelect);
|
||||
|
@ -91,12 +84,14 @@ void KCMRulesList::newClicked()
|
|||
void KCMRulesList::modifyClicked()
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
if ( pos == -1 )
|
||||
if (pos == -1) {
|
||||
return;
|
||||
}
|
||||
RulesDialog dlg(this);
|
||||
Rules* rule = dlg.edit(rules[ pos ], 0, false);
|
||||
if( rule == rules[ pos ] )
|
||||
if (rule == rules[ pos ]) {
|
||||
return;
|
||||
}
|
||||
delete rules[ pos ];
|
||||
rules[ pos ] = rule;
|
||||
rules_listbox->item(pos)->setText(rule->description);
|
||||
|
@ -112,12 +107,11 @@ void KCMRulesList::deleteClicked()
|
|||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::moveupClicked()
|
||||
void KCMRulesList::moveUpClicked()
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
assert(pos != -1);
|
||||
if( pos > 0 )
|
||||
{
|
||||
if (pos > 0) {
|
||||
QListWidgetItem * item = rules_listbox->takeItem(pos);
|
||||
rules_listbox->insertItem(pos - 1 , item);
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
|
@ -128,12 +122,11 @@ void KCMRulesList::moveupClicked()
|
|||
emit changed(true);
|
||||
}
|
||||
|
||||
void KCMRulesList::movedownClicked()
|
||||
void KCMRulesList::moveDownClicked()
|
||||
{
|
||||
int pos = rules_listbox->currentRow();
|
||||
assert(pos != -1);
|
||||
if( pos < int( rules_listbox->count()) - 1 )
|
||||
{
|
||||
if (pos < int(rules_listbox->count()) - 1) {
|
||||
QListWidgetItem * item = rules_listbox->takeItem(pos);
|
||||
rules_listbox->insertItem(pos + 1 , item);
|
||||
rules_listbox->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
|
||||
|
@ -158,17 +151,17 @@ void KCMRulesList::load()
|
|||
rules.reserve(count);
|
||||
for (int i = 1;
|
||||
i <= count;
|
||||
++i )
|
||||
{
|
||||
++i) {
|
||||
cfg = KConfigGroup(&_cfg, QString::number(i));
|
||||
Rules* rule = new Rules(cfg);
|
||||
rules.append(rule);
|
||||
rules_listbox->addItem(rule->description);
|
||||
}
|
||||
if( rules.count() > 0 )
|
||||
rules_listbox->setCurrentItem( rules_listbox->item( 0 ));
|
||||
else
|
||||
if (rules.count() > 0) {
|
||||
rules_listbox->setCurrentItem(rules_listbox->item(0), QItemSelectionModel::ClearAndSelect);
|
||||
} else {
|
||||
rules_listbox->setCurrentItem(NULL);
|
||||
}
|
||||
activeChanged();
|
||||
}
|
||||
|
||||
|
@ -184,8 +177,7 @@ void KCMRulesList::save()
|
|||
int i = 1;
|
||||
for (QVector< Rules* >::ConstIterator it = rules.constBegin();
|
||||
it != rules.constEnd();
|
||||
++it )
|
||||
{
|
||||
++it) {
|
||||
KConfigGroup cg(&cfg, QString::number(i));
|
||||
(*it)->write(cg);
|
||||
++i;
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef __RULESLIST_H__
|
||||
#define __RULESLIST_H__
|
||||
#ifndef RULESLIST__H
|
||||
#define RULESLIST__H
|
||||
|
||||
#include "../../rules.h"
|
||||
|
||||
|
@ -37,14 +37,14 @@ class KCMRulesList
|
|||
void load();
|
||||
void save();
|
||||
void defaults();
|
||||
signals:
|
||||
Q_SIGNALS:
|
||||
void changed(bool);
|
||||
private slots:
|
||||
private Q_SLOTS:
|
||||
void newClicked();
|
||||
void modifyClicked();
|
||||
void deleteClicked();
|
||||
void moveupClicked();
|
||||
void movedownClicked();
|
||||
void moveUpClicked();
|
||||
void moveDownClicked();
|
||||
void activeChanged();
|
||||
private:
|
||||
QVector< Rules* > rules;
|
||||
|
|
Loading…
Reference in New Issue