Ticket #6662: combosetting_labels_r23492.patch

File combosetting_labels_r23492.patch, 3.2 KB (added by mythtv@…, 14 years ago)
  • libs/libmyth/settings.cpp

     
    643643    for(unsigned int i = 0 ; i < labels.size() ; ++i)
    644644        cbwidget->insertItem(labels[i]);
    645645
     646    cbwidget->setMaxCount(cbwidget->count() + rw);
     647
    646648    if (isSet)
    647649        cbwidget->setCurrentIndex(current);
    648650
    649651    if (1 < step)
    650652        cbwidget->setStep(step);
    651653
     654    connect(cbwidget, SIGNAL(highlighted(int)),
     655            this, SLOT(setValue(int)));
     656    connect(cbwidget, SIGNAL(activated(int)),
     657            this, SLOT(setValue(int)));
     658    connect(this, SIGNAL(selectionsCleared()),
     659            cbwidget, SLOT(clear()));
     660
    652661    if (rw)
    653     {
    654         connect(cbwidget, SIGNAL(highlighted(const QString &)),
    655                 this, SLOT(setValue(const QString &)));
    656         connect(cbwidget, SIGNAL(activated(const QString &)),
    657                 this, SLOT(setValue(const QString &)));
    658662        connect(cbwidget, SIGNAL(editTextChanged(const QString &)),
    659                 this, SLOT(setValue(const QString &)));
    660     }
    661     else
    662     {
    663         connect(cbwidget, SIGNAL(highlighted(int)),
    664                 this, SLOT(setValue(int)));
    665         connect(cbwidget, SIGNAL(activated(int)),
    666                 this, SLOT(setValue(int)));
    667     }
     663                this, SLOT(editTextChanged(const QString &)));
    668664
    669     connect(this, SIGNAL(selectionsCleared()),
    670             cbwidget, SLOT(clear()));
    671 
    672665    if (cg)
    673666        connect(cbwidget, SIGNAL(changeHelpText(QString)), cg,
    674667                SIGNAL(changeHelpText(QString)));
     
    728721        if (cbwidget)
    729722            cbwidget->setCurrentIndex(current);
    730723    }
    731 };
     724}
    732725
    733726void ComboBoxSetting::setValue(int which)
    734727{
    735728    if (cbwidget)
    736729        cbwidget->setCurrentIndex(which);
    737730    SelectSetting::setValue(which);
    738 };
     731}
    739732
    740733void ComboBoxSetting::addSelection(
    741734    const QString &label, QString value, bool select)
     
    771764    return false;
    772765}
    773766
     767void ComboBoxSetting::editTextChanged(const QString &newText)
     768{
     769    if (cbwidget)
     770    {
     771        for (uint i = 0; i < labels.size(); i++)
     772            if (labels[i] == newText)
     773                return;
     774
     775        if (labels.size() == static_cast<size_t>(cbwidget->maxCount()))
     776        {
     777            SelectSetting::removeSelection(labels[cbwidget->maxCount() - 1],
     778                                           values[cbwidget->maxCount() - 1]);
     779            cbwidget->setItemText(cbwidget->maxCount() - 1, newText);
     780        }
     781        else
     782        {
     783            cbwidget->insertItem(newText);
     784        }
     785
     786        SelectSetting::addSelection(newText, newText, true);
     787        cbwidget->setCurrentIndex(cbwidget->maxCount() - 1);
     788    }
     789}
     790
    774791void ComboBoxSetting::setHelpText(const QString &str)
    775792{
    776793    if (cbwidget)
  • libs/libmyth/settings.h

     
    341341                      bool select = false);
    342342    bool removeSelection(const QString &label,
    343343                         QString value = QString::null);
     344    void editTextChanged(const QString &newText);
    344345
    345346private:
    346347    bool rw;