rangeselectimpl.cpp

Go to the documentation of this file.
00001 /*
00002         Description: start-up dialog
00003 
00004         Author: Marco Costalba (C) 2005-2006
00005 
00006         Copyright: See COPYING file that comes with this distribution
00007 
00008 */
00009 #include <qcombobox.h>
00010 #include <qlineedit.h>
00011 #include <qcheckbox.h>
00012 #include <qsettings.h>
00013 #include <qregexp.h>
00014 #include "common.h"
00015 #include "git.h"
00016 #include "rangeselectimpl.h"
00017 
00018 using namespace QGit;
00019 
00020 RangeSelectImpl::RangeSelectImpl(QWidget* par, QString* r, const QStringList& tl,
00021                                  bool* q, Git* g) : RangeSelectBase(par, 0, true) {
00022         range = r;
00023         quit = q;
00024         git = g;
00025         *quit = true; // if user press ESC everything works as expected
00026 
00027         QStringList otl;
00028         orderTags(tl, otl);
00029 
00030         // check if top tag is current HEAD
00031         if (!otl.empty()) {
00032                 const QString tagSha(git->getRefSha(otl.first(), Git::TAG, false));
00033                 if (git->checkRef(tagSha, Git::CUR_BRANCH))
00034                         // in this case remove from list to avoid an empty view
00035                         otl.pop_front();
00036         }
00037         comboBoxTo->insertStringList(otl);
00038         comboBoxTo->insertItem("HEAD", 0);
00039         comboBoxFrom->insertStringList(otl);
00040         comboBoxFrom->setFocus();
00041 
00042         int f = flags();
00043         checkBoxDiffCache->setChecked(f & DIFF_INDEX_F);
00044         checkBoxShowAll->setChecked(f & ALL_BRANCHES_F);
00045         checkBoxShowWholeHistory->setChecked(f & WHOLE_HISTORY_F);
00046         checkBoxShowDialog->setChecked(f & RANGE_SELECT_F);
00047 }
00048 
00049 void RangeSelectImpl::orderTags(const QStringList& src, QStringList& dst) {
00050 // we use an heuristic to list release candidates before corresponding
00051 // releases as example v.2.6.18-rc4 before v.2.6.18
00052 
00053         // match a (dotted) number + something else + a number + EOL
00054         QRegExp re("[\\d\\.]+([^\\d\\.]+\\d+$)");
00055 
00056         // in ASCII the space ' ' (32) comes before '!' (33) and both
00057         // before the rest, we need this to correctly order a sequence like
00058         //
00059         //      [v1.5, v1.5-rc1, v1.5.1] --> [v1.5.1, v1.5, v1.5-rc1]
00060 
00061         const QString rcMark(" $$%%");   // an impossible to find string starting with a space
00062         const QString noRcMark("!$$%%"); // an impossible to find string starting with a '!'
00063 
00064         typedef QMap<QString, QString> OrderedMap;
00065         QRegExp verRE("([^\\d])(\\d{1,2})(?=[^\\d])");
00066         OrderedMap map;
00067 
00068         FOREACH_SL (it, src) {
00069 
00070                 QString tmpStr(*it);
00071 
00072                 if (re.search(tmpStr) != -1)
00073                         tmpStr.insert(re.pos(1), rcMark);
00074                 else
00075                         tmpStr += noRcMark;
00076 
00077                 // Normalize all numbers to 3 digits with leading zeros, so one-digit
00078                 // version numbers are always smaller than two-digit version numbers
00079                 //     [v1.10.3, v1.5.1, v1.7.2] --> [v.1.10.3, v1.7.2, v1.5.1]
00080                 // QMap automatically sorts by keys, so we only have to iterate over it
00081                 // and return the original strings (stored as the data() in the map)
00082                 while (tmpStr.contains(verRE))
00083                         tmpStr.replace(verRE, "\\10\\2");
00084 
00085                 map[tmpStr] = *it;
00086         }
00087         dst.clear();
00088         FOREACH (OrderedMap, it, map)
00089                 dst.prepend(it.data());
00090 }
00091 
00092 void RangeSelectImpl::checkBoxDiffCache_toggled(bool b) {
00093 
00094         setFlag(DIFF_INDEX_F, b);
00095 }
00096 
00097 void RangeSelectImpl::checkBoxShowDialog_toggled(bool b) {
00098 
00099         setFlag(RANGE_SELECT_F, b);
00100 }
00101 
00102 void RangeSelectImpl::pushButtonOk_clicked() {
00103 
00104         *range = comboBoxFrom->currentText();
00105         if (!range->isEmpty())
00106                 range->append("..");
00107 
00108         range->append(comboBoxTo->currentText());
00109         range->prepend(lineEditOptions->text() + " ");
00110         *range = range->stripWhiteSpace();
00111         *quit = false;
00112         close();
00113 }
00114 
00115 void RangeSelectImpl::checkBoxShowAll_toggled(bool b) {
00116 
00117         QString opt(lineEditOptions->text());
00118         opt.remove("--all");
00119         if (b)
00120                 opt.append(" --all");
00121 
00122         lineEditOptions->setText(opt.stripWhiteSpace());
00123         setFlag(ALL_BRANCHES_F, b);
00124 }
00125 
00126 void RangeSelectImpl::checkBoxShowWholeHistory_toggled(bool b) {
00127 
00128         if (b) {
00129                 fromBckUp = comboBoxFrom->currentText();
00130                 toBckUp = comboBoxTo->currentText();
00131                 comboBoxFrom->setCurrentText("");
00132                 comboBoxTo->setCurrentText("HEAD");
00133 
00134         } else {
00135                 comboBoxFrom->setCurrentText(fromBckUp);
00136                 comboBoxTo->setCurrentText(toBckUp);
00137         }
00138         comboBoxFrom->setEnabled(!b);
00139         comboBoxTo->setEnabled(!b);
00140         setFlag(WHOLE_HISTORY_F, b);
00141 }

Generated on Fri Dec 7 21:57:38 2007 for QGit by  doxygen 1.5.3