Skip to content

Commit dcd9ba0

Browse files
committed
Merge (and solve conflicts with) latest master, including support for compiling w/ Qt4
2 parents c14304e + 98e33c5 commit dcd9ba0

11 files changed

Lines changed: 152 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ set(CMAKE_AUTOMOC ON)
1919

2020
# Select the Qt major version and its dependencies\
2121
set(QT_PACKAGE "Qt6" CACHE STRING "Major Qt version")
22-
#set_property(CACHE QT_PACKAGE PROPERTY STRINGS "Qt6" "Qt5" "Qt4")
23-
set_property(CACHE QT_PACKAGE PROPERTY STRINGS "Qt6" "Qt5")
24-
22+
set_property(CACHE QT_PACKAGE PROPERTY STRINGS "Qt6" "Qt5" "Qt4")
2523

2624
find_package(QT NAMES ${QT_PACKAGE} REQUIRED)
2725
set(QT Qt${QT_VERSION_MAJOR})

src/FileHistory.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
#include "git.h"
1919

20+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
21+
#define HAVE_COLUMNTYPE
22+
#endif
23+
2024
using namespace QGit;
2125

2226
FileHistory::FileHistory(QObject* p, Git* g) : QAbstractItemModel(p), git(g) {
@@ -118,16 +122,32 @@ void FileHistory::clear(bool complete) {
118122
rowData.clear();
119123

120124
if (testFlag(REL_DATE_F)) {
125+
#if QT_VERSION >= 0x06000
121126
secs = QDateTime::currentDateTime().toSecsSinceEpoch();
127+
#else
128+
secs = QDateTime::currentDateTime().toTime_t();
129+
#endif
130+
#ifdef HAVE_COLUMNTYPE
122131
headerInfo[ColumnType::TIME_COL] = "Last Change";
132+
#else
133+
headerInfo[5] = "Last Change";
134+
#endif
123135
} else {
124136
secs = 0;
137+
#ifdef HAVE_COLUMNTYPE
125138
headerInfo[ColumnType::TIME_COL] = "Author Date";
139+
#else
140+
headerInfo[5] = "Author Date";
141+
#endif
126142
}
127143
rowCnt = revOrder.count();
128144
annIdValid = false;
129145
endResetModel();
146+
#ifdef HAVE_COLUMNTYPE
130147
emit headerDataChanged(Qt::Horizontal, 0, ColumnType::TIME_COL);
148+
#else
149+
emit headerDataChanged(Qt::Horizontal, 0, 5);
150+
#endif
131151
}
132152

133153
void FileHistory::on_newRevsAdded(const FileHistory* fh, const QVector<ShaString>& shaVec) {

src/common.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,9 @@ RevFile& RevFile::operator<<(QDataStream& stream) {
265265
}
266266

267267
QString qt4and5escaping(QString toescape) {
268-
return toescape.toHtmlEscaped();
268+
#if QT_VERSION >= 0x050000
269+
return toescape.toHtmlEscaped();
270+
#else
271+
return Qt::escape(toescape);
272+
#endif
269273
}

src/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace QGit {
223223
enum FileDoubleClickAction {
224224
VIEW_PATCH,
225225
OPEN_IN_EDITOR,
226-
OPEN_IN_DIFFER,
226+
OPEN_IN_DIFFER
227227
};
228228

229229
// settings booleans
@@ -246,7 +246,7 @@ namespace QGit {
246246
USE_CMT_MSG_F = 1 << 15,
247247
// OPEN_IN_EDITOR_F = 1 << 16, // not used anymore; subject to be replaced
248248
ENABLE_DRAGNDROP_F = 1 << 17,
249-
ENABLE_SHORTREF_F = 1 << 18,
249+
ENABLE_SHORTREF_F = 1 << 18
250250
};
251251
const int FLAGS_DEF = USE_CMT_MSG_F | RANGE_SELECT_F | SMART_LBL_F | VERIFY_CMT_F | SIGN_PATCH_F | LOG_DIFF_TAB_F | MSG_ON_NEW_F | ENABLE_DRAGNDROP_F;
252252

src/git.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
#define GIT_LOG_FORMAT "%m%HX%PX%n%cn<%ce>%n%an<%ae>%n%at%n%s%n"
3333

34+
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
35+
#define QT_ASPRINTF asprintf
36+
#else
37+
#define QT_ASPRINTF sprintf
38+
#endif
39+
3440
// Used on init() for reading parameters once;
3541
// It's OK to be unique among qgit windows.
3642
static bool startup = true;
@@ -1955,8 +1961,12 @@ Rev* Git::fakeRevData(SCRef sha, SCList parents, SCRef author, SCRef date, SCRef
19551961
if (!patch.isEmpty())
19561962
data.append('\n' + patch);
19571963

1964+
#if QT_VERSION >= 0x050000
19581965
QTextCodec* tc = QTextCodec::codecForLocale();
19591966
QByteArray* ba = new QByteArray(tc->fromUnicode(data));
1967+
#else
1968+
QByteArray* ba = new QByteArray(data.toLatin1());
1969+
#endif
19601970
ba->append('\0');
19611971

19621972
fh->rowData.append(ba);
@@ -2436,7 +2446,7 @@ void Git::on_loaded(FileHistory* fh, ulong byteSize, int loadTime,
24362446
ulong kb = byteSize / 1024;
24372447
double mbs = (double)byteSize / fh->loadTime / 1000;
24382448
QString tmp;
2439-
tmp.asprintf("Loaded %lli revisions (%li KB), "
2449+
tmp.QT_ASPRINTF("Loaded %lli revisions (%li KB), "
24402450
"time elapsed: %i ms (%.2f MB/s)",
24412451
fh->revs.count(), kb, fh->loadTime, mbs);
24422452

src/listview.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,15 @@ void ListView::setupGeometry() {
9595

9696
QHeaderView* hv = header();
9797
hv->setStretchLastSection(true);
98+
#if QT_VERSION >= 0x050000
9899
hv->setSectionResizeMode(LOG_COL, QHeaderView::Interactive);
99100
hv->setSectionResizeMode(TIME_COL, QHeaderView::Interactive);
100101
hv->setSectionResizeMode(ANN_ID_COL, QHeaderView::ResizeToContents);
102+
#else
103+
hv->setResizeMode(LOG_COL, QHeaderView::Interactive);
104+
hv->setResizeMode(TIME_COL, QHeaderView::Interactive);
105+
hv->setResizeMode(ANN_ID_COL, QHeaderView::ResizeToContents);
106+
#endif
101107
hv->resizeSection(GRAPH_COL, DEF_GRAPH_COL_WIDTH);
102108
hv->resizeSection(LOG_COL, DEF_LOG_COL_WIDTH);
103109
hv->resizeSection(HASH_COL, DEF_HASH_COL_WIDTH);
@@ -352,7 +358,11 @@ QPixmap ListView::pixmapFromSelection(const QStringList &revs, const QString &re
352358
QStyleOptionViewItem o(opt);
353359
QString dummy;
354360
getTagMarkParams(dummy, o, refTypeFromName(ref), false);
361+
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
355362
painter.fillRect(0, 0, fm.horizontalAdvance(ref)+2*spacing, height, o.palette.window());
363+
#else
364+
painter.fillRect(0, 0, fm.width(ref)+2*spacing, height, o.palette.window());
365+
#endif
356366
painter.drawText(spacing, fm.ascent()+1, ref);
357367
row = 1;
358368
}
@@ -432,13 +442,13 @@ struct ListView::DropInfo {
432442
PATCHES = 1 << 0,
433443
REV_LIST = 1 << 1,
434444
REV_RANGE = 1 << 2,
435-
SAME_REPO = 1 << 3,
445+
SAME_REPO = 1 << 3
436446
};
437447
enum Action {
438448
PatchAction = Qt::CopyAction,
439449
RebaseAction = Qt::MoveAction,
440450
MoveRefAction = (Qt::LinkAction << 1) | Qt::MoveAction,
441-
MergeAction = Qt::LinkAction,
451+
MergeAction = Qt::LinkAction
442452
};
443453

444454
QString sourceRepo;
@@ -1201,7 +1211,11 @@ QString ListView::refNameAt(const QPoint &pos)
12011211
* Return the device pixel ratio
12021212
*/
12031213
qreal ListViewDelegate::dpr(void) const {
1204-
return qApp->devicePixelRatio();
1214+
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
1215+
return qApp->devicePixelRatio();
1216+
#else
1217+
return 1.0;
1218+
#endif
12051219
}
12061220

12071221
void ListViewDelegate::addTextPixmap(QPixmap** pp, SCRef txt, const QStyleOptionViewItem& opt) const {
@@ -1221,7 +1235,9 @@ void ListViewDelegate::addTextPixmap(QPixmap** pp, SCRef txt, const QStyleOption
12211235
static_cast<int>(text_height * dpr()));
12221236

12231237
QPixmap* newPm = new QPixmap(pixmapSize);
1224-
newPm->setDevicePixelRatio(dpr());
1238+
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
1239+
newPm->setDevicePixelRatio(dpr());
1240+
#endif
12251241

12261242
QPainter p;
12271243
p.begin(newPm);

src/mainimpl.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,25 @@ MainImpl::MainImpl(SCRef cd, QWidget* p) : QMainWindow(p) {
8181
QSettings settings;
8282
QString font(settings.value(STD_FNT_KEY).toString());
8383
if (font.isEmpty()) {
84+
#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
8485
font = QFontDatabase::systemFont(QFontDatabase::GeneralFont).toString();
86+
#else
87+
font = QApplication::font().toString();
88+
#endif
8589
}
8690
QGit::STD_FONT.fromString(font);
8791

8892
// set-up typewriter (fixed width) font
8993
font = settings.value(TYPWRT_FNT_KEY).toString();
9094
if (font.isEmpty()) { // choose a sensible default
95+
#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
9196
QFont fnt = QFontDatabase::systemFont(QFontDatabase::FixedFont);
97+
#else
98+
QFont fnt = QApplication::font();
99+
fnt.setStyleHint(QFont::TypeWriter, QFont::PreferDefault);
100+
fnt.setFixedPitch(true);
101+
fnt.setFamily(fnt.defaultFamily()); // the family corresponding
102+
#endif
92103
font = fnt.toString(); // to current style hint
93104
}
94105
QGit::TYPE_WRITER_FONT.fromString(font);
@@ -99,10 +110,19 @@ MainImpl::MainImpl(SCRef cd, QWidget* p) : QMainWindow(p) {
99110
tabWdg->addTab(rv->tabPage(), "&Rev list");
100111

101112
// hide close button for rev list tab
113+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
114+
// For Qt4: Use findChild to access QTabBar as tabBar() is protected
115+
QTabBar* const tabBar = tabWdg->findChild<QTabBar*>();
116+
#else
117+
// For Qt5+: Directly access tabBar()
102118
QTabBar* const tabBar = tabWdg->tabBar();
119+
#endif
120+
121+
if (tabBar) {
103122
tabBar->setTabButton(0, QTabBar::RightSide, NULL);
104123
tabBar->setTabButton(0, QTabBar::LeftSide, NULL);
105-
connect(tabWdg, SIGNAL(tabCloseRequested(int)), SLOT(tabBar_tabCloseRequested(int)));
124+
}
125+
connect(tabWdg, SIGNAL(tabCloseRequested(int)), SLOT(tabBar_tabCloseRequested(int)));
106126

107127
// set-up file names loading progress bar
108128
pbFileNamesLoading = new QProgressBar(statusBar());
@@ -710,7 +730,11 @@ bool MainImpl::eventFilter(QObject* obj, QEvent* ev) {
710730
if (e->modifiers() == Qt::AltModifier) {
711731

712732
int idx = tabWdg->currentIndex();
733+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
734+
if (e->delta() < 0)
735+
#else
713736
if (e->angleDelta().y() < 0)
737+
#endif
714738
idx = (++idx == tabWdg->count() ? 0 : idx);
715739
else
716740
idx = (--idx < 0 ? tabWdg->count() - 1 : idx);
@@ -1141,7 +1165,11 @@ void MainImpl::shortCutActivated() {
11411165
QShortcut* se = dynamic_cast<QShortcut*>(sender());
11421166

11431167
if (se) {
1168+
#if QT_VERSION >= 0x050000
11441169
const QKeySequence& key = se->key();
1170+
#else
1171+
const int key = se->key();
1172+
#endif
11451173

11461174
if (key == Qt::Key_I) {
11471175
rv->tab()->listViewLog->on_keyUp();
@@ -1322,7 +1350,11 @@ static void prepareRefSubmenu(QMenu* menu, const QStringList& refs, const QChar
13221350
QMenu* add_here = menu;
13231351
FOREACH_SL (pit, parts) {
13241352
if (pit == parts.end() - 1) break;
1353+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1354+
QMenu* found = add_here->findChild<QMenu*>(*pit);
1355+
#else
13251356
QMenu* found = add_here->findChild<QMenu*>(*pit, Qt::FindDirectChildrenOnly);
1357+
#endif
13261358
if(!found) {
13271359
found = add_here->addMenu(*pit);
13281360
found->setObjectName(*pit);

src/qgit.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
Copyright: See COPYING file that comes with this distribution
66
77
*/
8-
#include <QCommandLineParser>
8+
99
#include <QSettings>
10+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
11+
#include <QCommandLineParser>
12+
#else
13+
#include <QApplication>
14+
#include <QCoreApplication>
15+
#include <QStringList>
16+
#include <iostream>
17+
#endif
1018
#include "config.h" // defines PACKAGE_VERSION
1119
#include "common.h"
1220
#include "mainimpl.h"
@@ -21,9 +29,13 @@ using namespace QGit;
2129
int main(int argc, char* argv[]) {
2230

2331
QApplication app(argc, argv);
32+
#if QT_VERSION_CHECK(5, 6, 0) <= QT_VERSION && QT_VERSION < QT_VERSION_CHECK(6,0,0)
33+
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
34+
#endif
2435
QCoreApplication::setOrganizationName(ORG_KEY);
2536
QCoreApplication::setApplicationName(APP_KEY);
2637

38+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2739
QCommandLineParser parser;
2840
QCoreApplication::setApplicationVersion(PACKAGE_VERSION);
2941
parser.addHelpOption();
@@ -47,6 +59,45 @@ int main(int argc, char* argv[]) {
4759
QCoreApplication::setApplicationName("QGit");
4860
parser.process(app.arguments()); // exits the process
4961
}
62+
#else
63+
QStringList arguments = QCoreApplication::arguments();
64+
bool showHelp = false;
65+
bool showVersion = false;
66+
QStringList gitLogArgs;
67+
68+
for (int i = 1; i < arguments.size(); ++i) {
69+
QString arg = arguments.at(i);
70+
if (arg == "--help" || arg == "-h") {
71+
showHelp = true;
72+
} else if (arg == "--version" || arg == "-v") {
73+
showVersion = true;
74+
} else {
75+
gitLogArgs.append(arg); // Collect positional arguments
76+
}
77+
}
78+
79+
if (showHelp) {
80+
std::cout << "Usage: qgit [options] [git-log-args]\n"
81+
<< "Options:\n"
82+
<< " --help, -h Show this help message\n"
83+
<< " --version, -v Show application version\n"
84+
<< "\n"
85+
<< "Arguments:\n"
86+
<< " git-log-args Arguments forwarded to \"git log\"\n"
87+
<< " See \"man git-log\" for details.\n";
88+
return 0; // Exit after showing help
89+
}
90+
91+
if (showVersion) {
92+
std::cout << "QGit version: " << PACKAGE_VERSION << "\n";
93+
return 0; // Exit after showing version
94+
}
95+
96+
// Process git-log-args as needed
97+
foreach (const QString& arg, gitLogArgs) {
98+
std::cout << "Git log argument: " << arg.toStdString() << "\n";
99+
}
100+
#endif
50101

51102
/* On Windows msysgit exec directory is set up
52103
* during installation so to always find git.exe

src/revsview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void RevsView::updateLineEditSHA(bool clear) {
322322
l->setText(""); // clears history
323323

324324
else if (l->text() != st.sha()) {
325-
auto hash = QGit::testFlag(QGit::ENABLE_SHORTREF_F)
325+
QString hash = QGit::testFlag(QGit::ENABLE_SHORTREF_F)
326326
? st.sha().left(git->shortHashLength())
327327
: st.sha();
328328

src/smartbrowse.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ bool SmartBrowse::eventFilter(QObject *obj, QEvent *event) {
224224
if (sb && t == QEvent::Wheel && sb->orientation() == Qt::Vertical) {
225225

226226
QWheelEvent* we = static_cast<QWheelEvent*>(event);
227+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
228+
if (wheelRolled(we->delta(), visibilityFlags()))
229+
#else
227230
if (wheelRolled(we->angleDelta().y(), visibilityFlags()))
231+
#endif
228232
return true; // filter event out
229233
}
230234
return QObject::eventFilter(obj, event);

0 commit comments

Comments
 (0)