Ticket #6662: combosetting_labels_r20746.patch

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

     
    623623    for(unsigned int i = 0 ; i < labels.size() ; ++i)
    624624        cbwidget->insertItem(labels[i]);
    625625
     626    cbwidget->setMaxCount(cbwidget->count() + rw);
     627
    626628    if (isSet)
    627629        cbwidget->setCurrentIndex(current);
    628630
    629631    if (1 < step)
    630632        cbwidget->setStep(step);
    631633
     634    connect(cbwidget, SIGNAL(highlighted(int)),
     635            this, SLOT(setValue(int)));
     636    connect(cbwidget, SIGNAL(activated(int)),
     637            this, SLOT(setValue(int)));
     638    connect(this, SIGNAL(selectionsCleared()),
     639            cbwidget, SLOT(clear()));
     640
    632641    if (rw)
    633     {
    634         connect(cbwidget, SIGNAL(highlighted(const QString &)),
    635                 this, SLOT(setValue(const QString &)));
    636         connect(cbwidget, SIGNAL(activated(const QString &)),
    637                 this, SLOT(setValue(const QString &)));
    638642        connect(cbwidget, SIGNAL(editTextChanged(const QString &)),
    639                 this, SLOT(setValue(const QString &)));
    640     }
    641     else
    642     {
    643         connect(cbwidget, SIGNAL(highlighted(int)),
    644                 this, SLOT(setValue(int)));
    645         connect(cbwidget, SIGNAL(activated(int)),
    646                 this, SLOT(setValue(int)));
    647     }
     643                this, SLOT(editTextChanged(const QString &)));
    648644
    649     connect(this, SIGNAL(selectionsCleared()),
    650             cbwidget, SLOT(clear()));
    651 
    652645    if (cg)
    653646        connect(cbwidget, SIGNAL(changeHelpText(QString)), cg,
    654647                SIGNAL(changeHelpText(QString)));
     
    706699        if (cbwidget)
    707700            cbwidget->setCurrentIndex(current);
    708701    }
    709 };
     702}
    710703
    711704void ComboBoxSetting::setValue(int which)
    712705{
    713706    if (cbwidget)
    714707        cbwidget->setCurrentIndex(which);
    715708    SelectSetting::setValue(which);
    716 };
     709}
    717710
    718711void ComboBoxSetting::addSelection(
    719712    const QString &label, QString value, bool select)
     
    749742    return false;
    750743}
    751744
     745void ComboBoxSetting::editTextChanged(const QString &newText)
     746{
     747    if (cbwidget)
     748    {
     749        for (uint i = 0; i < labels.size(); i++)
     750            if (labels[i] == newText)
     751                return;
     752
     753        if (labels.size() == static_cast<size_t>(cbwidget->maxCount()))
     754        {
     755            SelectSetting::removeSelection(labels[cbwidget->maxCount() - 1],
     756                                           values[cbwidget->maxCount() - 1]);
     757            cbwidget->setItemText(cbwidget->maxCount() - 1, newText);
     758        }
     759        else
     760        {
     761            cbwidget->insertItem(newText);
     762        }
     763
     764        SelectSetting::addSelection(newText, newText, true);
     765        cbwidget->setCurrentIndex(cbwidget->maxCount() - 1);
     766    }
     767}
     768
    752769void ComboBoxSetting::setHelpText(const QString &str)
    753770{
    754771    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;